|
11 | 11 | AUTH_MOD_NOOP, |
12 | 12 | AUTH_MOD_K8S, |
13 | 13 | AUTH_MOD_JWK_TOKEN, |
| 14 | + POSTGRES_DEFAULT_SSL_MODE, |
| 15 | + POSTGRES_DEFAULT_GSS_ENCMODE, |
14 | 16 | ) |
15 | 17 |
|
16 | 18 | from models.config import ( |
|
24 | 26 | CORSConfiguration, |
25 | 27 | ModelContextProtocolServer, |
26 | 28 | InferenceConfiguration, |
| 29 | + PostgreSQLDatabaseConfiguration, |
27 | 30 | ) |
28 | 31 |
|
29 | 32 | from utils.checks import InvalidConfigurationError |
@@ -867,3 +870,63 @@ def test_authentication_configuration_module_unsupported() -> None: |
867 | 870 | k8s_ca_cert_path=None, |
868 | 871 | k8s_cluster_api=None, |
869 | 872 | ) |
| 873 | + |
| 874 | + |
| 875 | +def test_postgresql_database_configuration() -> None: |
| 876 | + """Test the PostgreSQLDatabaseConfiguration model.""" |
| 877 | + c = PostgreSQLDatabaseConfiguration(db="db", user="user", password="password") |
| 878 | + assert c is not None |
| 879 | + assert c.host == "localhost" |
| 880 | + assert c.port == 5432 |
| 881 | + assert c.db == "db" |
| 882 | + assert c.user == "user" |
| 883 | + assert c.password == "password" |
| 884 | + assert c.ssl_mode == POSTGRES_DEFAULT_SSL_MODE |
| 885 | + assert c.gss_encmode == POSTGRES_DEFAULT_GSS_ENCMODE |
| 886 | + assert c.namespace == "lightspeed-stack" |
| 887 | + assert c.ca_cert_path is None |
| 888 | + |
| 889 | + |
| 890 | +def test_postgresql_database_configuration_port_setting(subtests) -> None: |
| 891 | + """Test the PostgreSQLDatabaseConfiguration model.""" |
| 892 | + with subtests.test(msg="Correct port value"): |
| 893 | + c = PostgreSQLDatabaseConfiguration( |
| 894 | + db="db", user="user", password="password", port=1234 |
| 895 | + ) |
| 896 | + assert c is not None |
| 897 | + assert c.port == 1234 |
| 898 | + |
| 899 | + with subtests.test(msg="Negative port value"): |
| 900 | + with pytest.raises(ValidationError, match="Input should be greater than 0"): |
| 901 | + PostgreSQLDatabaseConfiguration( |
| 902 | + db="db", user="user", password="password", port=-1 |
| 903 | + ) |
| 904 | + |
| 905 | + with subtests.test(msg="Too big port value"): |
| 906 | + with pytest.raises(ValueError, match="Port value should be less than 65536"): |
| 907 | + PostgreSQLDatabaseConfiguration( |
| 908 | + db="db", user="user", password="password", port=100000 |
| 909 | + ) |
| 910 | + |
| 911 | + |
| 912 | +def test_postgresql_database_configuration_ca_cert_path(subtests) -> None: |
| 913 | + """Test the PostgreSQLDatabaseConfiguration model.""" |
| 914 | + with subtests.test(msg="Path exists"): |
| 915 | + c = PostgreSQLDatabaseConfiguration( |
| 916 | + db="db", |
| 917 | + user="user", |
| 918 | + password="password", |
| 919 | + port=1234, |
| 920 | + ca_cert_path=Path("tests/configuration/server.crt"), |
| 921 | + ) |
| 922 | + assert c.ca_cert_path == Path("tests/configuration/server.crt") |
| 923 | + |
| 924 | + with subtests.test(msg="Path does not exist"): |
| 925 | + with pytest.raises(ValidationError, match="Path does not point to a file"): |
| 926 | + PostgreSQLDatabaseConfiguration( |
| 927 | + db="db", |
| 928 | + user="user", |
| 929 | + password="password", |
| 930 | + port=1234, |
| 931 | + ca_cert_path=Path("not a file"), |
| 932 | + ) |
0 commit comments