mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 16:39:49 -04:00
adding templates and refactor to use dashboard data endpoint
This commit is contained in:
@@ -77,17 +77,17 @@ def get_organization_message_allowance(org_id):
|
|||||||
|
|
||||||
|
|
||||||
def get_services_usage(organization, year):
|
def get_services_usage(organization, year):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
services_and_usage = organization.services_and_usage(financial_year=year, include_all_services=True)["services"]
|
dashboard_data = organizations_client.get_organization_dashboard(organization.id, year)
|
||||||
|
services = dashboard_data.get("services", [])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(f"Error fetching services and usage: {e}")
|
current_app.logger.error(f"Error fetching dashboard data: {e}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
services = []
|
for service in services:
|
||||||
for service in services_and_usage:
|
|
||||||
service["id"] = service.get("service_id")
|
service["id"] = service.get("service_id")
|
||||||
service["name"] = service.get("service_name")
|
service["name"] = service.get("service_name")
|
||||||
|
service["recent_template"] = service.get("recent_sms_template_name")
|
||||||
|
|
||||||
emails_sent = service.get("emails_sent", 0)
|
emails_sent = service.get("emails_sent", 0)
|
||||||
sms_sent = service.get("sms_billable_units", 0)
|
sms_sent = service.get("sms_billable_units", 0)
|
||||||
@@ -105,8 +105,6 @@ def get_services_usage(organization, year):
|
|||||||
|
|
||||||
service["usage"] = ", ".join(usage_parts) if usage_parts else "No usage"
|
service["usage"] = ", ".join(usage_parts) if usage_parts else "No usage"
|
||||||
|
|
||||||
services.append(service)
|
|
||||||
|
|
||||||
return services
|
return services
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,5 +83,11 @@ class OrganizationsClient(NotifyAdminAPIClient):
|
|||||||
url="/organizations/{}/message-allowance".format(org_id),
|
url="/organizations/{}/message-allowance".format(org_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_organization_dashboard(self, org_id, year):
|
||||||
|
return self.get(
|
||||||
|
url=f"/organizations/{org_id}/dashboard",
|
||||||
|
params={"year": str(year)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
organizations_client = OrganizationsClient()
|
organizations_client = OrganizationsClient()
|
||||||
|
|||||||
@@ -1582,7 +1582,7 @@ def test_organization_dashboard_shows_service_counts(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
"app.organizations_client.get_services_and_usage",
|
"app.organizations_client.get_organization_dashboard",
|
||||||
return_value={
|
return_value={
|
||||||
"services": [
|
"services": [
|
||||||
{
|
{
|
||||||
@@ -1658,7 +1658,7 @@ def test_organization_dashboard_services_table_shows_usage(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
"app.organizations_client.get_services_and_usage",
|
"app.organizations_client.get_organization_dashboard",
|
||||||
return_value={
|
return_value={
|
||||||
"services": [
|
"services": [
|
||||||
{
|
{
|
||||||
@@ -1670,6 +1670,7 @@ def test_organization_dashboard_services_table_shows_usage(
|
|||||||
"sms_cost": 42.75,
|
"sms_cost": 42.75,
|
||||||
"active": True,
|
"active": True,
|
||||||
"restricted": False,
|
"restricted": False,
|
||||||
|
"recent_sms_template_name": "Welcome SMS",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"service_id": "2",
|
"service_id": "2",
|
||||||
@@ -1680,6 +1681,7 @@ def test_organization_dashboard_services_table_shows_usage(
|
|||||||
"sms_cost": 0,
|
"sms_cost": 0,
|
||||||
"active": True,
|
"active": True,
|
||||||
"restricted": True,
|
"restricted": True,
|
||||||
|
"recent_sms_template_name": "Reminder SMS",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user