(self)
| 964 | self.assertEqual(req.unredirected_hdrs["Spam"], "foo") |
| 965 | |
| 966 | def test_http_body_file(self): |
| 967 | # A regular file - chunked encoding is used unless Content Length is |
| 968 | # already set. |
| 969 | |
| 970 | h = urllib.request.AbstractHTTPHandler() |
| 971 | o = h.parent = MockOpener() |
| 972 | |
| 973 | file_obj = tempfile.NamedTemporaryFile(mode='w+b', delete=False) |
| 974 | file_path = file_obj.name |
| 975 | file_obj.close() |
| 976 | self.addCleanup(os.unlink, file_path) |
| 977 | |
| 978 | with open(file_path, "rb") as f: |
| 979 | req = Request("http://example.com/", f, {}) |
| 980 | newreq = h.do_request_(req) |
| 981 | te = newreq.get_header('Transfer-encoding') |
| 982 | self.assertEqual(te, "chunked") |
| 983 | self.assertFalse(newreq.has_header('Content-length')) |
| 984 | |
| 985 | with open(file_path, "rb") as f: |
| 986 | req = Request("http://example.com/", f, {"Content-Length": 30}) |
| 987 | newreq = h.do_request_(req) |
| 988 | self.assertEqual(int(newreq.get_header('Content-length')), 30) |
| 989 | self.assertFalse(newreq.has_header("Transfer-encoding")) |
| 990 | |
| 991 | def test_http_body_fileobj(self): |
| 992 | # A file object - chunked encoding is used |
nothing calls this directly
no test coverage detected