From 50138bc67790898c7f0b025efb78dd45e655fca3 Mon Sep 17 00:00:00 2001 From: Flavian Date: Mon, 16 Dec 2024 17:08:53 +0100 Subject: [PATCH] test: add tests --- .github/workflows/check.yml | 56 +++++++++++++++++++++++++++++++++++++ .gitignore | 3 +- cspell.json | 2 ++ poetry.lock | 16 ++++++++++- pyproject.toml | 1 + tests/__init__.py | 0 tests/test_rest.py | 25 +++++++++++++++++ 7 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/check.yml create mode 100644 tests/__init__.py create mode 100644 tests/test_rest.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..766c4f5 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,56 @@ +name: Check + +concurrency: + group: ${{ github.workflow }}.${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + workflow_call: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + id: setup-python + with: + python-version: 3.13 + + - uses: snok/install-poetry@v1 + with: + version: 1.8.4 + virtualenvs-create: true + virtualenvs-in-project: true + virtualenvs-path: .venv + installer-parallel: true + + - uses: actions/cache@v3 + id: cached-poetry-dependencies + name: Virtual env cache + with: + path: ./.venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root + + - name: Install project + run: poetry install --no-interaction + + - name: Run tests + run: | + source .venv/bin/activate + python -m unittest tests/test_rest.py + env: + LNM_API_KEY: ${{ secrets.LNM_API_KEY }} + LNM_API_SECRET: ${{ secrets.LNM_API_SECRET }} + LNM_API_PASSPHRASE: ${{ secrets.LNM_API_PASSPHRASE }} + LNM_API_NETWORK: testnet diff --git a/.gitignore b/.gitignore index 4310151..c19131c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .venv __pycache__ .DS_Store -dist \ No newline at end of file +dist +.env \ No newline at end of file diff --git a/cspell.json b/cspell.json index beb6458..d6249d1 100644 --- a/cspell.json +++ b/cspell.json @@ -12,12 +12,14 @@ ], "words": [ "cashin", + "dotenv", "linkingpublickey", "lnmarkets", "lnurl", "nostr", "ohlcs", "pipreqs", + "snok", "stoploss", "takeprofit", "topt", diff --git a/poetry.lock b/poetry.lock index 428a70e..80033ef 100644 --- a/poetry.lock +++ b/poetry.lock @@ -139,6 +139,20 @@ files = [ [package.extras] all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"] +[[package]] +name = "python-dotenv" +version = "1.0.1" +description = "Read key-value pairs from a .env file and set them as environment variables" +optional = false +python-versions = ">=3.8" +files = [ + {file = "python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca"}, + {file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"}, +] + +[package.extras] +cli = ["click (>=5.0)"] + [[package]] name = "requests" version = "2.32.3" @@ -180,4 +194,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "8f6b6c24f619f4b3c83feba88e6f3e8b31d33569993e9e520ccb70cf6c4799c5" +content-hash = "9a600d0ca7a2c9819e3a3132c23e371a12791288834e9e6cbdbaaac95fbfc12a" diff --git a/pyproject.toml b/pyproject.toml index e781d4f..c9981f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ urls = { "Homepage" = "https://github.com/ln-markets/sdk-python" } [tool.poetry.dependencies] python = "^3.11" requests = "^2.32.3" +python-dotenv = "^1.0.1" [build-system] requires = ["poetry-core"] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_rest.py b/tests/test_rest.py new file mode 100644 index 0000000..102f7e3 --- /dev/null +++ b/tests/test_rest.py @@ -0,0 +1,25 @@ +import unittest +import os +from dotenv import load_dotenv + +from lnmarkets import LNMClient +from lnmarkets.user import get_user + +load_dotenv() + +class TestRest(unittest.TestCase): + def test_rest(self): + client = LNMClient({ + 'network': 'testnet', + 'key': os.getenv('LNM_API_KEY'), + 'secret': os.getenv('LNM_API_SECRET'), + 'passphrase': os.getenv('LNM_API_PASSPHRASE'), + }) + + user_info = get_user(client) + + self.assertRegex(user_info['uid'], r'^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$') + + +if __name__ == '__main__': + unittest.main()