Files
santeh-ray/home/tests_settings.py
Azimkin 3d356c7d6a
All checks were successful
Build and Push Docker Image / build (push) Successful in 41s
feat: add price filter and dynamic slider to catalog
- Implemented JavaScript-based price slider for catalog filtering
- Updated catalog views to handle min/max price inputs and compute slider bounds
- Enhanced templates (`index.html`, `side-bar.html`) with filtering form and updated URLs
- Added CSS for price slider styling and form layout
- Introduced utility functions for URL building and price parsing
- Expanded tests for price filtering, sliders, and sidebar active states
- Updated context processor and header for dynamic navigation with price filters
2026-05-16 11:12:24 +02:00

57 lines
2.1 KiB
Python

import os
from unittest.mock import patch
from django.test import SimpleTestCase
from santehray.settings import (
collect_hosts,
collect_origins,
env_choice,
normalize_host,
normalize_origin,
)
class SettingsNormalizationTests(SimpleTestCase):
def test_normalize_host_strips_scheme_and_port(self):
self.assertEqual(normalize_host("https://preview-1.azimkin.dev:8000"), "preview-1.azimkin.dev")
def test_collect_hosts_normalizes_urls_and_bare_hosts(self):
with patch.dict(os.environ, {"ALLOWED_HOSTS": "https://preview-1.azimkin.dev:8000, localhost"}):
self.assertEqual(
collect_hosts("ALLOWED_HOSTS"),
["preview-1.azimkin.dev", "localhost"],
)
def test_collect_origins_normalizes_bare_hosts_and_urls(self):
with patch.dict(os.environ, {"CSRF_TRUSTED_ORIGINS": "preview-1.azimkin.dev,https://localhost:8443"}):
self.assertEqual(
collect_origins("CSRF_TRUSTED_ORIGINS"),
["https://preview-1.azimkin.dev", "https://localhost:8443"],
)
def test_normalize_origin_preserves_explicit_scheme_and_port(self):
self.assertEqual(normalize_origin("https://preview-1.azimkin.dev:8443"), "https://preview-1.azimkin.dev:8443")
def test_env_choice_accepts_allowed_value(self):
with patch.dict(os.environ, {"SECURE_REFERRER_POLICY": "strict-origin-when-cross-origin"}):
self.assertEqual(
env_choice(
"SECURE_REFERRER_POLICY",
"same-origin",
{"same-origin", "strict-origin-when-cross-origin"},
),
"strict-origin-when-cross-origin",
)
def test_env_choice_falls_back_for_invalid_value(self):
with patch.dict(os.environ, {"SECURE_REFERRER_POLICY": "invalid-policy"}):
self.assertEqual(
env_choice(
"SECURE_REFERRER_POLICY",
"same-origin",
{"same-origin", "strict-origin-when-cross-origin"},
),
"same-origin",
)