diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2add801 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI +on: + push: + branches: + - main + pull_request: + +jobs: + lint: + uses: lnbits/lnbits/.github/workflows/lint.yml@dev + + tests: + runs-on: ubuntu-latest + needs: [lint] + strategy: + matrix: + python-version: ['3.9', '3.10'] + steps: + - uses: actions/checkout@v4 + - uses: lnbits/lnbits/.github/actions/prepare@dev + with: + python-version: ${{ matrix.python-version }} + - name: Run pytest + uses: pavelzw/pytest-action@v2 + env: + LNBITS_BACKEND_WALLET_CLASS: FakeWallet + PYTHONUNBUFFERED: 1 + DEBUG: true + with: + verbose: true + job-summary: true + emoji: false + click-to-expand: true + custom-pytest: poetry run pytest + report-title: 'test (${{ matrix.python-version }})' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 4e02f97..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: lint -on: - push: - branches: - - main - pull_request: - -jobs: - lint: - uses: lnbits/lnbits/.github/workflows/lint.yml@dev diff --git a/__init__.py b/example/__init__.py similarity index 89% rename from __init__.py rename to example/__init__.py index 34ef08d..a9ae528 100644 --- a/__init__.py +++ b/example/__init__.py @@ -2,7 +2,6 @@ from fastapi import APIRouter from lnbits.db import Database -from lnbits.tasks import create_permanent_unique_task from loguru import logger from .tasks import wait_for_paid_invoices @@ -34,7 +33,9 @@ def example_stop(): def example_start(): - # ignore will be removed in lnbits `0.12.6` + # ignore will be removed in lnbits `0.12.7` # https://github.com/lnbits/lnbits/pull/2417 + from lnbits.tasks import create_permanent_unique_task + task = create_permanent_unique_task("ext_testing", wait_for_paid_invoices) # type: ignore scheduled_tasks.append(task) diff --git a/config.json b/example/config.json similarity index 100% rename from config.json rename to example/config.json diff --git a/crud.py b/example/crud.py similarity index 100% rename from crud.py rename to example/crud.py diff --git a/migrations.py b/example/migrations.py similarity index 100% rename from migrations.py rename to example/migrations.py diff --git a/models.py b/example/models.py similarity index 100% rename from models.py rename to example/models.py diff --git a/static/1.png b/example/static/1.png similarity index 100% rename from static/1.png rename to example/static/1.png diff --git a/static/2.png b/example/static/2.png similarity index 100% rename from static/2.png rename to example/static/2.png diff --git a/static/3.png b/example/static/3.png similarity index 100% rename from static/3.png rename to example/static/3.png diff --git a/static/bitcoin-extension.png b/example/static/bitcoin-extension.png similarity index 100% rename from static/bitcoin-extension.png rename to example/static/bitcoin-extension.png diff --git a/static/conversion-example.png b/example/static/conversion-example.png similarity index 100% rename from static/conversion-example.png rename to example/static/conversion-example.png diff --git a/static/conversion-example2.png b/example/static/conversion-example2.png similarity index 100% rename from static/conversion-example2.png rename to example/static/conversion-example2.png diff --git a/static/fastapi-example.png b/example/static/fastapi-example.png similarity index 100% rename from static/fastapi-example.png rename to example/static/fastapi-example.png diff --git a/static/fastapi-example2.png b/example/static/fastapi-example2.png similarity index 100% rename from static/fastapi-example2.png rename to example/static/fastapi-example2.png diff --git a/static/fastapi-framework.png b/example/static/fastapi-framework.png similarity index 100% rename from static/fastapi-framework.png rename to example/static/fastapi-framework.png diff --git a/static/fastapilogo.png b/example/static/fastapilogo.png similarity index 100% rename from static/fastapilogo.png rename to example/static/fastapilogo.png diff --git a/static/qrcode-example.png b/example/static/qrcode-example.png similarity index 100% rename from static/qrcode-example.png rename to example/static/qrcode-example.png diff --git a/static/qrcode-example1.png b/example/static/qrcode-example1.png similarity index 100% rename from static/qrcode-example1.png rename to example/static/qrcode-example1.png diff --git a/static/quasar-example.png b/example/static/quasar-example.png similarity index 100% rename from static/quasar-example.png rename to example/static/quasar-example.png diff --git a/static/quasar-framework.png b/example/static/quasar-framework.png similarity index 100% rename from static/quasar-framework.png rename to example/static/quasar-framework.png diff --git a/static/quasarlogo.png b/example/static/quasarlogo.png similarity index 100% rename from static/quasarlogo.png rename to example/static/quasarlogo.png diff --git a/static/script-example.png b/example/static/script-example.png similarity index 100% rename from static/script-example.png rename to example/static/script-example.png diff --git a/static/vif-example.png b/example/static/vif-example.png similarity index 100% rename from static/vif-example.png rename to example/static/vif-example.png diff --git a/static/vuejs-framework.png b/example/static/vuejs-framework.png similarity index 100% rename from static/vuejs-framework.png rename to example/static/vuejs-framework.png diff --git a/static/vuejslogo.png b/example/static/vuejslogo.png similarity index 100% rename from static/vuejslogo.png rename to example/static/vuejslogo.png diff --git a/static/websocket-example.png b/example/static/websocket-example.png similarity index 100% rename from static/websocket-example.png rename to example/static/websocket-example.png diff --git a/tasks.py b/example/tasks.py similarity index 100% rename from tasks.py rename to example/tasks.py diff --git a/templates/example/index.html b/example/templates/example/index.html similarity index 100% rename from templates/example/index.html rename to example/templates/example/index.html diff --git a/views.py b/example/views.py similarity index 100% rename from views.py rename to example/views.py diff --git a/views_api.py b/example/views_api.py similarity index 100% rename from views_api.py rename to example/views_api.py diff --git a/poetry.lock b/poetry.lock index 9d742f6..aa1e44b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -751,13 +751,13 @@ tests = ["dj-database-url", "dj-email-url", "django-cache-url", "pytest"] [[package]] name = "exceptiongroup" -version = "1.2.0" +version = "1.2.1" description = "Backport of PEP 654 (exception groups)" optional = false python-versions = ">=3.7" files = [ - {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, - {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, + {file = "exceptiongroup-1.2.1-py3-none-any.whl", hash = "sha256:5258b9ed329c5bbdd31a309f53cbfb0b155341807f6ff7606a1e801a891b29ad"}, + {file = "exceptiongroup-1.2.1.tar.gz", hash = "sha256:a4785e48b045528f5bfe627b6ad554ff32def154f42372786903b7abcfe1aa16"}, ] [package.extras] @@ -942,13 +942,13 @@ socks = ["socksio (==1.*)"] [[package]] name = "identify" -version = "2.5.35" +version = "2.5.36" description = "File identification library for Python" optional = false python-versions = ">=3.8" files = [ - {file = "identify-2.5.35-py2.py3-none-any.whl", hash = "sha256:c4de0081837b211594f8e877a6b4fad7ca32bbfc1a9307fdd61c28bfe923f13e"}, - {file = "identify-2.5.35.tar.gz", hash = "sha256:10a7ca245cfcd756a554a7288159f72ff105ad233c7c4b9c6f0f4d108f5f6791"}, + {file = "identify-2.5.36-py2.py3-none-any.whl", hash = "sha256:37d93f380f4de590500d9dba7db359d0d3da95ffe7f9de1753faa159e71e7dfa"}, + {file = "identify-2.5.36.tar.gz", hash = "sha256:e5e00f54165f9047fbebeb4a560f9acfb8af4c88232be60a488e9b68d122745d"}, ] [package.extras] @@ -996,13 +996,13 @@ files = [ [[package]] name = "itsdangerous" -version = "2.1.2" +version = "2.2.0" description = "Safely pass data to untrusted environments and back." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "itsdangerous-2.1.2-py3-none-any.whl", hash = "sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44"}, - {file = "itsdangerous-2.1.2.tar.gz", hash = "sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a"}, + {file = "itsdangerous-2.2.0-py3-none-any.whl", hash = "sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef"}, + {file = "itsdangerous-2.2.0.tar.gz", hash = "sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173"}, ] [[package]] @@ -1024,13 +1024,13 @@ i18n = ["Babel (>=2.7)"] [[package]] name = "limits" -version = "3.10.1" +version = "3.11.0" description = "Rate limiting utilities" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "limits-3.10.1-py3-none-any.whl", hash = "sha256:446242f5a6f7b8c7744e286a70793264ed81bca97860f94b821347284d14fbe9"}, - {file = "limits-3.10.1.tar.gz", hash = "sha256:1ee31d169d498da267a1b72183ae5940afc64b17b4ed4dfd977f6ea5607c2cfb"}, + {file = "limits-3.11.0-py3-none-any.whl", hash = "sha256:a19b31b28f692beb6c00de1ea61057dbb31929663e0c9f18d1dbb2f729a5ff6b"}, + {file = "limits-3.11.0.tar.gz", hash = "sha256:2ce80fbf245ea737ade6fe1197c9bbdfc49a6e558f1950e5f722734cb275d781"}, ] [package.dependencies] @@ -1384,13 +1384,13 @@ test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4.3)", "pytest- [[package]] name = "pluggy" -version = "1.4.0" +version = "1.5.0" description = "plugin and hook calling mechanisms for python" optional = false python-versions = ">=3.8" files = [ - {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, - {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, ] [package.extras] @@ -1745,6 +1745,20 @@ pytest = ">=7.0.0" 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 = "pytest-md" +version = "0.2.0" +description = "Plugin for generating Markdown reports for pytest results" +optional = false +python-versions = ">=3.6" +files = [ + {file = "pytest-md-0.2.0.tar.gz", hash = "sha256:3b248d5b360ea5198e05b4f49c7442234812809a63137ec6cdd3643a40cf0112"}, + {file = "pytest_md-0.2.0-py3-none-any.whl", hash = "sha256:4c4cd16fea6d1485e87ee254558712c804a96d2aa9674b780e7eb8fb6526e1d1"}, +] + +[package.dependencies] +pytest = ">=4.2.1" + [[package]] name = "python-crontab" version = "3.0.0" @@ -2267,13 +2281,13 @@ test = ["Cython (>=0.29.32,<0.30.0)", "aiohttp", "flake8 (>=3.9.2,<3.10.0)", "my [[package]] name = "virtualenv" -version = "20.25.1" +version = "20.25.3" description = "Virtual Python Environment builder" optional = false python-versions = ">=3.7" files = [ - {file = "virtualenv-20.25.1-py3-none-any.whl", hash = "sha256:961c026ac520bac5f69acb8ea063e8a4f071bcc9457b9c1f28f6b085c511583a"}, - {file = "virtualenv-20.25.1.tar.gz", hash = "sha256:e08e13ecdca7a0bd53798f356d5831434afa5b07b93f0abdf0797b7a06ffe197"}, + {file = "virtualenv-20.25.3-py3-none-any.whl", hash = "sha256:8aac4332f2ea6ef519c648d0bc48a5b1d324994753519919bddbb1aff25a104e"}, + {file = "virtualenv-20.25.3.tar.gz", hash = "sha256:7bb554bbdfeaacc3349fa614ea5bff6ac300fc7c335e9facf3a3bcfc703f45be"}, ] [package.dependencies] @@ -2282,7 +2296,7 @@ filelock = ">=3.12.2,<4" platformdirs = ">=3.9.1,<5" [package.extras] -docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2,!=7.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] [[package]] @@ -2491,4 +2505,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.10 | ^3.9" -content-hash = "3094709ec77c4cbb4260ff3787ec4b71229d028f97492ec918b59ac78e5e2a4d" +content-hash = "e529fd08a83eea5abf3479ccae38b03155d4eb8fb5b2c6a0372d3758cc5d2b43" diff --git a/pyproject.toml b/pyproject.toml index 2d002ea..c2f4a10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "lnbits-example" +name = "example" version = "0.0.0" description = "LNbits, free and open-source Lightning wallet and accounts system." authors = ["Alan Bits "] @@ -15,6 +15,7 @@ pytest = "^7.3.2" mypy = "^1.5.1" pre-commit = "^3.2.2" ruff = "^0.3.2" +pytest-md = "^0.2.0" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/tests/test_init.py b/tests/test_init.py new file mode 100644 index 0000000..56a142a --- /dev/null +++ b/tests/test_init.py @@ -0,0 +1,18 @@ +import pytest +from fastapi import APIRouter + +from example import example_ext, example_start, example_stop + + +# just import router and add it to a test router +@pytest.mark.asyncio +async def test_router(): + router = APIRouter() + router.include_router(example_ext) + assert 1 == 1 + + +@pytest.mark.asyncio +async def test_start_and_stop(): + example_start() + example_stop()