Skip to content
Snippets Groups Projects
Commit 3858849a authored by inso's avatar inso
Browse files

Migrate to aiohttp 3.0

parent a1f9e631
Branches
Tags
No related merge requests found
......@@ -41,7 +41,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/parameters', handler)
_, port, url = await self.create_server('GET', '/blockchain/parameters', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -110,7 +110,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/block/100', handler)
_, port, url = await self.create_server('GET', '/blockchain/block/100', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -124,7 +124,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/current', handler)
_, port, url = await self.create_server('GET', '/blockchain/current', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -185,7 +185,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/hardship/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU', handler)
_, port, url = await self.create_server('GET', '/blockchain/hardship/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -225,7 +225,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/memberships/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU', handler)
_, port, url = await self.create_server('GET', '/blockchain/memberships/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -247,7 +247,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/with/newcomers', handler)
_, port, url = await self.create_server('GET', '/blockchain/with/newcomers', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -269,7 +269,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/with/certs', handler)
_, port, url = await self.create_server('GET', '/blockchain/with/certs', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -291,7 +291,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/with/joiners', handler)
_, port, url = await self.create_server('GET', '/blockchain/with/joiners', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -313,7 +313,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/with/actives', handler)
_, port, url = await self.create_server('GET', '/blockchain/with/actives', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -335,7 +335,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/with/leavers', handler)
_, port, url = await self.create_server('GET', '/blockchain/with/leavers', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -458,7 +458,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/with/ud', handler)
_, port, url = await self.create_server('GET', '/blockchain/with/ud', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -480,7 +480,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/blockchain/with/tx', handler)
_, port, url = await self.create_server('GET', '/blockchain/with/tx', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......
......@@ -30,7 +30,7 @@ class TestBMANetwork(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/network/peering', handler)
_, port, url = await self.create_server('GET', '/network/peering', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -70,7 +70,7 @@ class TestBMANetwork(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/network/peering/peers', handler)
_, port, url = await self.create_server('GET', '/network/peering/peers', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......
......@@ -126,7 +126,7 @@ class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/tx/history/pubkey', handler)
_, port, url = await self.create_server('GET', '/tx/history/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -140,7 +140,7 @@ class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/tx/history/pubkey/blocks/0/100', handler)
_, port, url = await self.create_server('GET', '/tx/history/pubkey/blocks/0/100', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -179,7 +179,7 @@ class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/tx/sources/pubkey', handler)
_, port, url = await self.create_server('GET', '/tx/sources/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......
......@@ -78,7 +78,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/wot/lookup/pubkey', handler)
_, port, url = await self.create_server('GET', '/wot/lookup/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -102,7 +102,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/wot/members', handler)
_, port, url = await self.create_server('GET', '/wot/members', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -156,7 +156,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/wot/certifiers-of/pubkey', handler)
_, port, url = await self.create_server('GET', '/wot/certifiers-of/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -188,7 +188,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
}), "utf-8"), content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/wot/certifiers-of/pubkey', handler)
_, port, url = await self.create_server('GET', '/wot/certifiers-of/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......@@ -202,7 +202,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
return web.Response(body=b'{}', content_type='application/json')
async def go():
_, srv, port, url = await self.create_server('GET', '/wot/certified-by/pubkey', handler)
_, port, url = await self.create_server('GET', '/wot/certified-by/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
async with aiohttp.ClientSession() as session:
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
......
......@@ -10,12 +10,15 @@ class WebFunctionalSetupMixin:
def setUp(self):
self.handler = None
self.runner = None
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def tearDown(self):
if self.handler:
self.loop.run_until_complete(self.handler.shutdown())
if self.runner:
self.loop.run_until_complete(self.runner.cleanup())
try:
self.loop.stop()
self.loop.close()
......@@ -30,17 +33,17 @@ class WebFunctionalSetupMixin:
return port
async def create_server(self, method, path, handler=None, ssl_ctx=None):
app = web.Application()
if handler:
app.router.add_route(method, path, handler)
port = self.find_unused_port()
self.handler = app.make_handler(
keep_alive_on=False,
access_log=log.access_logger)
srv = await self.loop.create_server(
self.handler, '127.0.0.1', port, ssl=ssl_ctx)
self.runner = web.AppRunner(app)
await self.runner.setup()
site = web.TCPSite(self.runner, 'localhost', port)
await site.start()
protocol = "https" if ssl_ctx else "http"
url = "{}://127.0.0.1:{}".format(protocol, port) + path
self.addCleanup(srv.close)
return app, srv, port, url
\ No newline at end of file
return app, port, url
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment