From ed672b37298bd026696d66249892b460099446a6 Mon Sep 17 00:00:00 2001 From: Philip Nuzhnyi Date: Mon, 30 Oct 2023 16:19:38 +0000 Subject: [PATCH] add basic smoke tests for the data layer --- poetry.lock | 20 +++++++++++++++++++- pyproject.toml | 1 + tests/test_common_sense.py | 5 ----- tests/test_data.py | 20 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) delete mode 100644 tests/test_common_sense.py create mode 100644 tests/test_data.py diff --git a/poetry.lock b/poetry.lock index 388e6e5..5c6dc5c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1186,6 +1186,24 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "pytest-asyncio" +version = "0.21.1" +description = "Pytest support for asyncio" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-asyncio-0.21.1.tar.gz", hash = "sha256:40a7eae6dded22c7b604986855ea48400ab15b069ae38116e8c01238e9eeb64d"}, + {file = "pytest_asyncio-0.21.1-py3-none-any.whl", hash = "sha256:8666c1c8ac02631d7c51ba282e0c69a8a452b211ffedf2599099845da5c5c37b"}, +] + +[package.dependencies] +pytest = ">=7.0.0" + +[package.extras] +docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] +testing = ["coverage (>=6.2)", "flaky (>=3.5.0)", "hypothesis (>=5.7.1)", "mypy (>=0.931)", "pytest-trio (>=0.7.0)"] + [[package]] name = "python-dotenv" version = "1.0.0" @@ -1751,4 +1769,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "33a097f91d2b8441d6ea93bf62cb90ffbbcefc43d449699d5705f953fd8291be" +content-hash = "ad62c032e7d6e1fc6cfe386626ebfb8a717caa96f8a185f2bfaadbde6d80f712" diff --git a/pyproject.toml b/pyproject.toml index 8a1640b..757bd10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ python-dotenv = "1.0.0" [tool.poetry.group.dev.dependencies] pytest = "^7.4.3" +pytest-asyncio = "^0.21.1" [build-system] requires = ["poetry-core"] diff --git a/tests/test_common_sense.py b/tests/test_common_sense.py deleted file mode 100644 index 73c50e6..0000000 --- a/tests/test_common_sense.py +++ /dev/null @@ -1,5 +0,0 @@ -# test placeholder - - -def test_common_sense(): - assert 2 == 2 diff --git a/tests/test_data.py b/tests/test_data.py new file mode 100644 index 0000000..117e194 --- /dev/null +++ b/tests/test_data.py @@ -0,0 +1,20 @@ +import pytest + +from dotenv import load_dotenv +load_dotenv(".env.example") + +from bots.settings import TOKEN_ADDRESS, STABLE_TOKEN_ADDRESS +from bots.data import Token, Price + +@pytest.mark.asyncio +async def test_get_by_token_address(): + t = await Token.get_by_token_address(TOKEN_ADDRESS) + assert t.token_address == TOKEN_ADDRESS + assert t.listed == True + +@pytest.mark.asyncio +async def test_get_prices(): + prices = await Price.get_prices([await Token.get_by_token_address(TOKEN_ADDRESS)]) + assert len(prices) == 1 + [price] = prices + assert price.pretty_price != 0 \ No newline at end of file