update test

This commit is contained in:
Beverly Nguyen
2025-10-27 17:28:31 -07:00
parent c7c4b37a2a
commit 304efabeec
5 changed files with 16 additions and 13 deletions

View File

@@ -76,7 +76,7 @@ def get_organization_message_allowance(org_id):
}
def get_services_usage(organization, year):
def get_services_dashboard_data(organization, year):
try:
dashboard_data = organizations_client.get_organization_dashboard(organization.id, year)
services = dashboard_data.get("services", [])
@@ -87,7 +87,8 @@ def get_services_usage(organization, year):
for service in services:
service["id"] = service.get("service_id")
service["name"] = service.get("service_name")
service["recent_template"] = service.get("recent_sms_template_name")
service["recent_template"] = service.get("recent_sms_template_name") or "N/A"
service["primary_contact"] = service.get("primary_contact") or "N/A"
emails_sent = service.get("emails_sent", 0)
sms_sent = service.get("sms_billable_units", 0)
@@ -118,7 +119,7 @@ def organization_dashboard(org_id):
message_allowance = get_organization_message_allowance(org_id)
services_with_usage = get_services_usage(current_organization, year)
services_with_usage = get_services_dashboard_data(current_organization, year)
return render_template(
"views/organizations/organization/index.html",

View File

@@ -139,8 +139,8 @@ class Organization(JSONModel, SortByNameMixin):
def associate_service(self, service_id):
organizations_client.update_service_organization(service_id, self.id)
def services_and_usage(self, financial_year, include_all_services=False):
return organizations_client.get_services_and_usage(self.id, financial_year, include_all_services)
def services_and_usage(self, financial_year):
return organizations_client.get_services_and_usage(self.id, financial_year)
class Organizations(SerialisedModelCollection):

View File

@@ -72,10 +72,10 @@ class OrganizationsClient(NotifyAdminAPIClient):
def remove_user_from_organization(self, org_id, user_id):
return self.delete(f"/organizations/{org_id}/users/{user_id}")
def get_services_and_usage(self, org_id, year, include_all_services=False):
def get_services_and_usage(self, org_id, year):
return self.get(
url=f"/organizations/{org_id}/services-with-usage",
params={"year": str(year), "include_all_services": str(include_all_services).lower()},
params={"year": str(year)},
)
def get_organization_message_usage(self, org_id):

View File

@@ -104,9 +104,9 @@
Live
{% endif %}
</td>
<td>{{ service.usage|default('N/A') }}</td>
<td>{{ service.primary_contact|default('N/A') }}</td>
<td>{{ service.recent_template|default('N/A') }}</td>
<td>{{ service.usage }}</td>
<td>{{ service.primary_contact }}</td>
<td>{{ service.recent_template }}</td>
</tr>
{% endfor %}
{% else %}

View File

@@ -354,7 +354,7 @@ def test_organization_services_shows_live_services_and_usage(
client_request.login(active_user_with_permissions)
page = client_request.get(".organization_usage", org_id=ORGANISATION_ID)
mock.assert_called_once_with(ORGANISATION_ID, 2020, False)
mock.assert_called_once_with(ORGANISATION_ID, 2020)
services = page.select("main h3")
usage_rows = page.select("main .grid-col-6")
@@ -447,7 +447,7 @@ def test_organization_services_filters_by_financial_year(
org_id=ORGANISATION_ID,
year=financial_year,
)
mock.assert_called_once_with(ORGANISATION_ID, financial_year, False)
mock.assert_called_once_with(ORGANISATION_ID, financial_year)
assert normalize_spaces(page.select_one(".pill").text) == (
"2020 to 2021 fiscal year "
"2019 to 2020 fiscal year "
@@ -1609,7 +1609,7 @@ def test_organization_dashboard_shows_service_counts(
assert "1 Suspended" in normalize_spaces(service_box.text)
def test_organization_dashboard_services_table_shows_usage(
def test_organization_dashboard_services_table(
client_request,
mock_get_organization,
mocker,
@@ -1642,6 +1642,7 @@ def test_organization_dashboard_services_table_shows_usage(
"sms_remainder": 249500,
"sms_cost": 42.75,
"recent_sms_template_name": "Welcome SMS",
"primary_contact": None,
},
{
"service_id": "2",
@@ -1653,6 +1654,7 @@ def test_organization_dashboard_services_table_shows_usage(
"sms_remainder": 249900,
"sms_cost": 0,
"recent_sms_template_name": "Reminder SMS",
"primary_contact": None,
},
]
},