Skip to content

Commit

Permalink
Create a separate test settings file.
Browse files Browse the repository at this point in the history
- Updates manage.py to default to the test settings unless specified in the command or env.
- Disables whitenoises warning about static files directories not existing.
- Uses the md5 password hasher for tests to speed them up.
  • Loading branch information
tim-schilling committed Jan 13, 2024
1 parent 06fc941 commit a66b8de
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build:
env:
ENVIRONMENT: 'test'
DJANGO_SETTINGS_MODULE: 'indymeet.settings.production'
DJANGO_SETTINGS_MODULE: 'indymeet.settings.test'
HOST: "localhost"
USER: "djangonaut"
PASSWORD: "djangonaut"
Expand Down
16 changes: 16 additions & 0 deletions indymeet/settings/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations

from .production import *

# Get rid of whitenoise "No directory at" warning, as it's not helpful when running tests.
# Related:
# - https://github.com/evansd/whitenoise/issues/215
# - https://github.com/evansd/whitenoise/issues/191
# - https://github.com/evansd/whitenoise/commit/4204494d44213f7a51229de8bc224cf6d84c01eb
WHITENOISE_AUTOREFRESH = True

# Use MD5 hasher as it's much faster per:
# https://docs.djangoproject.com/en/5.0/topics/testing/overview/#password-hashing
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
7 changes: 6 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "indymeet.settings.dev")
# If we're running tests, default to the test settings file
default_settings = (
"indymeet.settings.test" if "test" in sys.argv else "indymeet.settings.dev"
)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", default_settings)

from django.core.management import execute_from_command_line

Expand Down
1 change: 1 addition & 0 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r requirements.txt
-r requirements-test.txt
pre-commit
django-tailwind[reload]
django-debug-toolbar

0 comments on commit a66b8de

Please sign in to comment.