Skip to content

Commit

Permalink
🧫 Pytest (#97)
Browse files Browse the repository at this point in the history
* Formats all files with black

* Fixes lint errors

* Fixes black errors

* Fixes errors for ruff v0.1.3

* Adds test dependencies

* Adds environment to CI tests

* Try: adding settings/test.py

* Try with 'NAME'

* Try with test for DJANGO_SETTINGS_MODULE

* Try setting env in conftest

* Try without conftest

* Try with envs as environment secrets

* Remove environment variable from CI workflow

* Try with host postgres

* Try with default HOST 127.0.0.1

* Update database settings with default test values

* Retry with all test settings in conftest
  • Loading branch information
mrharpo authored Nov 6, 2023
1 parent a3fc5f5 commit ab64591
Show file tree
Hide file tree
Showing 8 changed files with 1,106 additions and 31 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ on: [push, pull_request, workflow_dispatch]

jobs:
tests:
name: ⚗️ Application Tests
name: ⚗️ App Tests
uses: WGBH-MLA/.github/.github/workflows/pytest-with-postgres.yml@main
secrets: inherit
with:
pdm_args: -G test,ci
pdm_args: -G test
pytest_args: -n auto --nbmake -ra -s
pg_db: ov-test

pg_db: ov
lint:
name: 👕 Lint
uses: WGBH-MLA/.github/.github/workflows/lint.yml@main
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/test-coverage.yml

This file was deleted.

8 changes: 8 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from os import environ as env

env['DJANGO_SETTINGS_MODULE'] = 'ov_wag.settings.test'
env['OV_DB_HOST'] = 'localhost'
env['OV_DB_PORT'] = '5432'
env['OV_DB_NAME'] = 'ov'
env['OV_DB_USER'] = 'postgres'
env['OV_DB_PASSWORD'] = 'postgres'
2 changes: 1 addition & 1 deletion ov_wag/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

DATABASES = {
'default': {
'ENGINE': os.environ.get('OV_DB_ENGINE'),
'ENGINE': os.environ.get('OV_DB_ENGINE', 'django.db.backends.postgresql'),
'HOST': os.environ.get('OV_DB_HOST'),
'PORT': os.environ.get('OV_DB_PORT'),
'NAME': os.environ.get('OV_DB_NAME'),
Expand Down
18 changes: 18 additions & 0 deletions ov_wag/settings/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from contextlib import suppress

from ov_wag.settings.base import * # noqa F403

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-qsu^g!8&aye$7b@ucxwa6!**1y@&1uwzcf+rs0832)t-yp7zsp'

# SECURITY WARNING: define the correct hosts in production!
ALLOWED_HOSTS = ['*']

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


with suppress(ImportError):
from .local import * # noqa F403
6 changes: 6 additions & 0 deletions ov_wag/tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ def test_media_dir(self):
self.assertTrue(path.isdir(MEDIA_ROOT))

# Uncomment to show media directory in logs

def test_env(self):
"""Test if the environment variables are set"""
from os import environ as env

self.assertTrue(env.get('DJANGO_SETTINGS_MODULE') == 'ov_wag.settings.test')
1,064 changes: 1,062 additions & 2 deletions pdm.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ dev = [
'ruff~=0.1',
'pre-commit~=3.5',
]
test = [
"pytest>=7.4.3",
"pytest-django>=4.6.0",
"pytest-cov>=4.1.0",
"pytest-sugar>=0.9.7",
"pytest-xdist>=3.3.1",
"nbmake>=1.4.6",
]

0 comments on commit ab64591

Please sign in to comment.