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

Method test_http_body_file

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

Source from the content-addressed store, hash-verified

981 self.assertEqual(req.unredirected_hdrs["Spam"], "foo")
982
983 def test_http_body_file(self):
984 # A regular file - chunked encoding is used unless Content Length is
985 # already set.
986
987 h = urllib.request.AbstractHTTPHandler()
988 o = h.parent = MockOpener()
989
990 file_obj = tempfile.NamedTemporaryFile(mode='w+b', delete=False)
991 file_path = file_obj.name
992 file_obj.close()
993 self.addCleanup(os.unlink, file_path)
994
995 with open(file_path, "rb") as f:
996 req = Request("http://example.com/", f, {})
997 newreq = h.do_request_(req)
998 te = newreq.get_header('Transfer-encoding')
999 self.assertEqual(te, "chunked")
1000 self.assertFalse(newreq.has_header('Content-length'))
1001
1002 with open(file_path, "rb") as f:
1003 req = Request("http://example.com/", f, {"Content-Length": 30})
1004 newreq = h.do_request_(req)
1005 self.assertEqual(int(newreq.get_header('Content-length')), 30)
1006 self.assertFalse(newreq.has_header("Transfer-encoding"))
1007
1008 def test_http_body_fileobj(self):
1009 # A file object - chunked encoding is used

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected