Commit 934c9776 authored by inso's avatar inso

Endpoints now yields conn handlers

parent cd0eabe7
......@@ -185,14 +185,13 @@ class BMAEndpoint(Endpoint):
Return connection handler instance for the endpoint
:param aiohttp.ClientSession session: AIOHTTP client session instance
:rtype: ConnectionHandler
"""
if self.server:
return ConnectionHandler("http", "ws", self.server, self.port, proxy, session)
yield ConnectionHandler("http", "ws", self.server, self.port, proxy, session)
elif self.ipv6:
return ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, proxy, session)
yield ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, proxy, session)
else:
return ConnectionHandler("http", "ws", self.ipv4, self.port, proxy, session)
yield ConnectionHandler("http", "ws", self.ipv4, self.port, proxy, session)
def __str__(self):
return self.inline()
......@@ -243,8 +242,8 @@ class SecuredBMAEndpoint(BMAEndpoint):
:rtype: ConnectionHandler
"""
if self.server:
return ConnectionHandler("https", "wss", self.server, self.port, proxy, session)
yield ConnectionHandler("https", "wss", self.server, self.port, proxy, session)
elif self.ipv6:
return ConnectionHandler("https", "wss", "[{0}]".format(self.ipv6), self.port, proxy, session)
yield ConnectionHandler("https", "wss", "[{0}]".format(self.ipv6), self.port, proxy, session)
else:
return ConnectionHandler("https", "wss", self.ipv4, self.port, proxy, session)
yield ConnectionHandler("https", "wss", self.ipv4, self.port, proxy, session)
......@@ -100,8 +100,8 @@ class Transaction(Document):
:param int locktime:
:param list[str] issuers:
:param list[InputSource] inputs:
:param unlocks:
:param outputs:
:param list[Unlock] unlocks:
:param list[OutputSource] outputs:
:param comment:
:param signatures:
"""
......
......@@ -40,7 +40,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/parameters', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await parameters(connection)
self.loop.run_until_complete(go())
......@@ -109,7 +109,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/block/100', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await block(connection, 100)
self.loop.run_until_complete(go())
......@@ -123,7 +123,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/current', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await current(connection)
self.loop.run_until_complete(go())
......@@ -184,7 +184,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/hardship/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await hardship(connection, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.loop.run_until_complete(go())
......@@ -224,7 +224,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/memberships/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await memberships(connection, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
self.loop.run_until_complete(go())
......@@ -246,7 +246,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/with/newcomers', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await newcomers(connection)
self.loop.run_until_complete(go())
......@@ -268,7 +268,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/with/certs', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await certifications(connection)
self.loop.run_until_complete(go())
......@@ -290,7 +290,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/with/joiners', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await joiners(connection)
self.loop.run_until_complete(go())
......@@ -312,7 +312,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/with/actives', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await actives(connection)
self.loop.run_until_complete(go())
......@@ -334,7 +334,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/with/leavers', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await leavers(connection)
self.loop.run_until_complete(go())
......@@ -457,7 +457,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/with/ud', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await ud(connection)
self.loop.run_until_complete(go())
......@@ -479,7 +479,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/blockchain/with/tx', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await tx(connection)
self.loop.run_until_complete(go())
......@@ -33,7 +33,7 @@ class TestBMANetwork(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/network/peering', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await network.peering(connection)
self.loop.run_until_complete(go())
......@@ -73,7 +73,7 @@ class TestBMANetwork(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/network/peering/peers', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await network.peers(connection)
self.loop.run_until_complete(go())
......@@ -129,7 +129,7 @@ class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/tx/history/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await history(connection, 'pubkey')
self.loop.run_until_complete(go())
......@@ -143,7 +143,7 @@ class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/tx/history/pubkey/blocks/0/100', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await blocks(connection, 'pubkey', 0, 100)
self.loop.run_until_complete(go())
......@@ -182,7 +182,7 @@ class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/tx/sources/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await sources(connection, 'pubkey')
self.loop.run_until_complete(go())
\ No newline at end of file
......@@ -81,7 +81,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/wot/lookup/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await lookup(connection, 'pubkey')
self.loop.run_until_complete(go())
......@@ -105,7 +105,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/wot/members', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await members(connection)
self.loop.run_until_complete(go())
......@@ -159,7 +159,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/wot/certifiers-of/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await certifiers_of(connection, 'pubkey')
self.loop.run_until_complete(go())
......@@ -191,7 +191,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/wot/certifiers-of/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await certifiers_of(connection, 'pubkey')
self.loop.run_until_complete(go())
......@@ -205,7 +205,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase):
_, srv, port, url = await self.create_server('GET', '/wot/certified-by/pubkey', handler)
with self.assertRaises(jsonschema.exceptions.ValidationError):
with aiohttp.ClientSession() as session:
connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)
connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session))
await certified_by(connection, 'pubkey')
self.loop.run_until_complete(go())
......
......@@ -7,17 +7,17 @@ class Test_BMA_API(unittest.TestCase):
def test_reverse_url_complete(self):
endpoint = BMAEndpoint("test.com", "124.2.2.1", "2001:0db8:0000:85a3:0000:0000:ac1f:8001 ", 9092)
api = API(endpoint.conn_handler(), "any")
api = API(next(endpoint.conn_handler()), "any")
self.assertEqual(api.reverse_url("http", "/test/url"), "http://test.com:9092/any/test/url")
def test_reverse_url_only_ipv4(self):
endpoint = BMAEndpoint(None, "124.2.2.1", None, 9092)
api = API(endpoint.conn_handler(), "any")
api = API(next(endpoint.conn_handler()), "any")
self.assertEqual(api.reverse_url("http", "/test/url"), "http://124.2.2.1:9092/any/test/url")
def test_reverse_url_only_ipv6(self):
endpoint = BMAEndpoint(None, None, "2001:0db8:0000:85a3:0000:0000:ac1f:8001", 9092)
api = API(endpoint.conn_handler(), "any")
api = API(next(endpoint.conn_handler()), "any")
self.assertEqual(api.reverse_url("http", "/test/url"), "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:9092/any/test/url")
def test_parse_error(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment