Initial release: async repository layer over SQLModel

This commit is contained in:
2026-08-13 22:25:59 +03:00
commit 3d85c2b5dd
26 changed files with 2252 additions and 0 deletions

47
tests/test_settings.py Normal file
View File

@@ -0,0 +1,47 @@
import pytest
from pydantic import ValidationError
from metaorm import DatabaseSettings
class TestDatabaseSettings:
def test_default_values(self) -> None:
settings = DatabaseSettings()
assert settings.dsn == "sqlite+aiosqlite:///db.sqlite3"
assert settings.pool_size == 5
assert settings.pool_recycle == 60
assert settings.pool_timeout == 60
def test_custom_values(self) -> None:
settings = DatabaseSettings(
dsn="postgresql+asyncpg://user:pass@localhost/db",
pool_size=10,
pool_recycle=120,
pool_timeout=30,
)
assert settings.dsn == "postgresql+asyncpg://user:pass@localhost/db"
assert settings.pool_size == 10
assert settings.pool_recycle == 120
assert settings.pool_timeout == 30
def test_dsn_must_match_pattern(self) -> None:
with pytest.raises(ValidationError):
DatabaseSettings(dsn="invalid_dsn")
@pytest.mark.parametrize(
"field_name,invalid_value",
[
("pool_size", 0),
("pool_recycle", 0),
("pool_timeout", 0),
],
)
def test_integer_fields_must_be_greater_or_equal_one(
self,
field_name: str,
invalid_value: int,
) -> None:
with pytest.raises(ValidationError):
DatabaseSettings(**{field_name: invalid_value})