Skip to content

Commit adf1ba2

Browse files
committed
Add sample project but pytest fails
1 parent 7c90195 commit adf1ba2

File tree

22 files changed

+892
-0
lines changed

22 files changed

+892
-0
lines changed

tests/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,39 @@ def pytest_configure():
1313
}
1414
},
1515
INSTALLED_APPS=[
16+
"daphne",
1617
"django.contrib.auth",
1718
"django.contrib.contenttypes",
1819
"django.contrib.sessions",
1920
"django.contrib.admin",
21+
"django.contrib.staticfiles",
22+
"tests.sample_project.sampleapp",
2023
"channels",
2124
],
25+
STATIC_URL="static/",
26+
ASGI_APPLICATION="tests.sample_project.config.asgi.application",
27+
MIDDLEWARE=[
28+
"django.contrib.sessions.middleware.SessionMiddleware",
29+
"django.contrib.auth.middleware.AuthenticationMiddleware",
30+
],
31+
ROOT_URLCONF="tests.sample_project.config.urls",
32+
CHANNEL_LAYERS={
33+
"default": {
34+
"BACKEND": "channels.layers.InMemoryChannelLayer",
35+
},
36+
},
37+
TEMPLATES=[
38+
{
39+
"BACKEND": "django.template.backends.django.DjangoTemplates",
40+
"APP_DIRS": True,
41+
"OPTIONS": {
42+
"context_processors": [
43+
"django.template.context_processors.request",
44+
"django.contrib.auth.context_processors.auth",
45+
],
46+
},
47+
},
48+
],
2249
SECRET_KEY="Not_a_secret_key",
2350
)
2451

tests/sample_project/__init__.py

Whitespace-only changes.

tests/sample_project/config/__init__.py

Whitespace-only changes.

tests/sample_project/config/asgi.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
ASGI config for sample_project project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
8+
"""
9+
10+
from django.core.asgi import get_asgi_application
11+
from django.urls import path
12+
13+
from channels.auth import AuthMiddlewareStack
14+
from channels.routing import ProtocolTypeRouter, URLRouter
15+
from channels.security.websocket import AllowedHostsOriginValidator
16+
from tests.sample_project.sampleapp.consumers import LiveMessageConsumer
17+
18+
application = ProtocolTypeRouter(
19+
{
20+
"websocket": AllowedHostsOriginValidator(
21+
AuthMiddlewareStack(
22+
URLRouter(
23+
[
24+
path(
25+
"ws/message/",
26+
LiveMessageConsumer.as_asgi(),
27+
name="live_message_counter",
28+
),
29+
]
30+
)
31+
)
32+
),
33+
"http": get_asgi_application(),
34+
}
35+
)
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
"""
2+
Django settings for sample_project project.
3+
4+
Generated by 'django-admin startproject' using Django 5.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.2/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = "django-insecure-w%kkd-b39(9uvz68x!-9+xt=&9q&^j@#uc_&=g%-s@bcsz*qbu"
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
"daphne",
35+
"django.contrib.admin",
36+
"django.contrib.auth",
37+
"django.contrib.contenttypes",
38+
"django.contrib.sessions",
39+
"django.contrib.messages",
40+
"django.contrib.staticfiles",
41+
"sampleapp",
42+
"channels",
43+
]
44+
45+
MIDDLEWARE = [
46+
"django.middleware.security.SecurityMiddleware",
47+
"django.contrib.sessions.middleware.SessionMiddleware",
48+
"django.middleware.common.CommonMiddleware",
49+
"django.middleware.csrf.CsrfViewMiddleware",
50+
"django.contrib.auth.middleware.AuthenticationMiddleware",
51+
"django.contrib.messages.middleware.MessageMiddleware",
52+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
53+
]
54+
55+
ROOT_URLCONF = "config.urls"
56+
57+
TEMPLATES = [
58+
{
59+
"BACKEND": "django.template.backends.django.DjangoTemplates",
60+
"DIRS": [],
61+
"APP_DIRS": True,
62+
"OPTIONS": {
63+
"context_processors": [
64+
"django.template.context_processors.csrf",
65+
"django.template.context_processors.request",
66+
"django.contrib.auth.context_processors.auth",
67+
"django.contrib.messages.context_processors.messages",
68+
],
69+
},
70+
},
71+
]
72+
73+
WSGI_APPLICATION = "config.wsgi.application"
74+
ASGI_APPLICATION = "config.asgi.application"
75+
76+
CHANNEL_LAYERS = {
77+
"default": {
78+
"BACKEND": "channels.layers.InMemoryChannelLayer",
79+
},
80+
}
81+
82+
# Database
83+
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
84+
85+
DATABASES = {
86+
"default": {
87+
"ENGINE": "django.db.backends.sqlite3",
88+
"NAME": BASE_DIR / "sampleapp/sampleapp.sqlite3",
89+
"TEST": {
90+
"NAME": BASE_DIR / "sampleapp/test_sampleapp.sqlite3",
91+
},
92+
}
93+
}
94+
95+
96+
# Password validation
97+
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
98+
99+
AUTH_PASSWORD_VALIDATORS = [
100+
{
101+
"NAME": (
102+
"django.contrib.auth.password_validation."
103+
"UserAttributeSimilarityValidator"
104+
),
105+
},
106+
{
107+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
108+
},
109+
{
110+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
111+
},
112+
{
113+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
114+
},
115+
]
116+
117+
118+
# Internationalization
119+
# https://docs.djangoproject.com/en/5.2/topics/i18n/
120+
121+
LANGUAGE_CODE = "en-us"
122+
123+
TIME_ZONE = "UTC"
124+
125+
USE_I18N = True
126+
127+
USE_TZ = True
128+
129+
130+
# Static files (CSS, JavaScript, Images)
131+
# https://docs.djangoproject.com/en/5.2/howto/static-files/
132+
133+
STATIC_URL = "static/"
134+
135+
# Default primary key field type
136+
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
137+
138+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

tests/sample_project/config/urls.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
URL configuration for sample_project project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.2/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
18+
from django.conf import settings
19+
from django.contrib import admin
20+
from django.urls import path
21+
from django.views.generic import RedirectView
22+
23+
urlpatterns = [
24+
path("admin/", admin.site.urls),
25+
path(
26+
"favicon.ico",
27+
RedirectView.as_view(
28+
url=settings.STATIC_URL + "sampleapp/images/django.svg", permanent=True
29+
),
30+
),
31+
]

tests/sample_project/config/wsgi.py

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

tests/sample_project/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()

tests/sample_project/sampleapp/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.contrib import admin
2+
3+
from .models import Message
4+
5+
6+
@admin.register(Message)
7+
class MessageAdmin(admin.ModelAdmin):
8+
list_display = ("title", "created")
9+
change_list_template = "admin/sampleapp/message/change_list.html"

0 commit comments

Comments
 (0)