Skip to content

Commit

Permalink
add simple project tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilioid committed Feb 13, 2024
1 parent d5461e3 commit b6d7fe7
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 37 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/checks.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: checks
name: test
on:
- push
- workflow_dispatch
Expand All @@ -18,3 +18,19 @@ jobs:
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
steps:
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: install system dependencies
run: pip install pipenv
- 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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ ENV VW_DATABASE_URL=sqlite:///app/data/db.sqlite
# add additional metadata
VOLUME /app/data
EXPOSE 80/tcp
ENV APP_MODE=prod
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pre-commit = "*"
isort = "*"
black = "*"
ipython = "*"
pytest = "*"
pytest-django = "*"

[requires]
python_version = "3"
100 changes: 67 additions & 33 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ line-length = 110

[tool.isort]
profile = "black"

[tool.pytest.ini_options]
pythonpath = "src"
testpaths = "src/vinywaji}/*/tests"
log_cli = true
log_cli_level = "info"
django_find_project = false
DJANGO_SETTINGS_MODULE = "vinywaji.settings"
Empty file.
6 changes: 6 additions & 0 deletions src/vinywaji/api/tests/test_django_setup.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/vinywaji/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@


urlpatterns = [
path("schema", SpectacularAPIView.as_view(), name="schema"),
path("schema", SpectacularAPIView.as_view(), name="openapi_schema"),
path(
"schema/swagger",
SpectacularSwaggerView.as_view(url_name="schema"),
SpectacularSwaggerView.as_view(url_name="openapi_schema"),
name="swagger-ui",
),
path(
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions src/vinywaji/core/tests/test_django_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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
7 changes: 6 additions & 1 deletion src/vinywaji/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

from environs import Env

# Access runtime settings via `MY_SETTING = env.str("MY_SETTING")` (or user other types e.g. `env.bool()`)
env = Env()
env.read_env(env.path("VW_ENV_FILE", default=".env"))
env.read_env(".env", override=True)
env.read_env(".env.local", override=True)
APP_MODE = env.str("APP_MODE", default="dev")
env.read_env(f".env.{APP_MODE}", override=True)
env.read_env(f".env.{APP_MODE}.local", override=True)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down

0 comments on commit b6d7fe7

Please sign in to comment.