Skip to content

Commit 581297d

Browse files
committed
Add test config for django-mongodb-extensions
1 parent 897d9f6 commit 581297d

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from django.contrib.admin.apps import AdminConfig
2+
from django.contrib.auth.apps import AuthConfig
3+
from django.contrib.contenttypes.apps import ContentTypesConfig
4+
5+
6+
class MongoAdminConfig(AdminConfig):
7+
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
8+
9+
10+
class MongoAuthConfig(AuthConfig):
11+
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
12+
13+
14+
class MongoContentTypesConfig(ContentTypesConfig):
15+
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
"""Django settings for tests."""
2+
3+
import os
4+
from django_mongodb_cli.utils import get_databases
5+
6+
7+
DATABASES = get_databases("debug_toolbar")
8+
9+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
10+
11+
12+
# Quick-start development settings - unsuitable for production
13+
14+
SECRET_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
15+
16+
INTERNAL_IPS = ["127.0.0.1"]
17+
18+
LOGGING = { # avoids spurious output in tests
19+
"version": 1,
20+
"disable_existing_loggers": True,
21+
}
22+
23+
24+
# Application definition
25+
26+
INSTALLED_APPS = [
27+
"debug_toolbar.mongo_apps.MongoAdminConfig",
28+
"debug_toolbar.mongo_apps.MongoAuthConfig",
29+
"debug_toolbar.mongo_apps.MongoContentTypesConfig",
30+
"django.contrib.sessions",
31+
"django.contrib.messages",
32+
"django.contrib.staticfiles",
33+
"debug_toolbar",
34+
"tests",
35+
"django_mongodb_extensions",
36+
]
37+
38+
39+
USE_GIS = os.getenv("DB_BACKEND") == "postgis"
40+
41+
if USE_GIS:
42+
INSTALLED_APPS = ["django.contrib.gis"] + INSTALLED_APPS
43+
44+
MEDIA_URL = "/media/" # Avoids https://code.djangoproject.com/ticket/21451
45+
46+
MIDDLEWARE = [
47+
"tests.middleware.UseCacheAfterToolbar",
48+
"debug_toolbar.middleware.DebugToolbarMiddleware",
49+
"django.middleware.security.SecurityMiddleware",
50+
"django.contrib.sessions.middleware.SessionMiddleware",
51+
"django.middleware.common.CommonMiddleware",
52+
"django.middleware.csrf.CsrfViewMiddleware",
53+
"django.contrib.auth.middleware.AuthenticationMiddleware",
54+
"django.contrib.messages.middleware.MessageMiddleware",
55+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
56+
]
57+
58+
ROOT_URLCONF = "tests.urls"
59+
60+
TEMPLATES = [
61+
{
62+
"NAME": "jinja2",
63+
"BACKEND": "django.template.backends.jinja2.Jinja2",
64+
"APP_DIRS": True,
65+
"DIRS": [os.path.join(BASE_DIR, "tests", "templates", "jinja2")],
66+
},
67+
{
68+
"BACKEND": "django.template.backends.django.DjangoTemplates",
69+
"APP_DIRS": True,
70+
"OPTIONS": {
71+
"context_processors": [
72+
"django.template.context_processors.debug",
73+
"django.template.context_processors.request",
74+
"django.contrib.auth.context_processors.auth",
75+
"django.contrib.messages.context_processors.messages",
76+
]
77+
},
78+
},
79+
]
80+
81+
USE_TZ = True
82+
83+
STATIC_ROOT = os.path.join(BASE_DIR, "tests", "static")
84+
85+
STATIC_URL = "/static/"
86+
87+
STATICFILES_DIRS = [
88+
os.path.join(BASE_DIR, "tests", "additional_static"),
89+
("prefix", os.path.join(BASE_DIR, "tests", "additional_static")),
90+
]
91+
92+
# Cache and database
93+
94+
CACHES = {
95+
"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"},
96+
"second": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"},
97+
}
98+
99+
# Debug Toolbar configuration
100+
101+
DEBUG_TOOLBAR_CONFIG = {
102+
# Django's test client sets wsgi.multiprocess to True inappropriately
103+
"RENDER_PANELS": False,
104+
# IS_RUNNING_TESTS must be False even though we're running tests because we're running the toolbar's own tests.
105+
"IS_RUNNING_TESTS": False,
106+
}
107+
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
108+
MIGRATION_MODULES = {
109+
"admin": None,
110+
"auth": None,
111+
"contenttypes": None,
112+
}
113+
114+
DEBUG_TOOLBAR_PANELS = [
115+
"django_mongodb_extensions.debug_toolbar.panels.mql.MQLPanel",
116+
]

django_mongodb_cli/config.py

+43
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,49 @@
179179
join("src", "django-debug-toolbar", "tests"),
180180
],
181181
},
182+
"django-mongodb-extensions": {
183+
"apps_file": {
184+
"source": join("config", "extensions", "debug_toolbar_apps.py"),
185+
"target": join(
186+
"src",
187+
"django-mongodb-extensions",
188+
"django_mongodb_extensions",
189+
"mongo_apps.py",
190+
),
191+
},
192+
"test_command": "pytest",
193+
"test_dir": join("src", "django-mongodb-extensions"),
194+
"clone_dir": join("src", "django-mongodb-extensions"),
195+
"settings": {
196+
"test": {
197+
"source": join("config", "extensions", "debug_toolbar_settings.py"),
198+
"target": join(
199+
"src",
200+
"django-mongodb-extensions",
201+
"django_mongodb_extensions",
202+
"mongo_settings.py",
203+
),
204+
},
205+
"migrations": {
206+
"source": join("config", "debug_toolbar", "debug_toolbar_settings.py"),
207+
"target": join(
208+
"src",
209+
"django-mongodb-extensions",
210+
"django_mongodb_extensions",
211+
"mongo_settings.py",
212+
),
213+
},
214+
"module": {
215+
"test": "django_mongodb_extensions.mongo_settings",
216+
"migrations": "django_mongodb_extensions.mongo_settings",
217+
},
218+
},
219+
"test_dirs": [
220+
join(
221+
"src", "django-mongodb-extensions", "django_mongodb_extensions", "tests"
222+
),
223+
],
224+
},
182225
"django-allauth": {
183226
"test_command": "pytest",
184227
"test_dir": join("src", "django-allauth"),

django_mongodb_cli/repo.py

+1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def test(
353353
if (
354354
repo_name == "django-debug-toolbar"
355355
or repo_name == "django-allauth"
356+
or repo_name == "django-mongodb-extensions"
356357
):
357358
os.environ["DJANGO_SETTINGS_MODULE"] = test_settings_map[
358359
repo_name

0 commit comments

Comments
 (0)