def test_assert_same_host(self): c = connection_from_url('http://google.com:80') try: yield From(c.request('GET', 'http://yahoo.com:80', assert_same_host=True)) except HostChangedError as e: pass else: self.assertTrue(False, 'HostChangedError not raised by request')
def test_same_host(self): same_host = [ ('http://google.com/', '/'), ('http://google.com/', 'http://google.com/'), ('http://google.com/', 'http://google.com'), ('http://google.com/', 'http://google.com/abra/cadabra'), ('http://google.com:42/', 'http://google.com:42/abracadabra'), # Test comparison using default ports ('http://google.com:80/', 'http://google.com/abracadabra'), ('http://google.com/', 'http://google.com:80/abracadabra'), ('https://google.com:443/', 'https://google.com/abracadabra'), ('https://google.com/', 'https://google.com:443/abracadabra'), ] for a, b in same_host: c = connection_from_url(a) self.assertTrue(c.is_same_host(b), "%s =? %s" % (a, b)) not_same_host = [ ('https://google.com/', 'http://google.com/'), ('http://google.com/', 'https://google.com/'), ('http://yahoo.com/', 'http://google.com/'), ('http://google.com:42', 'https://google.com/abracadabra'), ('http://google.com', 'https://google.net/'), # Test comparison with default ports ('http://google.com:42', 'http://google.com'), ('https://google.com:42', 'https://google.com'), ('http://google.com:443', 'http://google.com'), ('https://google.com:80', 'https://google.com'), ('http://google.com:443', 'https://google.com'), ('https://google.com:80', 'http://google.com'), ('https://google.com:443', 'http://google.com'), ('http://google.com:80', 'https://google.com'), ] for a, b in not_same_host: c = connection_from_url(a) self.assertFalse(c.is_same_host(b), "%s =? %s" % (a, b)) c = connection_from_url(b) self.assertFalse(c.is_same_host(a), "%s =? %s" % (b, a))
def test_pool_close(self): pool = connection_from_url('http://google.com:80') # Populate with some connections conn1 = yield From(pool._get_conn(timeout=0.01)) conn2 = yield From(pool._get_conn(timeout=0.01)) conn3 = yield From(pool._get_conn(timeout=0.01)) pool._put_conn(conn1) pool._put_conn(conn2) old_pool_queue = pool.pool pool.close() self.assertEqual(pool.pool, None) self.aioAssertRaises(ClosedPoolError, pool._get_conn) pool._put_conn(conn3) self.aioAssertRaises(ClosedPoolError, pool._get_conn) self.aioAssertRaises(Empty, old_pool_queue.get, block=False)
def test_oldapi(self): http = ProxyManager(connection_from_url(self.proxy_url)) r = yield From(http.request('GET', '%s/' % self.http_url)) self.assertEqual(r.status, 200)