Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
i-oden committed Sep 6, 2023
1 parent 047f8ce commit 5eba2c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dds_cli/superadmin_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
38 changes: 18 additions & 20 deletions tests/test_superadmin_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5eba2c8

Please sign in to comment.