Skip to content

Commit

Permalink
add: some more automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saemideluxe committed Nov 27, 2021
1 parent 6c7da24 commit 6ec8890
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 54 deletions.
12 changes: 12 additions & 0 deletions bread/tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from bread.settings.required import * # noqa

INSTALLED_APPS = BREAD_DEPENDENCIES + ["django.contrib.admin"] # noqa
SECRET_KEY = "test" # nosec because this is only used to run tests
ROOT_URLCONF = "bread.tests.urls"
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
HAYSTACK_CONNECTIONS = {
"default": {
"ENGINE": "haystack.backends.simple_backend.SimpleEngine",
},
}
STATIC_URL = "static/"
41 changes: 41 additions & 0 deletions bread/tests/test_all_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# import random
# import uuid
import re
import string

from django.test import Client, TestCase
from django.urls import get_resolver, reverse
from django_extensions.management.commands import show_urls

ALPHANUMERIC_STR = "".join((string.ascii_letters, string.digits))


def get_real_url(view, urlname, urlpattern):
arguments = re.findall("<[^>]*>", urlpattern)
if not arguments:
return reverse(urlname)
return None


class TestAllURLs(TestCase):
# get a list of urlpatterns

def test_allurls(self):
tested = 0
allurls = show_urls.Command().extract_views_from_urlpatterns(
get_resolver(None).url_patterns
)
c = Client()
for (
view,
urlpattern,
urlname,
) in allurls:
url = get_real_url(view, urlname, urlpattern)
if url is None:
print(f"URL {urlname} with pattern {urlpattern} cannot be tested")
else:
c.get(url)
tested += 1
print(f"Tested URLS: {tested}")
print(f"Untested URLS: {len(allurls) - tested}")
56 changes: 2 additions & 54 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,11 @@
#!/usr/bin/env python

import os
import sys

import django
from django.conf import settings

INSTALLED_APPS = [
"django_extensions",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sites",
"guardian",
"bread",
"bread.contrib.reports",
"bread.contrib.workflows",
"django_celery_results",
]

settings.configure( # nosec because this is only for local development
DEBUG=True,
USE_TZ=True,
USE_I18N=True,
DATABASES={"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}},
MIDDLEWARE=(
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"bread.middleware.RequireAuthenticationMiddleware",
),
SITE_ID=1,
INSTALLED_APPS=INSTALLED_APPS,
AUTHENTICATION_BACKENDS=(
"django.contrib.auth.backends.ModelBackend",
"guardian.backends.ObjectPermissionBackend",
),
SECRET_KEY="SECRET_KEY_FOR_TESTING",
STATIC_URL="static/",
ROOT_URLCONF="bread.tests.urls",
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"dynamic_preferences.processors.global_preferences",
"bread.context_processors.bread_context",
]
},
}
],
)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bread.tests.settings")
django.setup()

if __name__ == "__main__":
Expand Down

0 comments on commit 6ec8890

Please sign in to comment.