Lines Matching refs:self
37 def test___all__(self):
45 self.assertEqual(u.__module__, 'nturl2path')
46 self.assertEqual(p.__module__, 'nturl2path')
48 self.assertEqual(v.__module__, 'urllib.%s' % module,
52 def test_trivial(self):
56 self.addCleanup(urllib.request.urlcleanup)
58 self.assertRaises(ValueError, urllib.request.urlopen, 'bogus url')
71 def test_parse_http_list(self):
80 self.assertEqual(urllib.request.parse_http_list(string), list)
82 def test_URLError_reasonstr(self):
84 self.assertIn(err.reason, str(err))
89 def test_request_headers_dict(self):
103 self.assertEqual(Request(url,
106 self.assertEqual(Request(url,
110 def test_request_headers_methods(self):
127 self.assertTrue(req.has_header("Spam-eggs"))
128 self.assertEqual(req.header_items(), [('Spam-eggs', 'blah')])
131 self.assertEqual(sorted(req.header_items()),
133 self.assertFalse(req.has_header("Not-there"))
134 self.assertIsNone(req.get_header("Not-there"))
135 self.assertEqual(req.get_header("Not-there", "default"), "default")
138 self.assertFalse(req.has_header("Spam-eggs"))
141 self.assertTrue(req.has_header("Unredirected-spam"))
144 self.assertFalse(req.has_header("Unredirected-spam"))
146 def test_password_manager(self):
158 self.assertEqual(find_user_pass("Some Realm", "example.com"),
160 self.assertEqual(find_user_pass("Some Realm", "http://example.com/ni"),
162 self.assertEqual(find_user_pass("Some Realm", "http://example.com"),
164 self.assertEqual(find_user_pass("Some Realm", "http://example.com/"),
166 self.assertEqual(find_user_pass("Some Realm",
169 self.assertEqual(find_user_pass("Some Realm",
179 self.assertEqual(find_user_pass("c", "http://example.com/foo"),
181 self.assertEqual(find_user_pass("c", "http://example.com/bar"),
183 self.assertEqual(find_user_pass("c", "http://example.com/foo/"),
185 self.assertEqual(find_user_pass("c", "http://example.com/foo/bar"),
187 self.assertEqual(find_user_pass("c", "http://example.com/foo/baz"),
189 self.assertEqual(find_user_pass("c", "http://example.com/foobar"),
194 self.assertEqual(find_user_pass("c", "http://example.com/baz"),
196 self.assertEqual(find_user_pass("c", "http://example.com/baz/"),
198 self.assertEqual(find_user_pass("c", "http://example.com/baz/bar"),
206 self.assertEqual(find_user_pass("b", "http://example.com/"),
212 self.assertEqual(find_user_pass("a", "http://example.com/"),
215 self.assertEqual(find_user_pass("a", "http://a.example.com/"),
220 self.assertEqual(find_user_pass("Some Realm", "c.example.com"),
222 self.assertEqual(find_user_pass("Some Realm", "c.example.com:3128"),
224 self.assertEqual(
227 self.assertEqual(find_user_pass("Some Realm", "d.example.com"),
229 self.assertEqual(find_user_pass("Some Realm", "e.example.com:3128"),
232 def test_password_manager_default_port(self):
245 self.assertEqual(find_user_pass("f", "g.example.com:100"),
247 self.assertEqual(find_user_pass("f", "g.example.com:80"),
249 self.assertEqual(find_user_pass("f", "g.example.com"),
251 self.assertEqual(find_user_pass("f", "http://g.example.com:100"),
253 self.assertEqual(find_user_pass("f", "http://g.example.com:80"),
255 self.assertEqual(find_user_pass("f", "http://g.example.com"),
257 self.assertEqual(find_user_pass("g", "h.example.com"), ('11', 'k'))
258 self.assertEqual(find_user_pass("g", "h.example.com:80"), ('11', 'k'))
259 self.assertEqual(find_user_pass("g", "http://h.example.com:80"),
261 self.assertEqual(find_user_pass("h", "i.example.com"), (None, None))
262 self.assertEqual(find_user_pass("h", "i.example.com:80"), ('12', 'l'))
263 self.assertEqual(find_user_pass("h", "http://i.example.com:80"),
265 self.assertEqual(find_user_pass("i", "j.example.com"), ('13', 'm'))
266 self.assertEqual(find_user_pass("i", "j.example.com:80"),
268 self.assertEqual(find_user_pass("i", "http://j.example.com"),
270 self.assertEqual(find_user_pass("i", "http://j.example.com:80"),
277 def open(self, req, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
278 self.req, self.data, self.timeout = req, data, timeout
280 def error(self, proto, *args):
281 self.proto, self.args = proto, args
285 def read(self, count=None):
288 def readline(self, count=None):
291 def close(self):
296 def getheaders(self, name):
297 return list(self.values())
301 def __init__(self, code, msg, headers, data, url=None):
302 io.StringIO.__init__(self, data)
303 self.code, self.msg, self.headers, self.url = code, msg, headers, url
305 def info(self):
306 return self.headers
308 def geturl(self):
309 return self.url
313 def add_cookie_header(self, request):
314 self.ach_req = request
316 def extract_cookies(self, response, request):
317 self.ec_req, self.ec_r = request, response
321 def __init__(self, meth_name, action, handle):
322 self.meth_name = meth_name
323 self.handle = handle
324 self.action = action
326 def __call__(self, *args):
327 return self.handle(self.meth_name, self.action, *args)
331 def __init__(self, fp, msg, status, reason):
332 self.fp = fp
333 self.msg = msg
334 self.status = status
335 self.reason = reason
336 self.code = 200
338 def read(self):
341 def info(self):
344 def geturl(self):
345 return self.url
349 def __init__(self):
350 self.level = 0
351 self.req_headers = []
352 self.data = None
353 self.raise_on_endheaders = False
354 self.sock = None
355 self._tunnel_headers = {}
357 def __call__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
358 self.host = host
359 self.timeout = timeout
360 return self
362 def set_debuglevel(self, level):
363 self.level = level
365 def set_tunnel(self, host, port=None, headers=None):
366 self._tunnel_host = host
367 self._tunnel_port = port
369 self._tunnel_headers = headers
371 self._tunnel_headers.clear()
373 def request(self, method, url, body=None, headers=None, *,
375 self.method = method
376 self.selector = url
378 self.req_headers += headers.items()
379 self.req_headers.sort()
381 self.data = body
382 self.encode_chunked = encode_chunked
383 if self.raise_on_endheaders:
386 def getresponse(self):
389 def close(self):
398 def __init__(self, methods):
399 self._define_methods(methods)
401 def _define_methods(self, methods):
407 meth = FakeMethod(name, action, self.handle)
408 setattr(self.__class__, name, meth)
410 def handle(self, fn_name, action, *args, **kwds):
411 self.parent.calls.append((self, fn_name, args, kwds))
414 elif action == "return self":
415 return self
428 return self.parent.error("http", args[0], res, code, "", {})
433 def close(self):
436 def add_parent(self, parent):
437 self.parent = parent
438 self.parent.calls = []
440 def __lt__(self, other):
444 return self.handler_order < other.handler_order
492 def __init__(self, code, headers):
493 self.code = code
494 self.headers = headers
495 self.reset()
497 def reset(self):
498 self._count = 0
499 self.requests = []
501 def http_open(self, req):
503 self.requests.append(copy.deepcopy(req))
504 if self._count == 0:
505 self._count = self._count + 1
506 name = http.client.responses[self.code]
507 msg = email.message_from_string(self.headers)
508 return self.parent.error(
509 "http", req, MockFile(), self.code, name, msg)
511 self.req = req
520 def __init__(self, debuglevel=0):
521 urllib.request.AbstractHTTPHandler.__init__(self, debuglevel=debuglevel)
522 self.httpconn = MockHTTPClass()
524 def https_open(self, req):
525 return self.do_open(self.httpconn, req)
532 def __init__(self, code):
533 self.code = code
534 self.has_auth_header = False
536 def reset(self):
537 self.has_auth_header = False
539 def http_open(self, req):
541 self.has_auth_header = True
542 name = http.client.responses[self.code]
543 return MockResponse(self.code, name, MockFile(), "", req.get_full_url())
548 def add_password(self, realm, uri, user, password):
549 self.realm = realm
550 self.url = uri
551 self.user = user
552 self.password = password
554 def find_user_password(self, realm, authuri):
555 self.target_realm = realm
556 self.target_url = authuri
557 return self.user, self.password
562 def test_add_non_handler(self):
565 self.assertRaises(TypeError,
568 def test_badly_named_methods(self):
574 # TypeError in real code; here, returning self from these mock
581 [("do_open", "return self"), ("proxy_open", "return self")],
582 [("redirect_request", "return self")],
587 self.assertRaises(URLError, o.open, scheme+"://example.com/")
589 def test_handled(self):
595 [("http_open", "return self")],
596 [("http_open", "return self")],
605 # In fact, second mock handler defining .http_open() returns self
608 self.assertEqual(r, handlers[2])
612 self.assertEqual((handler, name), expected)
613 self.assertEqual(args, (req,))
615 def test_handler_order(self):
618 for meths, handler_order in [([("http_open", "return self")], 500),
630 self.assertEqual(o.calls[0][0], handlers[1])
631 self.assertEqual(o.calls[1][0], handlers[0])
633 def test_raise(self):
638 [("http_open", "return self")],
643 self.assertRaises(urllib.error.URLError, o.open, req)
644 self.assertEqual(o.calls, [(handlers[0], "http_open", (req,), {})])
646 def test_http_error(self):
666 self.assertEqual((handler, method_name), got[:2])
667 self.assertEqual(args, got[2])
669 def test_processors(self):
691 self.assertEqual((handler, name), calls[i])
692 self.assertEqual(len(args), 1)
693 self.assertIsInstance(args[0], Request)
696 self.assertEqual((handler, name), calls[i])
697 self.assertEqual(len(args), 2)
698 self.assertIsInstance(args[0], Request)
702 self.assertIsInstance(args[1], MockResponse)
719 def test_ftp(self):
721 def __init__(self, data):
722 self.data = data
724 def retrfile(self, filename, filetype):
725 self.filename, self.filetype = filename, filetype
726 return io.StringIO(self.data), len(self.data)
728 def close(self):
732 def __init__(self, data):
733 self.data = data
735 def connect_ftp(self, user, passwd, host, port, dirs,
737 self.user, self.passwd = user, passwd
738 self.host, self.port = host, port
739 self.dirs = dirs
740 self.ftpwrapper = MockFTPWrapper(self.data)
741 return self.ftpwrapper
772 self.assertEqual(h.user, user)
773 self.assertEqual(h.passwd, passwd)
774 self.assertEqual(h.host, socket.gethostbyname(host))
775 self.assertEqual(h.port, port)
776 self.assertEqual(h.dirs, dirs)
777 self.assertEqual(h.ftpwrapper.filename, filename)
778 self.assertEqual(h.ftpwrapper.filetype, type_)
780 self.assertEqual(headers.get("Content-type"), mimetype)
781 self.assertEqual(int(headers["Content-length"]), len(data))
783 def test_file(self):
822 self.assertEqual(data, towrite)
823 self.assertEqual(headers["Content-type"], "text/plain")
824 self.assertEqual(headers["Content-length"], "13")
825 self.assertEqual(headers["Last-modified"], modified)
826 self.assertEqual(respurl, url)
844 self.assertRaises(urllib.error.URLError,
869 self.assertFalse(ftp)
871 self.assertIs(o.req, req)
872 self.assertEqual(req.type, "ftp")
873 self.assertEqual(req.type == "ftp", ftp)
875 def test_http(self):
894 self.assertEqual(r.geturl(), url)
896 self.assertEqual(http.host, "example.com")
897 self.assertEqual(http.level, 0)
898 self.assertEqual(http.method, method)
899 self.assertEqual(http.selector, "/")
900 self.assertEqual(http.req_headers,
903 self.assertEqual(http.data, data)
907 self.assertRaises(urllib.error.URLError, h.do_open, http, req)
911 self.assertRaises(TypeError, h.do_request_, req)
920 self.assertNotIn("Content-length", req.unredirected_hdrs)
921 self.assertNotIn("Content-type", req.unredirected_hdrs)
923 self.assertEqual(req.unredirected_hdrs["Content-length"], "0")
924 self.assertEqual(req.unredirected_hdrs["Content-type"],
927 self.assertEqual(req.unredirected_hdrs["Host"], "example.com")
928 self.assertEqual(req.unredirected_hdrs["Spam"], "eggs")
936 self.assertEqual(req.unredirected_hdrs["Content-length"], "foo")
937 self.assertEqual(req.unredirected_hdrs["Content-type"], "bar")
938 self.assertEqual(req.unredirected_hdrs["Host"], "baz")
939 self.assertEqual(req.unredirected_hdrs["Spam"], "foo")
941 def test_http_body_file(self):
951 self.addCleanup(os.unlink, file_path)
957 self.assertEqual(te, "chunked")
958 self.assertFalse(newreq.has_header('Content-length'))
963 self.assertEqual(int(newreq.get_header('Content-length')), 30)
964 self.assertFalse(newreq.has_header("Transfer-encoding"))
966 def test_http_body_fileobj(self):
978 self.assertEqual(newreq.get_header('Transfer-encoding'), 'chunked')
979 self.assertFalse(newreq.has_header('Content-length'))
984 self.assertEqual(int(newreq.get_header('Content-length')), 30)
985 self.assertFalse(newreq.has_header("Transfer-encoding"))
989 def test_http_body_pipe(self):
1004 self.assertEqual(newreq.get_header('Content-length'), None)
1005 self.assertEqual(newreq.get_header('Transfer-encoding'),
1008 self.assertEqual(int(newreq.get_header('Content-length')),
1011 def test_http_body_iterable(self):
1025 self.assertEqual(newreq.get_header('Content-length'), None)
1026 self.assertEqual(newreq.get_header('Transfer-encoding'),
1029 self.assertEqual(int(newreq.get_header('Content-length')), 11)
1031 def test_http_body_empty_seq(self):
1036 self.assertEqual(req.get_header("Transfer-encoding"), "chunked")
1037 self.assertFalse(req.has_header("Content-length"))
1039 def test_http_body_array(self):
1050 self.assertEqual(int(newreq.get_header('Content-length')),16)
1052 def test_http_handler_debuglevel(self):
1057 self.assertEqual(h._debuglevel, 1)
1059 def test_http_doubleslash(self):
1079 self.assertEqual(np_ds_req.unredirected_hdrs["Host"], "example.com")
1084 self.assertEqual(p_ds_req.unredirected_hdrs["Host"], "example.com")
1086 def test_full_url_setter(self):
1103 self.assertEqual(r.get_full_url(), url)
1106 self.assertEqual(r.fragment or '', parsed.fragment)
1107 self.assertEqual(urlparse(r.get_full_url()).query, parsed.query)
1109 def test_full_url_deleter(self):
1112 self.assertIsNone(r.full_url)
1113 self.assertIsNone(r.fragment)
1114 self.assertEqual(r.selector, '')
1116 def test_fixpath_in_weirdurls(self):
1126 self.assertEqual(newreq.host, 'www.python.org')
1127 self.assertEqual(newreq.selector, '/?getspam')
1132 self.assertEqual(newreq.host, 'www.python.org')
1133 self.assertEqual(newreq.selector, '')
1135 def test_errors(self):
1144 self.assertIs(r, newr)
1145 self.assertFalse(hasattr(o, "proto")) # o.error not called
1148 self.assertIs(r, newr)
1149 self.assertFalse(hasattr(o, "proto")) # o.error not called
1152 self.assertIs(r, newr)
1153 self.assertFalse(hasattr(o, "proto")) # o.error not called
1156 self.assertIsNone(h.http_response(req, r))
1157 self.assertEqual(o.proto, "http") # o.error called
1158 self.assertEqual(o.args, (req, r, 502, "Bad gateway", {}))
1160 def test_cookies(self):
1168 self.assertIs(cj.ach_req, req)
1169 self.assertIs(cj.ach_req, newreq)
1170 self.assertEqual(req.origin_req_host, "example.com")
1171 self.assertFalse(req.unverifiable)
1173 self.assertIs(cj.ec_req, req)
1174 self.assertIs(cj.ec_r, r)
1175 self.assertIs(r, newr)
1177 def test_redirect(self):
1198 self.assertIn(code, (307, 308))
1199 self.assertIsNotNone(data)
1200 self.assertEqual(o.req.get_full_url(), to_url)
1202 self.assertEqual(o.req.get_method(), "GET")
1204 self.assertFalse(o.req.data)
1209 self.assertNotIn("content-length", headers)
1210 self.assertNotIn("content-type", headers)
1212 self.assertEqual(o.req.headers["Nonsense"],
1214 self.assertNotIn("Spam", o.req.headers)
1215 self.assertNotIn("Spam", o.req.unredirected_hdrs)
1237 self.assertEqual(count, urllib.request.HTTPRedirectHandler.max_repeats)
1248 self.assertEqual(count,
1251 def test_invalid_redirect(self):
1263 self.assertRaises(urllib.error.HTTPError, h.http_error_302,
1271 self.assertEqual(o.req.get_full_url(), valid_url)
1273 def test_relative_redirect(self):
1284 self.assertEqual(o.req.get_full_url(), valid_url)
1286 def test_cookie_redirect(self):
1299 self.assertFalse(hh.req.has_header("Cookie"))
1301 def test_redirect_fragment(self):
1308 self.assertEqual(fp.geturl(), redirected_url.strip())
1310 def test_redirect_no_path(self):
1314 self.addCleanup(urllib.request.urlcleanup)
1319 self.addCleanup(setattr, http.client, "HTTPConnection", real_class)
1322 self.assertEqual(url, next(urls))
1328 self.assertEqual(fp.geturl(), "http://python.org/path?query")
1330 def test_redirect_encoding(self):
1334 def http_open(self, req):
1335 result = self.do_open(self.connection, req)
1336 self.last_buf = self.connection.buf
1338 self.connection = test_urllib.fakehttp(
1354 with self.subTest(repr(location)):
1363 self.assertTrue(request.startswith(expected), repr(request))
1365 def test_proxy(self):
1377 self.assertEqual(req.host, "acme.example.com")
1379 self.assertEqual(req.host, u)
1380 self.assertEqual([(handlers[0], "http_open")],
1383 def test_proxy_no_proxy(self):
1389 self.assertEqual(req.host, "www.perl.org")
1391 self.assertEqual(req.host, "proxy.example.com")
1393 self.assertEqual(req.host, "www.python.org")
1395 self.assertEqual(req.host, "www.python.org")
1398 def test_proxy_no_proxy_all(self):
1404 self.assertEqual(req.host, "www.python.org")
1406 self.assertEqual(req.host, "www.python.org")
1409 def test_proxy_https(self):
1419 self.assertEqual(req.host, "www.example.com")
1421 self.assertEqual(req.host, "proxy.example.com:3128")
1422 self.assertEqual([(handlers[0], "https_open")],
1425 def test_proxy_https_proxy_authorization(self):
1434 self.assertEqual(req.host, "www.example.com")
1435 self.assertIsNone(req._tunnel_host)
1440 self.assertNotIn(("Proxy-Authorization", "FooBar"),
1442 self.assertIn(("User-Agent", "Grail"),
1444 self.assertIsNotNone(req._tunnel_host)
1445 self.assertEqual(req.host, "proxy.example.com:3128")
1446 self.assertEqual(req.get_header("Proxy-authorization"), "FooBar")
1449 def test_osx_proxy_bypass(self):
1458 self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass),
1463 self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass),
1468 self.assertTrue(_proxy_bypass_macosx_sysconf('test', bypass))
1476 self.assertTrue(_proxy_bypass_macosx_sysconf(host, bypass),
1479 self.assertFalse(_proxy_bypass_macosx_sysconf(host, bypass),
1482 def check_basic_auth(self, headers, realm):
1483 with self.subTest(realm=realm, headers=headers):
1491 self._test_basic_auth(opener, auth_handler, "Authorization",
1496 def test_basic_auth(self):
1522 self.check_basic_auth(headers, realm)
1528 self.check_basic_auth(headers, realm)
1539 self.check_basic_auth(headers, realm)
1541 def test_proxy_basic_auth(self):
1552 self._test_basic_auth(opener, auth_handler, "Proxy-authorization",
1558 def test_basic_and_digest_auth_handlers(self):
1568 def __init__(self):
1569 OpenerDirector.__init__(self)
1570 self.recorded = []
1572 def record(self, info):
1573 self.recorded.append(info)
1576 def http_error_401(self, *args, **kwds):
1577 self.parent.record("digest")
1578 urllib.request.HTTPDigestAuthHandler.http_error_401(self,
1582 def http_error_401(self, *args, **kwds):
1583 self.parent.record("basic")
1584 urllib.request.HTTPBasicAuthHandler.http_error_401(self,
1599 self._test_basic_auth(opener, basic_handler, "Authorization",
1606 self.assertEqual(opener.recorded, ["digest", "basic"]*2)
1608 def test_unsupported_auth_digest_handler(self):
1616 self.assertRaises(ValueError, opener.open, "http://www.example.com")
1618 def test_unsupported_auth_basic_handler(self):
1626 self.assertRaises(ValueError, opener.open, "http://www.example.com")
1628 def _test_basic_auth(self, opener, auth_handler, auth_header,
1636 self.assertEqual(realm, password_manager.realm)
1637 self.assertEqual(request_url, password_manager.url)
1638 self.assertEqual(user, password_manager.user)
1639 self.assertEqual(password, password_manager.password)
1644 self.assertEqual(password_manager.target_realm, realm)
1645 self.assertEqual(password_manager.target_url, protected_url)
1648 self.assertEqual(len(http_handler.requests), 2)
1649 self.assertFalse(http_handler.requests[0].has_header(auth_header))
1653 self.assertEqual(http_handler.requests[1].get_header(auth_header),
1655 self.assertEqual(http_handler.requests[1].unredirected_hdrs[auth_header],
1662 self.assertEqual(len(http_handler.requests), 1)
1663 self.assertFalse(http_handler.requests[0].has_header(auth_header))
1665 def test_basic_prior_auth_auto_send(self):
1679 self.assertTrue(pwd_manager.is_authenticated(request_url))
1680 self.assertTrue(pwd_manager.is_authenticated(request_url + '/nested'))
1681 self.assertFalse(pwd_manager.is_authenticated(request_url + 'plain'))
1690 self.assertTrue(http_handler.has_auth_header)
1692 def test_basic_prior_auth_send_after_first_success(self):
1704 self.assertFalse(is_auth)
1716 self.assertTrue(is_auth)
1719 self.assertFalse(http_handler.has_auth_header)
1730 self.assertTrue(http_handler.has_auth_header)
1732 def test_http_closed(self):
1746 self.assertTrue(conn.fakesock.closed,
1749 def test_invalid_closed(self):
1755 with self.assertRaises(http.client.BadStatusLine):
1757 self.assertTrue(conn.fakesock.closed, "Connection not closed")
1762 def opener_has_handler(self, opener, handler_class):
1763 self.assertTrue(any(h.__class__ == handler_class
1766 def test_build_opener(self):
1771 def foo_open(self):
1775 def bar_open(self):
1781 self.opener_has_handler(o, FooHandler)
1782 self.opener_has_handler(o, BarHandler)
1786 self.opener_has_handler(o, FooHandler)
1787 self.opener_has_handler(o, BarHandler)
1791 self.opener_has_handler(o, MyHTTPHandler)
1796 self.opener_has_handler(o, urllib.request.HTTPHandler)
1798 self.opener_has_handler(o, urllib.request.HTTPHandler)
1800 self.opener_has_handler(o, urllib.request.HTTPHandler)
1807 self.opener_has_handler(o, MyHTTPHandler)
1808 self.opener_has_handler(o, MyOtherHTTPHandler)
1810 def test_HTTPError_interface(self):
1819 self.assertTrue(hasattr(err, 'reason'))
1820 self.assertEqual(err.reason, 'something bad happened')
1821 self.assertTrue(hasattr(err, 'headers'))
1822 self.assertEqual(err.headers, 'Content-Length: 42')
1824 self.assertEqual(str(err), expected_errmsg)
1826 self.assertEqual(repr(err), expected_errmsg)
1828 def test_gh_98778(self):
1830 self.assertEqual(getattr(x, "__notes__", ()), ())
1831 self.assertIsInstance(x.fp.read(), bytes)
1833 def test_parse_proxy(self):
1874 self.assertEqual(_parse_proxy(tc), expected)
1876 self.assertRaises(ValueError, _parse_proxy, 'file:/ftp.example.com'),
1878 def test_unsupported_algorithm(self):
1880 with self.assertRaises(ValueError) as exc:
1882 self.assertEqual(
1892 def setUp(self):
1893 self.get = Request("http://www.python.org/~jeremy/")
1894 self.post = Request("http://www.python.org/~jeremy/",
1897 self.head = Request("http://www.python.org/~jeremy/", method='HEAD')
1898 self.put = self.PutRequest("http://www.python.org/~jeremy/")
1899 self.force_post = self.PutRequest("http://www.python.org/~jeremy/",
1902 def test_method(self):
1903 self.assertEqual("POST", self.post.get_method())
1904 self.assertEqual("GET", self.get.get_method())
1905 self.assertEqual("HEAD", self.head.get_method())
1906 self.assertEqual("PUT", self.put.get_method())
1907 self.assertEqual("POST", self.force_post.get_method())
1909 def test_data(self):
1910 self.assertFalse(self.get.data)
1911 self.assertEqual("GET", self.get.get_method())
1912 self.get.data = "spam"
1913 self.assertTrue(self.get.data)
1914 self.assertEqual("POST", self.get.get_method())
1919 def test_setting_data_should_remove_content_length(self):
1920 self.assertNotIn("Content-length", self.get.unredirected_hdrs)
1921 self.get.add_unredirected_header("Content-length", 42)
1922 self.assertEqual(42, self.get.unredirected_hdrs["Content-length"])
1923 self.get.data = "spam"
1924 self.assertNotIn("Content-length", self.get.unredirected_hdrs)
1927 def test_deleting_data_should_remove_content_length(self):
1928 self.assertNotIn("Content-length", self.get.unredirected_hdrs)
1929 self.get.data = 'foo'
1930 self.get.add_unredirected_header("Content-length", 3)
1931 self.assertEqual(3, self.get.unredirected_hdrs["Content-length"])
1932 del self.get.data
1933 self.assertNotIn("Content-length", self.get.unredirected_hdrs)
1935 def test_get_full_url(self):
1936 self.assertEqual("http://www.python.org/~jeremy/",
1937 self.get.get_full_url())
1939 def test_selector(self):
1940 self.assertEqual("/~jeremy/", self.get.selector)
1942 self.assertEqual("/", req.selector)
1944 def test_get_type(self):
1945 self.assertEqual("http", self.get.type)
1947 def test_get_host(self):
1948 self.assertEqual("www.python.org", self.get.host)
1950 def test_get_host_unquote(self):
1952 self.assertEqual("www.python.org", req.host)
1954 def test_proxy(self):
1955 self.assertFalse(self.get.has_proxy())
1956 self.get.set_proxy("www.perl.org", "http")
1957 self.assertTrue(self.get.has_proxy())
1958 self.assertEqual("www.python.org", self.get.origin_req_host)
1959 self.assertEqual("www.perl.org", self.get.host)
1961 def test_wrapped_url(self):
1963 self.assertEqual("www.python.org", req.host)
1965 def test_url_fragment(self):
1967 self.assertEqual("/?qs=query", req.selector)
1969 self.assertEqual("/", req.selector)
1974 self.assertEqual(req.get_full_url(), url)
1976 def test_url_fullurl_get_full_url(self):
1982 self.assertEqual(req.get_full_url(), req.full_url)