|
3 | 3 | import pytest
|
4 | 4 | from pydantic import ValidationError
|
5 | 5 |
|
6 |
| -from tipg.settings import PostgresSettings |
| 6 | +from tipg.settings import DatabaseSettings, PostgresSettings |
7 | 7 |
|
8 | 8 |
|
9 | 9 | def test_pg_settings(monkeypatch):
|
@@ -48,3 +48,31 @@ def test_pg_settings(monkeypatch):
|
48 | 48 | )
|
49 | 49 | assert str(settings.database_url) == "postgresql://user:secret@0.0.0.0:8888/db"
|
50 | 50 | assert not settings.postgres_port
|
| 51 | + |
| 52 | + |
| 53 | +def test_db_settings(monkeypatch): |
| 54 | + """test DatabaseSettings class.""" |
| 55 | + monkeypatch.delenv("TIPG_DB_SCHEMAS", raising=False) |
| 56 | + monkeypatch.delenv("TIPG_DB_APPLICATION_SCHEMA", raising=False) |
| 57 | + |
| 58 | + settings = DatabaseSettings(_env_file=None) |
| 59 | + assert settings.schemas == ["public"] |
| 60 | + assert settings.tipg_schema == "pg_temp" |
| 61 | + |
| 62 | + settings = DatabaseSettings( |
| 63 | + schemas=["private"], |
| 64 | + application_schema="pg_tipg_temp", |
| 65 | + _env_file=None, |
| 66 | + ) |
| 67 | + assert settings.schemas == ["private"] |
| 68 | + assert settings.tipg_schema == "pg_tipg_temp" |
| 69 | + |
| 70 | + |
| 71 | +def test_db_settings_env(monkeypatch): |
| 72 | + """test DatabaseSettings class with env variable.""" |
| 73 | + monkeypatch.setenv("TIPG_DB_SCHEMAS", '["private"]') |
| 74 | + monkeypatch.setenv("TIPG_DB_APPLICATION_SCHEMA", "pg_tipg_temp") |
| 75 | + |
| 76 | + settings = DatabaseSettings(_env_file=None) |
| 77 | + assert settings.schemas == ["private"] |
| 78 | + assert settings.tipg_schema == "pg_tipg_temp" |
0 commit comments