From e9737d3907984817e3cb8f015f1faa69e7e11cba Mon Sep 17 00:00:00 2001 From: Anson <58594437+AnsonDev42@users.noreply.github.com> Date: Sat, 20 Apr 2024 13:42:35 +0100 Subject: [PATCH] Add trackers (#11) * fix: improve query TrackerAPI perf. by 140x * chore: exclude debug log * ci: pytest and fix tests * ci: test on ubuntu only * chore: rename pytest CI --- .github/workflows/pytest-ci.yml | 56 +++++++++++++++++++++++++++++++++ poetry.lock | 20 +++++++++++- pyproject.toml | 7 ++--- test/test_service.py | 2 +- 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/pytest-ci.yml diff --git a/.github/workflows/pytest-ci.yml b/.github/workflows/pytest-ci.yml new file mode 100644 index 0000000..0743a8b --- /dev/null +++ b/.github/workflows/pytest-ci.yml @@ -0,0 +1,56 @@ +on: + push: + branches: + - "**" + pull_request: + branches: + - "**" +name: Pytest CI +concurrency: + group: check-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + name: test with ${{ matrix.py }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: mydatabaseuser + POSTGRES_PASSWORD: mypassword + POSTGRES_DB: mydatabase + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + strategy: + matrix: + py: + - "3.12.2" + os: + - ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup python for test ${{ matrix.py }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.py }} + - name: Install poetry + run: | + python -m pip install poetry + poetry install + - name: Set environment variables + run: | + set -a + source .env.dev + set +a + env | grep -vE '^(_|PWD|HOME|GITHUB_)' >> $GITHUB_ENV + - name: Run tests + run: poetry run pytest -vv diff --git a/poetry.lock b/poetry.lock index 2fa3064..b868b01 100644 --- a/poetry.lock +++ b/poetry.lock @@ -896,6 +896,24 @@ pluggy = ">=1.4,<2.0" [package.extras] testing = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "pytest-asyncio" +version = "0.23.6" +description = "Pytest support for asyncio" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-asyncio-0.23.6.tar.gz", hash = "sha256:ffe523a89c1c222598c76856e76852b787504ddb72dd5d9b6617ffa8aa2cde5f"}, + {file = "pytest_asyncio-0.23.6-py3-none-any.whl", hash = "sha256:68516fdd1018ac57b846c9846b954f0393b26f094764a28c955eabb0536a4e8a"}, +] + +[package.dependencies] +pytest = ">=7.0.0,<9" + +[package.extras] +docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] +testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"] + [[package]] name = "pytest-django" version = "4.8.0" @@ -1177,4 +1195,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "9ed81928104ac32d7e2bb90618d56ee5d3414f7c56985d684b54e41188bdb93d" +content-hash = "4cc30511b4eb2985b28f5fbb66ae1f76c2cf41af8c5df9e738c3d3e081a5b4cf" diff --git a/pyproject.toml b/pyproject.toml index 82fda7b..f232db6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ readme = "README.md" python = "^3.12" django = "^5.0.2" psycopg = "^3.1.18" -httpx = {extras = ["http2"], version = "^0.27.0"} +httpx = { extras = ["http2"], version = "^0.27.0" } pydantic = "^2.6.2" celery = "^5.3.6" djangorestframework = "^3.14.0" @@ -23,12 +23,11 @@ python-dotenv = "^1.0.1" dj-rest-auth = "^5.0.2" pytest = "^8.0.2" pytest-django = "^4.8.0" +pytest-asyncio = "^0.23.6" -[build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] DJANGO_SETTINGS_MODULE = "uptimemonitor.settings" +asyncio_mode = "auto" diff --git a/test/test_service.py b/test/test_service.py index 36e28af..6c74027 100644 --- a/test/test_service.py +++ b/test/test_service.py @@ -70,7 +70,7 @@ def test_create_service_with_periodic_task_data(periodic_task_data): assert serializer.is_valid(), serializer.errors service = serializer.save() assert service.periodic_task is not None - assert service.periodic_task.name == "Test Task" + assert data["name"] in service.periodic_task.name assert ( service.periodic_task.interval.every == 10 ), service.periodic_task.interval.every