Skip to content

Commit 28d4257

Browse files
authored
Update test apps according to Django 4.2 template (#50)
1 parent 1b948b4 commit 28d4257

File tree

4 files changed

+158
-26
lines changed

4 files changed

+158
-26
lines changed

tests/manage.py

100644100755
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
14
from __future__ import annotations
25

36
import os
47
import sys
58

6-
from django.core.management import execute_from_command_line
7-
8-
PROJECT_ROOT = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
9-
sys.path.insert(0, PROJECT_ROOT)
10-
11-
if __name__ == "__main__":
12-
if len(sys.argv) == 1:
13-
sys.argv += ["test"]
149

10+
def main():
11+
"""Run administrative tasks."""
1512
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
13+
try:
14+
from django.core.management import execute_from_command_line
15+
except ImportError as exc:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
) from exc
1621
execute_from_command_line(sys.argv)
22+
23+
24+
if __name__ == "__main__":
25+
main()

tests/settings.py

Lines changed: 116 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,137 @@
1+
"""
2+
Django settings for tests project.
3+
4+
Generated by 'django-admin startproject' using Django 4.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.2/ref/settings/
11+
"""
12+
113
from __future__ import annotations
214

3-
USE_TZ = True
15+
from pathlib import Path
16+
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
19+
20+
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
25+
SECRET_KEY = "nokey" # noqa: S105
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
# Application definition
433

534
PROJECT_APPS = (
635
"django_fsm",
736
"tests.testapp",
837
)
938

10-
INSTALLED_APPS = (
11-
"django.contrib.contenttypes",
39+
INSTALLED_APPS = [
40+
"django.contrib.admin",
1241
"django.contrib.auth",
42+
"django.contrib.contenttypes",
43+
"django.contrib.sessions",
44+
"django.contrib.messages",
45+
"django.contrib.staticfiles",
1346
"guardian",
1447
*PROJECT_APPS,
15-
)
48+
]
1649

17-
AUTHENTICATION_BACKENDS = (
18-
"django.contrib.auth.backends.ModelBackend", # this is default
19-
"guardian.backends.ObjectPermissionBackend",
20-
)
50+
MIDDLEWARE = [
51+
"django.middleware.security.SecurityMiddleware",
52+
"django.contrib.sessions.middleware.SessionMiddleware",
53+
"django.middleware.common.CommonMiddleware",
54+
"django.middleware.csrf.CsrfViewMiddleware",
55+
"django.contrib.auth.middleware.AuthenticationMiddleware",
56+
"django.contrib.messages.middleware.MessageMiddleware",
57+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
58+
]
59+
60+
ROOT_URLCONF = "tests.urls"
61+
62+
TEMPLATES = [
63+
{
64+
"BACKEND": "django.template.backends.django.DjangoTemplates",
65+
"DIRS": [],
66+
"APP_DIRS": True,
67+
"OPTIONS": {
68+
"context_processors": [
69+
"django.template.context_processors.request",
70+
"django.contrib.auth.context_processors.auth",
71+
"django.contrib.messages.context_processors.messages",
72+
],
73+
},
74+
},
75+
]
76+
77+
WSGI_APPLICATION = "tests.wsgi.application"
78+
79+
80+
# Database
81+
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
2182

22-
DATABASE_ENGINE = "sqlite3"
23-
SECRET_KEY = "nokey" # noqa: S105
24-
MIDDLEWARE_CLASSES = ()
2583
DATABASES = {
2684
"default": {
2785
"ENGINE": "django.db.backends.sqlite3",
86+
"NAME": BASE_DIR / "db.sqlite3",
2887
}
2988
}
3089

31-
MIGRATION_MODULES = {
32-
"auth": None,
33-
"contenttypes": None,
34-
"guardian": None,
35-
}
90+
# Authentication
91+
# https://docs.djangoproject.com/en/4.2/topics/auth/
92+
93+
AUTHENTICATION_BACKENDS = (
94+
"django.contrib.auth.backends.ModelBackend", # this is default
95+
"guardian.backends.ObjectPermissionBackend",
96+
)
97+
98+
# Password validation
99+
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
100+
101+
AUTH_PASSWORD_VALIDATORS = [
102+
{
103+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
104+
},
105+
{
106+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
107+
},
108+
{
109+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
110+
},
111+
{
112+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
113+
},
114+
]
115+
116+
117+
# Internationalization
118+
# https://docs.djangoproject.com/en/4.2/topics/i18n/
119+
120+
LANGUAGE_CODE = "en-us"
121+
122+
TIME_ZONE = "UTC"
123+
124+
USE_I18N = True
125+
126+
USE_TZ = True
127+
128+
129+
# Static files (CSS, JavaScript, Images)
130+
# https://docs.djangoproject.com/en/4.2/howto/static-files/
131+
132+
STATIC_URL = "static/"
36133

37-
ANONYMOUS_USER_ID = 0
134+
# Default primary key field type
135+
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
38136

39-
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
137+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

tests/urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
from django.contrib import admin
4+
from django.urls import path
5+
6+
urlpatterns = [
7+
path("admin/", admin.site.urls, name="admin"),
8+
]

tests/wsgi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""WSGI config for silvr project.
2+
3+
It exposes the WSGI callable as a module-level variable named ``application``.
4+
5+
For more information on this file, see
6+
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
7+
"""
8+
9+
from __future__ import annotations
10+
11+
import os
12+
13+
from django.core.wsgi import get_wsgi_application
14+
15+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "silvr.settings")
16+
17+
application = get_wsgi_application()

0 commit comments

Comments
 (0)