Update Dockerfile and settings for user permissions, add test URL patterns, and adjust volume paths
This commit is contained in:
parent
ea4cd498d0
commit
b08143980c
5 changed files with 219 additions and 4 deletions
50
config/tests/test_urls.py
Normal file
50
config/tests/test_urls.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterable
|
||||
from types import ModuleType
|
||||
|
||||
|
||||
def _pattern_strings(module: ModuleType) -> Iterable[str]:
|
||||
"""Return string representations of the URL patterns' route/regex."""
|
||||
return (str(p.pattern) for p in module.urlpatterns)
|
||||
|
||||
|
||||
def _reload_urls_with(**overrides) -> ModuleType:
|
||||
"""Reload `config.urls` while temporarily overriding Django settings.
|
||||
|
||||
Returns:
|
||||
ModuleType: The `config.urls` module as imported under the
|
||||
overridden settings. The real `config.urls` module is reloaded
|
||||
back to the test-default settings before this function returns.
|
||||
"""
|
||||
# Import under overridden settings
|
||||
with override_settings(**overrides):
|
||||
mod = importlib.reload(importlib.import_module("config.urls"))
|
||||
|
||||
# Restore to the normal test settings to avoid leaking changes to other tests
|
||||
importlib.reload(importlib.import_module("config.urls"))
|
||||
return mod
|
||||
|
||||
|
||||
def test_top_level_named_routes_available() -> None:
|
||||
"""Top-level routes defined in `config.urls` are reversible."""
|
||||
assert reverse("sitemap") == "/sitemap.xml"
|
||||
assert reverse("robots") == "/robots.txt"
|
||||
# ensure the included `twitch` namespace is present
|
||||
assert reverse("twitch:dashboard") == "/"
|
||||
|
||||
|
||||
def test_debug_tools_not_present_while_testing() -> None:
|
||||
"""`silk` and Django Debug Toolbar URL patterns are not present while running tests."""
|
||||
# Default test environment should *not* expose debug routes.
|
||||
mod = _reload_urls_with(TESTING=True)
|
||||
patterns = list(_pattern_strings(mod))
|
||||
assert not any("silk" in p for p in patterns)
|
||||
assert not any("__debug__" in p or "debug" in p for p in patterns)
|
||||
Loading…
Add table
Add a link
Reference in a new issue