diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09ed138..828ea3a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,6 @@ name: test on: + workflow_dispatch: push: branches: [ "*" ] @@ -31,9 +32,18 @@ jobs: !/tmp/github_test_project/**/node_modules retention-days: 1 - run-test-project: + test-test-project: runs-on: ubuntu-latest needs: [ create-test-project ] + services: + db: + image: docker.io/postgres + ports: + - 5432:5432 + env: + POSTGRES_USER: github_test_project + POSTGRES_PASSWORD: github_test_project + POSTGRES_DB: github_test_project steps: - name: install system dependencies run: | @@ -43,10 +53,11 @@ jobs: - uses: actions/download-artifact@v4 with: name: ${{ env.artifact_name }} - - run: ls src/ - name: install project dependencies run: pipenv sync --dev - name: manage.py --help run: | chmod +x ./src/manage.py pipenv run ./src/manage.py --help + - name: pytest + run: pipenv run pytest diff --git a/{{ cookiecutter.project_slug }}/.github/workflows/test.yml b/{{ cookiecutter.project_slug }}/.github/workflows/test.yml new file mode 100644 index 0000000..ca4716c --- /dev/null +++ b/{{ cookiecutter.project_slug }}/.github/workflows/test.yml @@ -0,0 +1,48 @@ +name: test +on: + workflow_dispatch: + push: + branches: [ "*" ] + +jobs: + check-pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - uses: actions/setup-node@v3 + with: + node-version: 18 + - run: python -m pip install pre-commit + - uses: actions/cache@v3 + with: + path: ~/.cache/pre-commit + key: pre-commit|{{ "${{ env.pythonLocation }}" }}|${{ hashFiles('.pre-commit-config.yaml') }} + - run: pre-commit run --show-diff-on-failure --color=always --all-files + + test-backend: + runs-on: ubuntu-latest + services: + db: + image: docker.io/postgres + ports: + - 5432:5432 + env: + POSTGRES_USER: {{ cookiecutter.project_slug }} + POSTGRES_PASSWORD: {{ cookiecutter.project_slug }} + POSTGRES_DB: {{ cookiecutter.project_slug }} + steps: + - name: install system dependencies + run: | + pip install pipenv + sudo apt install npm + npm install -g pnpm + - uses: actions/checkout@v4 + - name: install project dependencies + run: pipenv sync --dev + - name: manage.py --help + run: pipenv run ./src/manage.py --help + - name: pytest + run: pipenv run pytest diff --git a/{{ cookiecutter.project_slug }}/Pipfile b/{{ cookiecutter.project_slug }}/Pipfile index 828ee66..67e6588 100644 --- a/{{ cookiecutter.project_slug }}/Pipfile +++ b/{{ cookiecutter.project_slug }}/Pipfile @@ -19,6 +19,8 @@ opentelemetry-exporter-prometheus = "*" # translation of telemet ipython = "*" black = "*" isort = "*" +pytest = "*" +pytest-django = "*" [requires] python_version = "3" diff --git a/{{ cookiecutter.project_slug }}/pyproject.toml b/{{ cookiecutter.project_slug }}/pyproject.toml index e13a6b1..d662b53 100644 --- a/{{ cookiecutter.project_slug }}/pyproject.toml +++ b/{{ cookiecutter.project_slug }}/pyproject.toml @@ -3,3 +3,12 @@ line-length = 110 [tool.isort] profile = "black" + +[tool.pytest.ini_options] +pythonpath = "src" +testpaths = "src/{{ cookiecutter.project_slug }}/*/tests" +log_cli = true +log_cli_level = "info" +django_find_project = false +norecursedirs = "dev_db *.egg .* dist node_modules" +DJANGO_SETTINGS_MODULE = "{{ cookiecutter.project_slug }}.settings" diff --git a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/api/tests/__init__.py b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/api/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/api/tests/test_django_setup.py b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/api/tests/test_django_setup.py new file mode 100644 index 0000000..33972ec --- /dev/null +++ b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/api/tests/test_django_setup.py @@ -0,0 +1,6 @@ +from django.shortcuts import resolve_url + + +def test_openapi_schema_loads(client): + response = client.get(resolve_url("openapi_schema")) + assert response.status_code == 200 diff --git a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/core/tests/__init__.py b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/core/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/core/tests/test_django_setup.py b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/core/tests/test_django_setup.py new file mode 100644 index 0000000..4e589e2 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/core/tests/test_django_setup.py @@ -0,0 +1,11 @@ +import pytest + + +def test_django_loads(): + from django.conf import settings + assert len(settings.INSTALLED_APPS) > 0 + + +@pytest.mark.django_db() +def test_db_connection(django_user_model): + assert django_user_model.objects.all().count() == 0