Skip to content

Commit

Permalink
fix column descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
i-oden committed Sep 6, 2023
1 parent 7175dc1 commit 047f8ce
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
74 changes: 34 additions & 40 deletions dds_cli/superadmin_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(
# Initiate DDSBaseClass to authenticate user
super().__init__(
authenticate=authenticate,
method=False,
method_check=False,
no_prompt=no_prompt,
token_path=token_path,
)
Expand Down Expand Up @@ -90,62 +90,56 @@ def get_stats(self) -> None:
LOG.debug(response_json)

# Get items from response
stats = response_json.get("stats")
if not stats:
raise dds_cli.exceptions.ApiResponseError(message="No stats were returned from API.")
stats, columns = dds_cli.utils.get_required_in_response(
keys=["stats", "columns"], response=response_json
)

# Format table consisting of user stats
user_stat_columns = [
"Date",
"Units",
"Researchers",
"Project Owners",
"Unit Personnel",
"Unit Admins",
"Super Admins",
"Total Users",
]
column_descriptions = " ".join(
f"[underline]{col}[/underline]: {columns[col]}" for col in user_stat_columns
)
table_users = dds_cli.utils.create_table(
title="Units and accounts",
columns=[
"Date",
"Units",
"Researchers",
"Project Owners",
"Unit Personnel",
"Unit Admins",
"Super Admins",
"Total Users",
],
columns=user_stat_columns,
rows=stats,
caption=(
"Number of Units using the DDS for data deliveries, and number of accounts with different roles.\n"
# "[underline]Researchers[/underline]: "
# "[underline]Project Owners[/underline]:
# "[underline]Unit Personnel[/underline]: "
# "[underline]Unit Admins[/underline]: "
# "[underline]Super Admins[/underline]:
# "[underline]Total Users[/underline]:
f"Number of Units using the DDS for data deliveries, and number of accounts with different roles.\n {column_descriptions}"
),
)
dds_cli.utils.console.print(
table_users, "\n"
) # TODO: Possibly change to print_or_page later on, or give option to save stats

# Format table consisting of project and data stats
project_stat_columns = [
"Date",
"Active Projects",
"Inactive Projects",
"Total Projects",
"Data Now (TB)",
"Data Uploaded (TB)",
"TBHours Last Month",
"TBHours Total",
]
column_descriptions = " ".join(
f"[underline]{col}[/underline]: {columns[col]}" for col in project_stat_columns
)
table_data = dds_cli.utils.create_table(
title="Amount of data delivered via the DDS",
columns=[
"Date",
"Active Projects",
"Inactive Projects",
"Total Projects",
"Data Now (TB)",
"Data Uploaded (TB)",
"TBHours Last Month",
"TBHours Total",
],
columns=project_stat_columns,
rows=stats,
caption=(
"Number of delivery projects and amount of data that is being (and has been) delivered via the DDS.\n"
# "[underline]Date[/underline]: "
# "[underline]Active Projects[/underline]: "
# "[underline]Inactive Projects[/underline]: "
# "[underline]Total Projects[/underline]: "
# "[underline]Data Now (TB)[/underline]: "
# "[underline]Data Uploaded (TB)[/underline]: "
# "[underline]TBHours Last Month[/underline]: "
# "[underline]TBHours Total[/underline]: "
f"Number of delivery projects and amount of data that is being (and has been) delivered via the DDS.\n {column_descriptions}"
),
)
dds_cli.utils.console.print(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_superadmin_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ def test_get_stats(caplog: LogCaptureFixture):

def test_get_maintenance_mode_status_ok(caplog: LogCaptureFixture):
"""Check current maintenance mode status."""
returned_response: Dict = {"message": "Message from API about 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.get(DDSEndpoint.MAINTENANCE, status_code=200, json=returned_response)

with maintenance_manager.MaintenanceManager(
with superadmin_helper.MaintenanceManager(
authenticate=False, no_prompt=True
) as maint_mngr:
maint_mngr.token = {} # required, otherwise none
Expand Down

0 comments on commit 047f8ce

Please sign in to comment.