mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 08:28:15 -04:00
Merge pull request #3332 from alphagov/organisation-usage
Add usage stats to organisation page.
This commit is contained in:
@@ -125,8 +125,10 @@ def add_organisation_from_nhs_local_service(service_id):
|
|||||||
@main.route("/organisations/<uuid:org_id>", methods=['GET'])
|
@main.route("/organisations/<uuid:org_id>", methods=['GET'])
|
||||||
@user_has_permissions()
|
@user_has_permissions()
|
||||||
def organisation_dashboard(org_id):
|
def organisation_dashboard(org_id):
|
||||||
|
services = current_organisation.services_and_usage()
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/organisations/organisation/index.html',
|
'views/organisations/organisation/index.html',
|
||||||
|
services=services
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from app.models import JSONModel, ModelList
|
|||||||
from app.notify_client.email_branding_client import email_branding_client
|
from app.notify_client.email_branding_client import email_branding_client
|
||||||
from app.notify_client.letter_branding_client import letter_branding_client
|
from app.notify_client.letter_branding_client import letter_branding_client
|
||||||
from app.notify_client.organisations_api_client import organisations_client
|
from app.notify_client.organisations_api_client import organisations_client
|
||||||
|
from app.utils import get_current_financial_year
|
||||||
|
|
||||||
|
|
||||||
class Organisation(JSONModel):
|
class Organisation(JSONModel):
|
||||||
@@ -198,6 +199,9 @@ class Organisation(JSONModel):
|
|||||||
self.id
|
self.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def services_and_usage(self):
|
||||||
|
return organisations_client.get_services_and_usage(self.id, get_current_financial_year())
|
||||||
|
|
||||||
|
|
||||||
class Organisations(ModelList):
|
class Organisations(ModelList):
|
||||||
client_method = organisations_client.get_organisations
|
client_method = organisations_client.get_organisations
|
||||||
|
|||||||
@@ -87,5 +87,11 @@ class OrganisationsClient(NotifyAdminAPIClient):
|
|||||||
params={"org_id": org_id, "name": name}
|
params={"org_id": org_id, "name": name}
|
||||||
)["result"]
|
)["result"]
|
||||||
|
|
||||||
|
def get_services_and_usage(self, org_id, year):
|
||||||
|
return self.get(
|
||||||
|
url=f"/organisations/{org_id}/services-with-usage",
|
||||||
|
params={"year": str(year)}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
organisations_client = OrganisationsClient()
|
organisations_client = OrganisationsClient()
|
||||||
|
|||||||
@@ -9,11 +9,17 @@
|
|||||||
<h1 class="heading-medium">
|
<h1 class="heading-medium">
|
||||||
Usage
|
Usage
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for service in current_org.live_services %}
|
{% for service in services['services'] %}
|
||||||
<li class="browse-list-item">
|
<li class="browse-list-item">
|
||||||
<a href="{{ url_for('main.usage', service_id=service.id) }}" class="govuk-link govuk-link--no-visited-state browse-list-link">{{ service['name'] }}</a>
|
<a href="{{ url_for('main.usage', service_id=service.service_id) }}" class="govuk-link govuk-link--no-visited-state browse-list-link">{{ service.service_name }}</a>
|
||||||
</li>
|
</li>
|
||||||
|
<div class="grid-row">
|
||||||
|
<div class="column-one-third">{{ service.emails_sent|format_thousands }} emails sent</div>
|
||||||
|
<div class="column-one-third">{{ "£{:,.2f}".format(service.sms_cost) }} spent on text messages</div>
|
||||||
|
<div class="column-one-third">{{ "£{:,.2f}".format(service.letter_cost) }} spent on letters</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ def test_view_organisation_shows_the_correct_organisation(
|
|||||||
'app.organisations_client.get_organisation', return_value=org
|
'app.organisations_client.get_organisation', return_value=org
|
||||||
)
|
)
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'app.organisations_client.get_organisation_services', return_value=[]
|
'app.organisations_client.get_services_and_usage', return_value=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
page = client_request.get(
|
page = client_request.get(
|
||||||
@@ -389,26 +389,28 @@ def test_nhs_local_assigns_to_selected_organisation(
|
|||||||
mock_update_service_organisation.assert_called_once_with(SERVICE_ONE_ID, ORGANISATION_ID)
|
mock_update_service_organisation.assert_called_once_with(SERVICE_ONE_ID, ORGANISATION_ID)
|
||||||
|
|
||||||
|
|
||||||
def test_organisation_services_shows_live_services_only(
|
def test_organisation_services_shows_live_services_and_usage(
|
||||||
client_request,
|
client_request,
|
||||||
mock_get_organisation,
|
mock_get_organisation,
|
||||||
mocker,
|
mocker,
|
||||||
active_user_with_permissions,
|
active_user_with_permissions,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
):
|
):
|
||||||
mocker.patch(
|
mock = mocker.patch(
|
||||||
'app.organisations_client.get_organisation_services',
|
'app.organisations_client.get_services_and_usage',
|
||||||
return_value=[
|
return_value={"services": [
|
||||||
service_json(id_=SERVICE_ONE_ID, name='1', restricted=False, active=True), # live
|
{'service_id': SERVICE_ONE_ID, 'service_name': '1', 'chargeable_billable_sms': 250122, 'emails_sent': 13000,
|
||||||
service_json(id_='2', name='2', restricted=True, active=True), # trial
|
'free_sms_limit': 250000, 'letter_cost': 30.50, 'sms_billable_units': 122, 'sms_cost': 1.93,
|
||||||
service_json(id_='3', name='3', restricted=True, active=False), # trial, now archived
|
'sms_remainder': None},
|
||||||
service_json(id_='4', name='4', restricted=False, active=False), # was live, now archived
|
{'service_id': SERVICE_TWO_ID, 'service_name': '5', 'chargeable_billable_sms': 0, 'emails_sent': 20000,
|
||||||
service_json(id_=SERVICE_TWO_ID, name='5', restricted=False, active=True), # live, member of
|
'free_sms_limit': 250000, 'letter_cost': 0, 'sms_billable_units': 2500, 'sms_cost': 0.0,
|
||||||
]
|
'sms_remainder': None}
|
||||||
|
]}
|
||||||
)
|
)
|
||||||
|
|
||||||
client_request.login(active_user_with_permissions)
|
client_request.login(active_user_with_permissions)
|
||||||
page = client_request.get('.organisation_dashboard', org_id=ORGANISATION_ID)
|
page = client_request.get('.organisation_dashboard', org_id=ORGANISATION_ID)
|
||||||
|
mock.assert_called_once_with(ORGANISATION_ID, 2019)
|
||||||
|
|
||||||
services = page.select('.browse-list-item')
|
services = page.select('.browse-list-item')
|
||||||
assert len(services) == 2
|
assert len(services) == 2
|
||||||
@@ -416,7 +418,14 @@ def test_organisation_services_shows_live_services_only(
|
|||||||
assert normalize_spaces(services[0].text) == '1'
|
assert normalize_spaces(services[0].text) == '1'
|
||||||
assert normalize_spaces(services[1].text) == '5'
|
assert normalize_spaces(services[1].text) == '5'
|
||||||
assert services[0].find('a')['href'] == url_for('main.usage', service_id=SERVICE_ONE_ID)
|
assert services[0].find('a')['href'] == url_for('main.usage', service_id=SERVICE_ONE_ID)
|
||||||
|
usage_rows = page.find_all("div", class_="column-one-third")
|
||||||
|
assert normalize_spaces(usage_rows[0].text) == "13,000 emails sent"
|
||||||
|
assert normalize_spaces(usage_rows[1].text) == "£1.93 spent on text messages"
|
||||||
|
assert normalize_spaces(usage_rows[2].text) == "£30.50 spent on letters"
|
||||||
assert services[1].find('a')['href'] == url_for('main.usage', service_id=SERVICE_TWO_ID)
|
assert services[1].find('a')['href'] == url_for('main.usage', service_id=SERVICE_TWO_ID)
|
||||||
|
assert normalize_spaces(usage_rows[3].text) == "20,000 emails sent"
|
||||||
|
assert normalize_spaces(usage_rows[4].text) == "£0.00 spent on text messages"
|
||||||
|
assert normalize_spaces(usage_rows[5].text) == "£0.00 spent on letters"
|
||||||
|
|
||||||
|
|
||||||
def test_organisation_trial_mode_services_shows_all_non_live_services(
|
def test_organisation_trial_mode_services_shows_all_non_live_services(
|
||||||
|
|||||||
@@ -143,12 +143,15 @@ def test_a_page_should_nave_selected_header_navigation_item(
|
|||||||
def test_a_page_should_nave_selected_org_navigation_item(
|
def test_a_page_should_nave_selected_org_navigation_item(
|
||||||
client_request,
|
client_request,
|
||||||
mock_get_organisation,
|
mock_get_organisation,
|
||||||
mock_get_organisation_services,
|
|
||||||
mock_get_users_for_organisation,
|
mock_get_users_for_organisation,
|
||||||
mock_get_invited_users_for_organisation,
|
mock_get_invited_users_for_organisation,
|
||||||
endpoint,
|
endpoint,
|
||||||
selected_nav_item,
|
selected_nav_item,
|
||||||
|
mocker
|
||||||
):
|
):
|
||||||
|
mocker.patch(
|
||||||
|
'app.organisations_client.get_services_and_usage', return_value=[]
|
||||||
|
)
|
||||||
page = client_request.get(endpoint, org_id=ORGANISATION_ID)
|
page = client_request.get(endpoint, org_id=ORGANISATION_ID)
|
||||||
selected_nav_items = page.select('.navigation a.selected')
|
selected_nav_items = page.select('.navigation a.selected')
|
||||||
assert len(selected_nav_items) == 1
|
assert len(selected_nav_items) == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user