-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve test coverage and use pytest
- Loading branch information
Showing
14 changed files
with
226 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import os | ||
import sys | ||
|
||
import django | ||
from django.conf import global_settings, settings | ||
from django.test.utils import get_runner | ||
|
||
from tests.settings import HELPER_SETTINGS | ||
|
||
|
||
CMS_APP = [ | ||
"cms", | ||
"menus", | ||
"easy_thumbnails", | ||
"treebeard", | ||
"sekizai", | ||
"djangocms_link", | ||
] | ||
CMS_APP_STYLE = [] | ||
CMS_PROCESSORS = [] | ||
CMS_MIDDLEWARE = [ | ||
"cms.middleware.user.CurrentUserMiddleware", | ||
"cms.middleware.page.CurrentPageMiddleware", | ||
"cms.middleware.toolbar.ToolbarMiddleware", | ||
"cms.middleware.language.LanguageCookieMiddleware", | ||
] | ||
|
||
INSTALLED_APPS = ( | ||
[ | ||
"django.contrib.contenttypes", | ||
"django.contrib.auth", | ||
"django.contrib.sessions", | ||
"django.contrib.sites", | ||
"django.contrib.staticfiles", | ||
] | ||
+ CMS_APP_STYLE | ||
+ ["django.contrib.admin", "django.contrib.messages"] | ||
+ CMS_APP | ||
) | ||
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}} | ||
TEMPLATE_LOADERS = [ | ||
"django.template.loaders.filesystem.Loader", | ||
"django.template.loaders.app_directories.Loader", | ||
] | ||
STATICFILES_FINDERS = [ | ||
"django.contrib.staticfiles.finders.FileSystemFinder", | ||
"django.contrib.staticfiles.finders.AppDirectoriesFinder", | ||
] | ||
TEMPLATE_CONTEXT_PROCESSORS = [ | ||
"django.template.context_processors.debug", | ||
"django.template.context_processors.request", | ||
"django.contrib.auth.context_processors.auth", | ||
"django.contrib.messages.context_processors.messages", | ||
] + CMS_PROCESSORS | ||
TEMPLATES = [ | ||
{ | ||
"BACKEND": "django.template.backends.django.DjangoTemplates", | ||
"DIRS": [ | ||
os.path.join(os.path.dirname(__file__), "templates"), | ||
# insert your TEMPLATE_DIRS here | ||
], | ||
"APP_DIRS": True, | ||
"OPTIONS": { | ||
"context_processors": TEMPLATE_CONTEXT_PROCESSORS, | ||
}, | ||
}, | ||
] | ||
MIDDLEWARE = [ | ||
"django.middleware.http.ConditionalGetMiddleware", | ||
"django.contrib.sessions.middleware.SessionMiddleware", | ||
"django.contrib.auth.middleware.AuthenticationMiddleware", | ||
"django.contrib.messages.middleware.MessageMiddleware", | ||
"django.middleware.csrf.CsrfViewMiddleware", | ||
"django.middleware.locale.LocaleMiddleware", | ||
"django.middleware.common.CommonMiddleware", | ||
] + CMS_MIDDLEWARE | ||
SITE_ID = 1 | ||
LANGUAGE_CODE = "en" | ||
LANGUAGES = (("en", "English"),) | ||
STATIC_URL = "/static/" | ||
MEDIA_URL = "/media/" | ||
DEBUG = True | ||
CMS_TEMPLATES = (("fullwidth.html", "Fullwidth"), ("page.html", "Normal page")) | ||
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",) | ||
MIGRATION_MODULES = {} | ||
URL_CONF = "tests.utils.urls" | ||
|
||
|
||
def pytest_configure(): | ||
INSTALLED_APPS.extend(HELPER_SETTINGS.pop("INSTALLED_APPS")) | ||
|
||
settings.configure( | ||
default_settings=global_settings, | ||
**{ | ||
**dict( | ||
INSTALLED_APPS=INSTALLED_APPS, | ||
TEMPLATES=TEMPLATES, | ||
DATABASES=DATABASES, | ||
SITE_ID=SITE_ID, | ||
LANGUAGES=LANGUAGES, | ||
CMS_CONFIRM_VERSION4=True, | ||
MIGRATION_MODULES=MIGRATION_MODULES, | ||
ROOT_URLCONF=URL_CONF, | ||
STATIC_URL=STATIC_URL, | ||
MEDIA_URL=MEDIA_URL, | ||
SECRET_KEY="Secret!", | ||
MIDDLEWARE=MIDDLEWARE, | ||
), | ||
**HELPER_SETTINGS, | ||
} | ||
) | ||
django.setup() | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest_configure() | ||
|
||
argv = ["tests"] if sys.argv is None else sys.argv | ||
tests = argv[1:] if len(argv) > 1 else ["tests"] | ||
TestRunner = get_runner(settings) | ||
test_runner = TestRunner() | ||
failures = test_runner.run_tests(tests) | ||
sys.exit(bool(failures)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ isort | |
flake8 | ||
pyflakes>=2.1 | ||
django-test-migrations | ||
pytest | ||
pytest-django |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends "base.html" %} | ||
{% load cms_tags %} | ||
|
||
{% block title %}{% page_attribute 'title' %}{% endblock title %} | ||
|
||
{% block content %} | ||
{% placeholder "content" %} | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends "base.html" %} | ||
{% load cms_tags %} | ||
|
||
{% block title %}{% page_attribute 'title' %}{% endblock title %} | ||
|
||
{% block content %} | ||
{% placeholder "content" %} | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.conf import settings | ||
from django.conf.urls.i18n import i18n_patterns | ||
from django.contrib import admin | ||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns | ||
from django.urls import include, path, re_path | ||
from django.views.i18n import JavaScriptCatalog | ||
from django.views.static import serve | ||
|
||
|
||
admin.autodiscover() | ||
|
||
urlpatterns = [ | ||
re_path(r"^media/(?P<path>.*)$", serve, {"document_root": settings.MEDIA_ROOT, "show_indexes": True}), # NOQA | ||
re_path(r"^jsi18n/(?P<packages>\S+?)/$", JavaScriptCatalog.as_view()), # NOQA | ||
] | ||
i18n_urls = [ | ||
re_path(r"^admin/", admin.site.urls), | ||
] | ||
|
||
i18n_urls.append(path("", include("cms.urls"))) # NOQA | ||
|
||
urlpatterns += i18n_patterns(*i18n_urls) | ||
urlpatterns += staticfiles_urlpatterns() |