-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c7da24
commit 6ec8890
Showing
3 changed files
with
55 additions
and
54 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
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/" |
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,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}") |
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