33import warnings
44
55import pytest
6+ from pydantic import ValidationError
67
78from stac_fastapi .pgstac .config import PostgresSettings
89
@@ -21,12 +22,13 @@ async def test_pg_settings_with_env_postgres(monkeypatch):
2122 """Test PostgresSettings with POSTGRES_* environment variables"""
2223 monkeypatch .setenv ("POSTGRES_USER" , "username" )
2324 monkeypatch .setenv ("POSTGRES_PASS" , "password" )
24- monkeypatch .setenv ("POSTGRES_HOST" , "0.0.0.0" )
25+ monkeypatch .setenv ("POSTGRES_HOST_READER" , "0.0.0.0" )
26+ monkeypatch .setenv ("POSTGRES_HOST_WRITER" , "0.0.0.0" )
2527 monkeypatch .setenv ("POSTGRES_PORT" , "1111" )
2628 monkeypatch .setenv ("POSTGRES_DBNAME" , "pgstac" )
2729 with pytest .warns (DeprecationWarning ) as record :
2830 assert PostgresSettings (_env_file = None )
29- assert len (record ) == 5
31+ assert len (record ) == 6
3032
3133
3234async def test_pg_settings_attributes (monkeypatch ):
@@ -49,7 +51,7 @@ async def test_pg_settings_attributes(monkeypatch):
4951 settings = PostgresSettings (
5052 postgres_user = "user" ,
5153 postgres_pass = "password" ,
52- postgres_host = "0.0.0.0" ,
54+ postgres_host_reader = "0.0.0.0" ,
5355 postgres_port = 1111 ,
5456 postgres_dbname = "pgstac" ,
5557 _env_file = None ,
@@ -59,4 +61,16 @@ async def test_pg_settings_attributes(monkeypatch):
5961
6062 # Should raise warning when accessing deprecated attributes
6163 with pytest .warns (DeprecationWarning ):
62- assert settings .postgres_host == "0.0.0.0"
64+ assert settings .postgres_host_reader == "0.0.0.0"
65+
66+ with pytest .raises (ValidationError ):
67+ with pytest .warns (DeprecationWarning ) as record :
68+ PostgresSettings (
69+ postgres_user = "user" ,
70+ postgres_pass = "password" ,
71+ postgres_host_reader = "0.0.0.0" ,
72+ postgres_host_writer = "1.1.1.1" ,
73+ postgres_port = 1111 ,
74+ postgres_dbname = "pgstac" ,
75+ _env_file = None ,
76+ )
0 commit comments