From 8c7523ac8574a5fd4ccfdf6fa1cbd1cb077da9c8 Mon Sep 17 00:00:00 2001 From: Natasha Singh Date: Mon, 3 Mar 2025 11:37:29 -0500 Subject: [PATCH 1/3] :recycle: Check for empty str and None in db conn params --- d3b_api_client_cli/db/postgres/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d3b_api_client_cli/db/postgres/__init__.py b/d3b_api_client_cli/db/postgres/__init__.py index 361171e..f410c32 100644 --- a/d3b_api_client_cli/db/postgres/__init__.py +++ b/d3b_api_client_cli/db/postgres/__init__.py @@ -25,7 +25,7 @@ class DBConnectionParam: def __post_init__(self): if any( - value is None + not value for value in vars(self).values() if not callable(value) ): From 43164647696f086e2d31e7943d19e57bda427631 Mon Sep 17 00:00:00 2001 From: Natasha Singh Date: Mon, 3 Mar 2025 11:37:41 -0500 Subject: [PATCH 2/3] :white_check_mark: Unit test db conn params --- tests/unit/db/test_postgres.py | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/unit/db/test_postgres.py diff --git a/tests/unit/db/test_postgres.py b/tests/unit/db/test_postgres.py new file mode 100644 index 0000000..d8f234f --- /dev/null +++ b/tests/unit/db/test_postgres.py @@ -0,0 +1,51 @@ +""" +Unit tests for interacting with postgres +""" +import pytest + +from d3b_api_client_cli.db.postgres import DBConnectionParam + + +def test_db_connection_params(): + """ + Test DBConnectionParam + """ + username = "foo" + password = "bar" + hostname = "postgres.com" + port = "5432" + db_name = "postgres" + + params = DBConnectionParam( + username=username, + password=password, + hostname=hostname, + port=port, + db_name=db_name + ) + + assert params.username == username + assert params.password == password + assert params.hostname == hostname + assert params.port == port + assert params.db_name == db_name + + +def test_db_connection_params_error(): + """ + Test DBConnectionParam errors + """ + username = "" + password = "" + hostname = None + port = None + db_name = "postgres" + + with pytest.raises(ValueError): + DBConnectionParam( + username=username, + password=password, + hostname=hostname, + port=port, + db_name=db_name + ) From 5494634cba4e19fa5486d9edc634d2a9e186a0a9 Mon Sep 17 00:00:00 2001 From: Natasha Singh Date: Mon, 3 Mar 2025 11:45:48 -0500 Subject: [PATCH 3/3] :rotating_light: Fix black formatter errors --- d3b_api_client_cli/db/postgres/__init__.py | 4 +--- tests/unit/db/test_postgres.py | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/d3b_api_client_cli/db/postgres/__init__.py b/d3b_api_client_cli/db/postgres/__init__.py index f410c32..e24d185 100644 --- a/d3b_api_client_cli/db/postgres/__init__.py +++ b/d3b_api_client_cli/db/postgres/__init__.py @@ -25,9 +25,7 @@ class DBConnectionParam: def __post_init__(self): if any( - not value - for value in vars(self).values() - if not callable(value) + not value for value in vars(self).values() if not callable(value) ): display = {} for k, v in vars(self).items(): diff --git a/tests/unit/db/test_postgres.py b/tests/unit/db/test_postgres.py index d8f234f..5671bd5 100644 --- a/tests/unit/db/test_postgres.py +++ b/tests/unit/db/test_postgres.py @@ -1,6 +1,7 @@ """ Unit tests for interacting with postgres """ + import pytest from d3b_api_client_cli.db.postgres import DBConnectionParam @@ -21,7 +22,7 @@ def test_db_connection_params(): password=password, hostname=hostname, port=port, - db_name=db_name + db_name=db_name, ) assert params.username == username @@ -47,5 +48,5 @@ def test_db_connection_params_error(): password=password, hostname=hostname, port=port, - db_name=db_name + db_name=db_name, )