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

Method test_http_body_iterable

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

Source from the content-addressed store, hash-verified

1052 30)
1053
1054 def test_http_body_iterable(self):
1055 # Generic iterable. There is no way to determine the content
1056 # length up front. Fall back to Transfer-encoding chunked.
1057
1058 h = urllib.request.AbstractHTTPHandler()
1059 o = h.parent = MockOpener()
1060
1061 def iterable_body():
1062 yield b"one"
1063
1064 for headers in {}, {"Content-Length": 11}:
1065 req = Request("http://example.com/", iterable_body(), headers)
1066 newreq = h.do_request_(req)
1067 if not headers:
1068 self.assertEqual(newreq.get_header('Content-length'), None)
1069 self.assertEqual(newreq.get_header('Transfer-encoding'),
1070 'chunked')
1071 else:
1072 self.assertEqual(int(newreq.get_header('Content-length')), 11)
1073
1074 def test_http_body_empty_seq(self):
1075 # Zero-length iterable body should be treated like any other iterable

Callers

nothing calls this directly

Calls 5

do_request_Method · 0.95
RequestClass · 0.90
MockOpenerClass · 0.85
assertEqualMethod · 0.45
get_headerMethod · 0.45

Tested by

no test coverage detected