Skip to content

Commit c598b19

Browse files
committed
Fix unit test errors
1 parent 00f02fc commit c598b19

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

sqlsynthgen/settings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ class Settings(BaseSettings):
4444
The destination database schema to use, if applicable.
4545
"""
4646

47-
# Connection parameters for the source database. See also
47+
src_schema: Optional[str]
48+
dst_schema: Optional[str]
49+
50+
# DSNs for the databases. For example:
51+
# postgresql://user:secret@localhost:6789/dbname
52+
# See also
4853
# https://www.postgresql.org/docs/11/libpq-connect.html#LIBPQ-PARAMKEYWORDS
4954
src_dsn: Optional[str]
5055
dst_dsn: Optional[str]
5156

52-
src_schema: Optional[str]
53-
dst_schema: Optional[str]
54-
5557
@validator("src_dsn")
5658
def validate_src_dsn(cls, dsn: Optional[str], values: Any) -> Optional[str]:
5759
"""Create and validate the source DB DSN."""

tests/test_functional.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ class FunctionalTestCase(RequiresDBTestCase):
3636
env = os.environ.copy()
3737
env = {
3838
**env,
39-
"src_host_name": "localhost",
40-
"src_user_name": "postgres",
41-
"src_password": "password",
42-
"src_db_name": "src",
43-
"dst_host_name": "localhost",
44-
"dst_user_name": "postgres",
45-
"dst_password": "password",
46-
"dst_db_name": "dst",
39+
"src_dsn": "postgresql://postgres:password@localhost/src",
40+
"dst_dsn": "postgresql://postgres:password@localhost/dst",
4741
}
4842

4943
def setUp(self) -> None:

tests/test_remove.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_remove_db_data(
3131
@patch("sqlsynthgen.remove.get_settings")
3232
def test_remove_db_data_raises(self, mock_get: MagicMock) -> None:
3333
"""Check that remove_db_data raises if dst DSN is missing."""
34-
mock_get.return_value = Settings(dst_user_name=None, _env_file=None)
34+
mock_get.return_value = Settings(dst_dsn=None, _env_file=None)
3535
with self.assertRaises(AssertionError) as context_manager:
3636
remove_db_data(example_orm, remove_ssg)
3737
self.assertEqual(
@@ -56,7 +56,7 @@ def test_remove_db_vocab(
5656
@patch("sqlsynthgen.remove.get_settings")
5757
def test_remove_db_vocab_raises(self, mock_get: MagicMock) -> None:
5858
"""Check that remove_db_vocab raises if dst DSN is missing."""
59-
mock_get.return_value = Settings(dst_user_name=None, _env_file=None)
59+
mock_get.return_value = Settings(dst_dsn=None, _env_file=None)
6060
with self.assertRaises(AssertionError) as context_manager:
6161
remove_db_vocab(example_orm, remove_ssg)
6262
self.assertEqual(
@@ -75,7 +75,7 @@ def test_remove_tables(self, mock_engine: MagicMock, _: MagicMock) -> None:
7575
@patch("sqlsynthgen.remove.get_settings")
7676
def test_remove_db_tables_raises(self, mock_get: MagicMock) -> None:
7777
"""Check that remove_db_tables raises if dst DSN is missing."""
78-
mock_get.return_value = Settings(dst_user_name=None, _env_file=None)
78+
mock_get.return_value = Settings(dst_dsn=None, _env_file=None)
7979
with self.assertRaises(AssertionError) as context_manager:
8080
remove_db_tables(example_orm)
8181
self.assertEqual(

tests/utils.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@ def get_test_settings() -> settings.Settings:
1818
"""Get a Settings object that ignores .env files and environment variables."""
1919

2020
return settings.Settings(
21-
src_host_name="shost",
22-
src_user_name="suser",
23-
src_password="spassword",
24-
src_db_name="sdbname",
25-
dst_host_name="dhost",
26-
dst_user_name="duser",
27-
dst_password="dpassword",
28-
dst_db_name="ddbname",
21+
src_dsn="postgresql://suser:spassword@shost:5432/sdbname",
22+
dst_dsn="postgresql://duser:dpassword@dhost:5432/ddbname",
2923
# To stop any local .env files influencing the test
3024
_env_file=None,
3125
)

0 commit comments

Comments
 (0)