57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
from config import Settings
|
|
|
|
|
|
class TestSettings:
|
|
"""Tests the Settings model."""
|
|
|
|
def test_default_cors_origins(self):
|
|
"""Test the default value."""
|
|
settings = Settings()
|
|
assert settings.cors_origins == ["http://localhost:5173"]
|
|
assert isinstance(settings.cors_origins, list)
|
|
|
|
def test_cors_origins_single_value(self, monkeypatch):
|
|
"""Test with only one origin in the env variable."""
|
|
monkeypatch.setenv("CORS_ORIGINS", "http://example.com")
|
|
settings = Settings()
|
|
assert settings.cors_origins == ["http://example.com"]
|
|
|
|
def test_cors_origins_multiple_values(self, monkeypatch):
|
|
"""Test with several origins comma separated."""
|
|
monkeypatch.setenv(
|
|
"CORS_ORIGINS", "http://a.com,http://b.com,http://c.com"
|
|
)
|
|
settings = Settings()
|
|
assert settings.cors_origins == [
|
|
"http://a.com", "http://b.com", "http://c.com"
|
|
]
|
|
|
|
def test_cors_origins_with_spaces(self, monkeypatch):
|
|
"""Test with origins with spaces around commas."""
|
|
monkeypatch.setenv(
|
|
"CORS_ORIGINS", "http://a.com , http://b.com , http://c.com"
|
|
)
|
|
settings = Settings()
|
|
assert settings.cors_origins == [
|
|
"http://a.com", "http://b.com", "http://c.com"
|
|
]
|
|
|
|
def test_cors_origins_empty_string(self, monkeypatch):
|
|
"""Test with an empty list."""
|
|
monkeypatch.setenv("CORS_ORIGINS", "")
|
|
settings = Settings()
|
|
assert settings.cors_origins == []
|
|
|
|
def test_cors_origins_with_trailing_comma(self, monkeypatch):
|
|
"""Test with a trailing comma."""
|
|
monkeypatch.setenv("CORS_ORIGINS", "http://a.com,http://b.com,")
|
|
settings = Settings()
|
|
assert settings.cors_origins == ["http://a.com", "http://b.com"]
|
|
|
|
def test_cors_origins_type_is_list(self):
|
|
"""Test that the returned type is a list"""
|
|
settings = Settings()
|
|
assert isinstance(settings.cors_origins, list)
|
|
assert all(isinstance(origin, str) for origin in settings.cors_origins)
|
|
|