From fe3118760a065f978124edaeed94396dac57e7b4 Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Sun, 24 Jun 2018 11:14:16 +0200 Subject: [PATCH] issue #46 remove useless generator in conn_handler return (break BC) Fix python version required in Readme.rst Fix requirements.txt All tests pass. --- README.rst | 30 +++++++++++------ duniterpy/documents/peer.py | 43 +++++++++++++------------ examples/create_and_publish_identity.py | 2 +- examples/request_data.py | 2 +- examples/save_revoke_document.py | 2 +- examples/send_certification.py | 2 +- examples/send_membership.py | 2 +- examples/send_transaction.py | 2 +- requirements.txt | 13 ++++---- tests/api/bma/test_blockchain.py | 24 +++++++------- tests/api/bma/test_network.py | 4 +-- tests/api/bma/test_tx.py | 8 ++--- tests/api/bma/test_wot.py | 10 +++--- tests/api/bma/test_ws2p.py | 2 +- tests/api/test_bma.py | 6 ++-- 15 files changed, 83 insertions(+), 69 deletions(-) diff --git a/README.rst b/README.rst index 6adc76eb..85150556 100644 --- a/README.rst +++ b/README.rst @@ -16,28 +16,38 @@ Features Requirements ------------ -* Python >= 3.5 -* `aiohttp >= 0.19 <https://pypi.python.org/pypi/aiohttp>`_ -* `pylibscrypt <https://pypi.python.org/pypi/pylibscrypt>`_ -* `libnacl <https://pypi.python.org/pypi/libnacl>`_ -* `base58 <https://pypi.python.org/pypi/base58>`_ +* Python >= 3.5.2 +* `aiohttp >= 0.19 <https://pypi.org/pypi/aiohttp>`_ +* `pylibscrypt <https://pypi.org/pypi/pylibscrypt>`_ +* `libnacl <https://pypi.org/pypi/libnacl>`_ +* `base58 <https://pypi.org/pypi/base58>`_ +* `attr <https://pypi.org/project/attr/>`_ Installation ------------ -You can install duniter-python-api and all its dependencies via the following pip install: +You can install duniter-python-api and all its dependencies via the following pip install:: -:code:`pip3 install duniterpy` + pip3 install duniterpy Please take a look at the document `HTTP API <https://git.duniter.org/nodes/typescript/duniter/blob/master/doc/HTTP_API.md>`_ to learn about the API. Development ----------- -* Create a python environment with pyenv +* Create a python environment with `pyenv <https://github.com/pyenv/pyenv>`_ :: + + curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash` + * Add PYTHONPATH env var to your shell containing the path to this repository -* Take a look at examples -* Run examples from parent folder :code:`python examples/request_data.py` +* Run unit tests with :: + + python -m unittest + +* Take a look at examples folder +* Run examples from parent folder :: + + python examples/request_data.py Documentation ------------- diff --git a/duniterpy/documents/peer.py b/duniterpy/documents/peer.py index cf74b3ca..a638d536 100644 --- a/duniterpy/documents/peer.py +++ b/duniterpy/documents/peer.py @@ -1,4 +1,5 @@ import re +import aiohttp from typing import Generator from ..api.bma import ConnectionHandler @@ -184,20 +185,20 @@ class BMAEndpoint(Endpoint): IPv6=(" {0}".format(self.ipv6) if self.ipv6 else ""), PORT=(" {0}".format(self.port) if self.port else "")) - def conn_handler(self, session=None, proxy=None): + def conn_handler(self, session: aiohttp.ClientSession = None, proxy: str = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint :param aiohttp.ClientSession session: AIOHTTP client session instance :param str proxy: Proxy url - :rtype: Generator[ConnectionHandler, None, None] + :rtype: ConnectionHandler """ if self.server: - yield ConnectionHandler("http", "ws", self.server, self.port, "", proxy, session) + return ConnectionHandler("http", "ws", self.server, self.port, "", proxy, session) elif self.ipv6: - yield ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, "", proxy, session) - else: - yield ConnectionHandler("http", "ws", self.ipv4, self.port, "", proxy, session) + return ConnectionHandler("http", "ws", "[{0}]".format(self.ipv6), self.port, "", proxy, session) + + return ConnectionHandler("http", "ws", self.ipv4, self.port, "", proxy, session) def __str__(self): return self.inline() @@ -242,20 +243,20 @@ class SecuredBMAEndpoint(BMAEndpoint): inlined = [str(info) for info in (self.server, self.ipv4, self.ipv6, self.port, self.path) if info] return SecuredBMAEndpoint.API + " " + " ".join(inlined) - def conn_handler(self, session=None, proxy=None): + def conn_handler(self, session: aiohttp.ClientSession = None, proxy: str = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint :param aiohttp.ClientSession session: AIOHTTP client session instance :param str proxy: Proxy url - :rtype: Generator[ConnectionHandler, None, None] + :rtype: ConnectionHandler """ if self.server: - yield ConnectionHandler("https", "wss", self.server, self.port, self.path, proxy, session) + return ConnectionHandler("https", "wss", self.server, self.port, self.path, proxy, session) elif self.ipv6: - yield ConnectionHandler("https", "wss", "[{0}]".format(self.ipv6), self.port, self.path, proxy, session) - else: - yield ConnectionHandler("https", "wss", self.ipv4, self.port, self.path, proxy, session) + return ConnectionHandler("https", "wss", "[{0}]".format(self.ipv6), self.port, self.path, proxy, session) + + return ConnectionHandler("https", "wss", self.ipv4, self.port, self.path, proxy, session) class WS2PEndpoint(Endpoint): @@ -289,14 +290,15 @@ class WS2PEndpoint(Endpoint): inlined = [str(info) for info in (self.ws2pid, self.server, self.port, self.path) if info] return WS2PEndpoint.API + " " + " ".join(inlined) - def conn_handler(self, session=None, proxy=None): + def conn_handler(self, session: aiohttp.ClientSession = None, proxy: str = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint :param aiohttp.ClientSession session: AIOHTTP client session instance + :param str proxy: Proxy url :rtype: ConnectionHandler """ - yield ConnectionHandler("https", "wss", self.server, self.port, self.path, proxy, session) + return ConnectionHandler("https", "wss", self.server, self.port, self.path, proxy, session) def __str__(self): return self.inline() @@ -335,14 +337,15 @@ class ESUserEndpoint(Endpoint): inlined = [str(info) for info in (self.server, self.port) if info] return ESUserEndpoint.API + " " + " ".join(inlined) - def conn_handler(self, session=None, proxy=None): + def conn_handler(self, session: aiohttp.ClientSession = None, proxy: str = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint :param aiohttp.ClientSession session: AIOHTTP client session instance + :param str proxy: Proxy url :rtype: ConnectionHandler """ - yield ConnectionHandler("https", "wss", self.server, self.port, "", proxy, session) + return ConnectionHandler("https", "wss", self.server, self.port, "", proxy, session) def __str__(self): return self.inline() @@ -380,14 +383,15 @@ class ESSubscribtionEndpoint(Endpoint): inlined = [str(info) for info in (self.server, self.port) if info] return ESSubscribtionEndpoint.API + " " + " ".join(inlined) - def conn_handler(self, session=None, proxy=None): + def conn_handler(self, session: aiohttp.ClientSession = None, proxy: str = None) -> ConnectionHandler: """ Return connection handler instance for the endpoint :param aiohttp.ClientSession session: AIOHTTP client session instance + :param str proxy: Proxy url :rtype: ConnectionHandler """ - yield ConnectionHandler("https", "wss", self.server, self.port, "", proxy, session) + return ConnectionHandler("https", "wss", self.server, self.port, "", proxy, session) def __str__(self): return self.inline() @@ -402,8 +406,7 @@ class ESSubscribtionEndpoint(Endpoint): return hash((ESSubscribtionEndpoint.API, self.server, self.port)) - -MANAGED_API={ +MANAGED_API = { BMAEndpoint.API: BMAEndpoint, SecuredBMAEndpoint.API: SecuredBMAEndpoint, WS2PEndpoint.API: WS2PEndpoint, diff --git a/examples/create_and_publish_identity.py b/examples/create_and_publish_identity.py index 559fd83d..b4fb846d 100644 --- a/examples/create_and_publish_identity.py +++ b/examples/create_and_publish_identity.py @@ -63,7 +63,7 @@ async def main(): """ # connection handler from BMA endpoint - connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) # capture current block to get version and currency and blockstamp current_block = await bma.blockchain.current(connection) diff --git a/examples/request_data.py b/examples/request_data.py index 1680352c..87efed5f 100644 --- a/examples/request_data.py +++ b/examples/request_data.py @@ -22,7 +22,7 @@ async def main(): Main code """ # connection handler from BMA endpoint - connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) # Get the node summary infos response = await bma.node.summary(connection) diff --git a/examples/save_revoke_document.py b/examples/save_revoke_document.py index 3664de56..1209db35 100644 --- a/examples/save_revoke_document.py +++ b/examples/save_revoke_document.py @@ -113,7 +113,7 @@ async def main(): exit(0) # connection handler from BMAS endpoint - connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) # capture current block to get currency name current_block = await bma.blockchain.current(connection) diff --git a/examples/send_certification.py b/examples/send_certification.py index b7318cbd..d31fb765 100644 --- a/examples/send_certification.py +++ b/examples/send_certification.py @@ -92,7 +92,7 @@ async def main(): Main code """ # connection handler from BMA endpoint - connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") diff --git a/examples/send_membership.py b/examples/send_membership.py index b1d22ea8..790aa6a3 100644 --- a/examples/send_membership.py +++ b/examples/send_membership.py @@ -97,7 +97,7 @@ async def main(): Main code """ # connection handler from BMA endpoint - connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) # capture current block to get version and currency and blockstamp current_block = await bma.blockchain.current(connection) diff --git a/examples/send_transaction.py b/examples/send_transaction.py index a78f3a3c..efd75736 100644 --- a/examples/send_transaction.py +++ b/examples/send_transaction.py @@ -95,7 +95,7 @@ async def main(): Main code """ # connection handler from BMA endpoint - connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") diff --git a/requirements.txt b/requirements.txt index 3956c62a..38c71ad3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ -aiohttp -pylibscrypt -libnacl -base58 -jsonschema -pypeg2 +aiohttp >= 3.3.2 +pylibscrypt >= 1.7.1 +libnacl >= 1.6.1 +base58 >= 1.0.0 +jsonschema >= 2.6.0 +pypeg2 >= 2.15.2 +attr >= 0.3.1 diff --git a/tests/api/bma/test_blockchain.py b/tests/api/bma/test_blockchain.py index a8ea1b95..a4c3b41d 100644 --- a/tests/api/bma/test_blockchain.py +++ b/tests/api/bma/test_blockchain.py @@ -44,7 +44,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await parameters(connection) self.loop.run_until_complete(go()) @@ -113,7 +113,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await block(connection, 100) self.loop.run_until_complete(go()) @@ -127,7 +127,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await current(connection) self.loop.run_until_complete(go()) @@ -188,7 +188,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await hardship(connection, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU") self.loop.run_until_complete(go()) @@ -228,7 +228,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await memberships(connection, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU") self.loop.run_until_complete(go()) @@ -250,7 +250,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await newcomers(connection) self.loop.run_until_complete(go()) @@ -272,7 +272,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await certifications(connection) self.loop.run_until_complete(go()) @@ -294,7 +294,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await joiners(connection) self.loop.run_until_complete(go()) @@ -316,7 +316,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await actives(connection) self.loop.run_until_complete(go()) @@ -338,7 +338,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await leavers(connection) self.loop.run_until_complete(go()) @@ -461,7 +461,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await ud(connection) self.loop.run_until_complete(go()) @@ -483,7 +483,7 @@ class Test_BMA_blockchain(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await tx(connection) self.loop.run_until_complete(go()) diff --git a/tests/api/bma/test_network.py b/tests/api/bma/test_network.py index bf7b68d4..a4600ab7 100644 --- a/tests/api/bma/test_network.py +++ b/tests/api/bma/test_network.py @@ -33,7 +33,7 @@ class TestBMANetwork(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = 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): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await network.peers(connection) self.loop.run_until_complete(go()) diff --git a/tests/api/bma/test_tx.py b/tests/api/bma/test_tx.py index 6e8d72ad..3e8d78fb 100644 --- a/tests/api/bma/test_tx.py +++ b/tests/api/bma/test_tx.py @@ -129,7 +129,7 @@ class Test_BMA_TX(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = 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): _, 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)) + connection = 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): _, 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)) + connection = 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 + self.loop.run_until_complete(go()) diff --git a/tests/api/bma/test_wot.py b/tests/api/bma/test_wot.py index c44fbed6..061890e9 100644 --- a/tests/api/bma/test_wot.py +++ b/tests/api/bma/test_wot.py @@ -168,7 +168,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await lookup(connection, 'pubkey') self.loop.run_until_complete(go()) @@ -192,7 +192,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await members(connection) self.loop.run_until_complete(go()) @@ -246,7 +246,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await certifiers_of(connection, 'pubkey') self.loop.run_until_complete(go()) @@ -278,7 +278,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await certifiers_of(connection, 'pubkey') self.loop.run_until_complete(go()) @@ -292,7 +292,7 @@ class Test_BMA_Wot(WebFunctionalSetupMixin, unittest.TestCase): _, 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)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await certified_by(connection, 'pubkey') self.loop.run_until_complete(go()) diff --git a/tests/api/bma/test_ws2p.py b/tests/api/bma/test_ws2p.py index 3b911b5b..1e4c9e81 100644 --- a/tests/api/bma/test_ws2p.py +++ b/tests/api/bma/test_ws2p.py @@ -48,7 +48,7 @@ class Test_WS2P_Heads(WebFunctionalSetupMixin, unittest.TestCase): _, port, url = await self.create_server('GET', '/network/ws2p/heads', handler) with self.assertRaises(jsonschema.ValidationError): async with aiohttp.ClientSession() as session: - connection = next(BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)) + connection = BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session) await heads(connection) self.loop.run_until_complete(go()) diff --git a/tests/api/test_bma.py b/tests/api/test_bma.py index 9fa00d04..f6791bc7 100644 --- a/tests/api/test_bma.py +++ b/tests/api/test_bma.py @@ -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(next(endpoint.conn_handler()), "any") + api = API(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(next(endpoint.conn_handler()), "any") + api = API(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(next(endpoint.conn_handler()), "any") + api = API(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): -- GitLab