From 543b30c4ee10cec67cd99c5ca511ab84b32d171f Mon Sep 17 00:00:00 2001 From: roadscape <roadscape@users.noreply.github.com> Date: Fri, 29 Jun 2018 14:11:37 -0500 Subject: [PATCH] get_state tests --- Pipfile | 1 + bin/stub_units | 13 ++++++------ setup.py | 3 ++- tests/test_server_condenser_api.py | 33 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 tests/test_server_condenser_api.py diff --git a/Pipfile b/Pipfile index b49322893..d7627b9ac 100644 --- a/Pipfile +++ b/Pipfile @@ -25,6 +25,7 @@ aiomysql = "*" "pytest-cov" = "*" "pytest-docker" = "*" "pytest-pylint" = "*" +"pytest-asyncio" = "*" "pytest-console-scripts" = "*" "yapf" = "*" "autopep8" = "*" diff --git a/bin/stub_units b/bin/stub_units index def0a015d..14cdad466 100755 --- a/bin/stub_units +++ b/bin/stub_units @@ -10,14 +10,15 @@ def _generate(infile): for line in open(infile, 'r'): line = line.strip() - if line[0:4] == 'def ' and line[0:5] != 'def _': - m = re.match(r'^def\s([^\(]+)\(([^\)]*)\):$', line) - assert m and m[1], "`%s` no match" % line - method = m[1] - args = m[2] + m = re.match(r'^(async )?def\s([^_\(][^\(]+)\(([^\)]*)\):$', line) + if m: + isasync = bool(m[1]) + method = m[2] + args = m[3] methods.append(method) - stub = "def test_%s():\n assert %s(%s) == expected" % (method, method, args) + stub = "def test_%s():\n assert %s%s(%s) == expected" % ( + method, 'await ' if isasync else '', method, args) stubs.append(stub) outfile = open('tests/test_' + '_'.join(path[1:]) + '.py', 'w') diff --git a/setup.py b/setup.py index fa0732769..db569c0fc 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ tests_require = [ 'pytest', 'pytest-cov', 'pytest-pylint', + 'pytest-asyncio', 'pytest-console-scripts', 'git-pylint-commit-hook', 'pep8', @@ -20,7 +21,7 @@ tests_require = [ setup( name='hivemind', version='0.0.1', - description='Community consensus layer for the Steem blockchain', + description='Developer-friendly microservice powering social networks on the Steem blockchain.', long_description=open('README.md').read(), packages=find_packages(exclude=['scripts']), setup_requires=['pytest-runner'], diff --git a/tests/test_server_condenser_api.py b/tests/test_server_condenser_api.py new file mode 100644 index 000000000..c745abcd4 --- /dev/null +++ b/tests/test_server_condenser_api.py @@ -0,0 +1,33 @@ +import pytest +from hive.server.condenser_api.get_state import get_state + +@pytest.mark.asyncio +async def test_get_state(): + ret = await get_state('/trending') + assert 'discussion_idx' in ret + + assert await get_state('trending') + assert await get_state('promoted') + assert await get_state('created') + assert await get_state('hot') + + assert await get_state('@test-safari') + assert await get_state('@test-safari/feed') + assert await get_state('@test-safari/comments') + assert await get_state('@test-safari/recent-replies') + + assert await get_state('spam/@test-safari/1ncq2-may-spam') + + assert await get_state('trending/blockchain') + + assert await get_state('tags') + + with pytest.raises(AssertionError): + await get_state('trending/blockchain/xxx') + + with pytest.raises(AssertionError): + await get_state('tags/xxx') + + with pytest.raises(Exception): + await get_state('witnesses') + -- GitLab