MCPcopy Index your code
hub / github.com/python/cpython / test_http_body_fileobj

Method test_http_body_fileobj

Lib/test/test_urllib2.py:1008–1029  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1006 self.assertFalse(newreq.has_header("Transfer-encoding"))
1007
1008 def test_http_body_fileobj(self):
1009 # A file object - chunked encoding is used
1010 # unless Content Length is already set.
1011 # (Note that there are some subtle differences to a regular
1012 # file, that is why we are testing both cases.)
1013
1014 h = urllib.request.AbstractHTTPHandler()
1015 o = h.parent = MockOpener()
1016 file_obj = io.BytesIO()
1017
1018 req = Request("http://example.com/", file_obj, {})
1019 newreq = h.do_request_(req)
1020 self.assertEqual(newreq.get_header('Transfer-encoding'), 'chunked')
1021 self.assertFalse(newreq.has_header('Content-length'))
1022
1023 headers = {"Content-Length": 30}
1024 req = Request("http://example.com/", file_obj, headers)
1025 newreq = h.do_request_(req)
1026 self.assertEqual(int(newreq.get_header('Content-length')), 30)
1027 self.assertFalse(newreq.has_header("Transfer-encoding"))
1028
1029 file_obj.close()
1030
1031 @requires_subprocess()
1032 def test_http_body_pipe(self):

Callers

nothing calls this directly

Calls 8

do_request_Method · 0.95
closeMethod · 0.95
RequestClass · 0.90
MockOpenerClass · 0.85
assertFalseMethod · 0.80
assertEqualMethod · 0.45
get_headerMethod · 0.45
has_headerMethod · 0.45

Tested by

no test coverage detected