diff --git a/Pipfile b/Pipfile index b493228931a459f863517c0437f5b8cdbcc67b1b..d7627b9ac001f2a9c2cd33723b75b0cac4b9ceb2 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 def0a015da6f132fb10a661cfa8db2fe757f678e..14cdad4669ba5ca0a020e8114b4b73d4c9768af8 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 fa07327695973e4572f29ea7eee5e2976ff7f363..db569c0fc74b59016a5e77c86ca41eb3963d80c1 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 0000000000000000000000000000000000000000..c745abcd4f6af5debed6d215dd371fce883719e2 --- /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') +