Skip to content

Commit

Permalink
Merge pull request #82 from aio-libs/aiohttp-2.0-support
Browse files Browse the repository at this point in the history
fix tests to work with aiohttp>=2.0
  • Loading branch information
rutsky authored Mar 28, 2017
2 parents 8ae4ada + 3e13937 commit 3f72542
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def read_file(filename):
],
test_suite="tests",
install_requires=[
"aiohttp>=1.1,<2.0",
"aiohttp>=1.1",
],
extras_require={
# TODO: Rich comparison in environment markers are broken in
Expand Down
34 changes: 19 additions & 15 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def setUp(self):

self.server = None

self.session = aiohttp.ClientSession()

def tearDown(self):
self.session.close()

if self.server is not None:
self.loop.run_until_complete(self.shutdown_server())

Expand Down Expand Up @@ -96,7 +100,7 @@ def shutdown_server(self):
self.server.close()
yield from self.handler.finish_connections()
yield from self.server.wait_closed()
yield from self.app.finish()
yield from self.app.cleanup()

self.server = None
self.app = None
Expand All @@ -117,7 +121,7 @@ def test_message_roundtrip(self):

yield from self.create_server(app)

response = yield from aiohttp.request("GET", self.server_url)
response = yield from self.session.request("GET", self.server_url)
self.assertEqual(response.status, 200)
data = yield from response.text()

Expand All @@ -143,7 +147,7 @@ def test_dummy_setup_roundtrip(self):

yield from self.create_server(app)

response = yield from aiohttp.request("GET", self.server_url)
response = yield from self.session.request("GET", self.server_url)
self.assertEqual(response.status, 200)
data = yield from response.text()

Expand All @@ -160,7 +164,7 @@ def test_dummy_setup_roundtrip_resource(self):

yield from self.create_server(app)

response = yield from aiohttp.request("GET", self.server_url)
response = yield from self.session.request("GET", self.server_url)
self.assertEqual(response.status, 200)
data = yield from response.text()

Expand All @@ -178,7 +182,7 @@ def _run_simple_requests_tests(self,
def run_test(test):
"""Run single test"""

response = yield from aiohttp.get(
response = yield from self.session.get(
self.server_url + "resource",
headers=test.get("request_headers", {}))
self.assertEqual(response.status, 200)
Expand Down Expand Up @@ -448,7 +452,7 @@ def _run_preflight_requests_tests(self, tests_descriptions, use_resources):
def run_test(test):
"""Run single test"""

response = yield from aiohttp.options(
response = yield from self.session.options(
self.server_url + "resource",
headers=test.get("request_headers", {}))
self.assertEqual(response.status, test.get("response_status", 200))
Expand Down Expand Up @@ -627,7 +631,7 @@ def test_preflight_request_multiple_routes_with_one_options(self):

yield from self.create_server(app)

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url + "user",
headers={
hdrs.ORIGIN: "http://example.org",
Expand Down Expand Up @@ -660,7 +664,7 @@ def test_preflight_request_multiple_routes_with_one_options_resource(self):

yield from self.create_server(app)

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url + "user",
headers={
hdrs.ORIGIN: "http://example.org",
Expand Down Expand Up @@ -689,7 +693,7 @@ def test_preflight_request_headers_resource(self):

yield from self.create_server(app)

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url,
headers={
hdrs.ORIGIN: "http://example.org",
Expand All @@ -705,7 +709,7 @@ def test_preflight_request_headers_resource(self):
response.headers[hdrs.ACCESS_CONTROL_ALLOW_HEADERS].upper(),
"content-type".upper())

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url,
headers={
hdrs.ORIGIN: "http://example.org",
Expand All @@ -722,7 +726,7 @@ def test_preflight_request_headers_resource(self):
{"X-Header".upper(), "content-type".upper()})
self.assertEqual((yield from response.text()), "")

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url,
headers={
hdrs.ORIGIN: "http://example.org",
Expand Down Expand Up @@ -756,7 +760,7 @@ def test_preflight_request_headers(self):

yield from self.create_server(app)

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url,
headers={
hdrs.ORIGIN: "http://example.org",
Expand All @@ -772,7 +776,7 @@ def test_preflight_request_headers(self):
response.headers[hdrs.ACCESS_CONTROL_ALLOW_HEADERS].upper(),
"content-type".upper())

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url,
headers={
hdrs.ORIGIN: "http://example.org",
Expand All @@ -789,7 +793,7 @@ def test_preflight_request_headers(self):
{"X-Header".upper(), "content-type".upper()})
self.assertEqual((yield from response.text()), "")

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", self.server_url,
headers={
hdrs.ORIGIN: "http://example.org",
Expand Down Expand Up @@ -824,7 +828,7 @@ def test_static_route(self):

yield from self.create_server(app)

response = yield from aiohttp.request(
response = yield from self.session.request(
"OPTIONS", URL(self.server_url) / "static/test_page.html",
headers={
hdrs.ORIGIN: "http://example.org",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_real_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def stop_servers(self):
server_descr.server.close()
yield from server_descr.handler.finish_connections()
yield from server_descr.server.wait_closed()
yield from server_descr.app.finish()
yield from server_descr.app.cleanup()

self.servers = {}

Expand Down

0 comments on commit 3f72542

Please sign in to comment.