Files
santeh-ray/home/tests_settings.py
Azimkin bba8fdf2a2
All checks were successful
Build and Push Docker Image / build (push) Successful in 26s
fix: normalize coolify host env
2026-04-21 12:26:14 +02:00

29 lines
1.2 KiB
Python

import os
from unittest.mock import patch
from django.test import SimpleTestCase
from santehray.settings import collect_hosts, collect_origins, 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")