feat: implement blog project with CI pipeline
This commit is contained in:
52
tests/unit/test_config.py
Normal file
52
tests/unit/test_config.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.core.config import Settings
|
||||
|
||||
|
||||
class TestSettings:
|
||||
def test_default_values(self) -> None:
|
||||
settings = Settings()
|
||||
assert settings.app_name == "Blog API"
|
||||
assert settings.debug is False
|
||||
assert settings.host == "0.0.0.0"
|
||||
assert settings.port == 8000
|
||||
assert settings.database_url is None
|
||||
|
||||
def test_custom_values(self) -> None:
|
||||
settings = Settings(
|
||||
app_name="Test API",
|
||||
debug=True,
|
||||
host="localhost",
|
||||
port=9000,
|
||||
database_url="postgresql://test",
|
||||
)
|
||||
assert settings.app_name == "Test API"
|
||||
assert settings.debug is True
|
||||
assert settings.host == "localhost"
|
||||
assert settings.port == 9000
|
||||
assert settings.database_url == "postgresql://test"
|
||||
|
||||
def test_settings_from_env(self) -> None:
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
"APP_NAME": "Env API",
|
||||
"DEBUG": "true",
|
||||
"HOST": "127.0.0.1",
|
||||
"PORT": "8080",
|
||||
"DATABASE_URL": "sqlite:///test.db",
|
||||
},
|
||||
):
|
||||
settings = Settings()
|
||||
assert settings.app_name == "Env API"
|
||||
assert settings.debug is True
|
||||
assert settings.host == "127.0.0.1"
|
||||
assert settings.port == 8080
|
||||
assert settings.database_url == "sqlite:///test.db"
|
||||
|
||||
def test_global_settings_instance(self) -> None:
|
||||
from app.core.config import settings
|
||||
|
||||
assert isinstance(settings, Settings)
|
||||
assert settings.app_name == "Blog API"
|
||||
Reference in New Issue
Block a user