From 4cd8488ed79cfec365cfc22d0af6336838ee8878 Mon Sep 17 00:00:00 2001 From: joriscarrier Date: Tue, 15 Jan 2019 22:57:45 +0100 Subject: [PATCH] tests(server): test storing (#64) --- dev-requirements.txt | 1 + kademlia/tests/conftest.py | 14 ++++++++++++++ kademlia/tests/test_server.py | 15 +++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 kademlia/tests/conftest.py diff --git a/dev-requirements.txt b/dev-requirements.txt index c93065f..8b96c7a 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,3 +4,4 @@ sphinx>=1.6.5 sphinxcontrib-napoleon>=0.6.1 sphinxcontrib-zopeext>=0.2.1 pytest>=4.1.0 +pytest-asyncio>=0.10.0 diff --git a/kademlia/tests/conftest.py b/kademlia/tests/conftest.py new file mode 100644 index 0000000..7b4c626 --- /dev/null +++ b/kademlia/tests/conftest.py @@ -0,0 +1,14 @@ +import pytest + +from kademlia.network import Server + + +@pytest.yield_fixture +def bootstrap_node(event_loop): + server = Server() + event_loop.run_until_complete(server.listen(8468)) + + try: + yield ('127.0.0.1', 8468) + finally: + server.stop() diff --git a/kademlia/tests/test_server.py b/kademlia/tests/test_server.py index e2c39d2..43df098 100644 --- a/kademlia/tests/test_server.py +++ b/kademlia/tests/test_server.py @@ -1,10 +1,25 @@ import unittest import asyncio +import pytest + from kademlia.network import Server from kademlia.protocol import KademliaProtocol +@pytest.mark.asyncio +async def test_storing(bootstrap_node): + server = Server() + await server.listen(bootstrap_node[1] + 1) + await server.bootstrap([bootstrap_node]) + await server.set('key', 'value') + result = await server.get('key') + + assert result == 'value' + + server.stop() + + class SwappableProtocolTests(unittest.TestCase): def test_default_protocol(self):