From 5eba2c8f2a7606a568874688954dba8898f1b2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ina=20Od=C3=A9n=20=C3=96sterbo?= Date: Wed, 6 Sep 2023 15:36:02 +0200 Subject: [PATCH] fix test --- dds_cli/superadmin_helper.py | 2 +- tests/test_superadmin_helper.py | 38 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/dds_cli/superadmin_helper.py b/dds_cli/superadmin_helper.py index aa1bcc36..e0cffc7b 100644 --- a/dds_cli/superadmin_helper.py +++ b/dds_cli/superadmin_helper.py @@ -81,13 +81,13 @@ def display_maintenance_mode_status(self) -> None: def get_stats(self) -> None: """Get rows from statistics.""" + # Get stats from API response_json, _ = dds_cli.utils.perform_request( endpoint=DDSEndpoint.STATS, headers=self.token, method="get", error_message="Failed getting statistics from API.", ) - LOG.debug(response_json) # Get items from response stats, columns = dds_cli.utils.get_required_in_response( diff --git a/tests/test_superadmin_helper.py b/tests/test_superadmin_helper.py index 2d5b04ab..ad5e8b45 100644 --- a/tests/test_superadmin_helper.py +++ b/tests/test_superadmin_helper.py @@ -120,45 +120,43 @@ def test_deactivate_maintenance_ok(caplog: LogCaptureFixture): ) in caplog.record_tuples -def test_get_stats(caplog: LogCaptureFixture): - """""" - returned_response: typing.Dict = {"message": "Message from API about mode change."} +def test_get_maintenance_mode_status_ok(caplog: LogCaptureFixture): + """Check current maintenance mode status.""" + returned_response: typing.Dict = {"message": "Message from API about mode status."} with caplog.at_level(logging.INFO): # Create mocker with Mocker() as mock: # Create mocked request - real request not executed - mock.put(DDSEndpoint.STATS, status_code=200, json=returned_response) + mock.get(DDSEndpoint.MAINTENANCE, status_code=200, json=returned_response) - with superadmin_helper.SuperAdminHelper( + with superadmin_helper.MaintenanceManager( authenticate=False, no_prompt=True ) as maint_mngr: maint_mngr.token = {} # required, otherwise none - maint_mngr.change_maintenance_mode(setting="on") # Run deactivation + maint_mngr.display_maintenance_mode_status() # Run deactivation assert ( - "dds_cli.superadmin_helper", + "dds_cli.maintenance_manager", logging.INFO, - "Message from API about mode change.", + "Message from API about mode status.", ) in caplog.record_tuples -def test_get_maintenance_mode_status_ok(caplog: LogCaptureFixture): - """Check current maintenance mode status.""" - returned_response: typing.Dict = {"message": "Message from API about mode status."} +def test_get_stats(caplog: LogCaptureFixture): + """Print stats.""" + returned_response: typing.Dict = {} with caplog.at_level(logging.INFO): # Create mocker with Mocker() as mock: # Create mocked request - real request not executed - mock.get(DDSEndpoint.MAINTENANCE, status_code=200, json=returned_response) + mock.put(DDSEndpoint.STATS, status_code=200, json=returned_response) - with superadmin_helper.MaintenanceManager( - authenticate=False, no_prompt=True - ) as maint_mngr: - maint_mngr.token = {} # required, otherwise none - maint_mngr.display_maintenance_mode_status() # Run deactivation + with superadmin_helper.SuperAdminHelper(authenticate=False, no_prompt=True) as helper: + helper.token = {} # required, otherwise none + helper.get_stats() # Get stats assert ( - "dds_cli.maintenance_manager", - logging.INFO, - "Message from API about mode status.", + "dds_cli.superadmin_helper", + logging.ERROR, + "The following information was not returned: ['stats', 'columns']", ) in caplog.record_tuples