From 3ea9cba0bc0868ca88619c06a4d5c7a1ed45cfb4 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 15 Mar 2021 09:42:06 +0000 Subject: [PATCH] Fix bug when live services have no organisation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The performance page expects all live services to have an organisation. This should be true on production, but it isn’t always the case in other environments. When the organisation name is `None`, the frontend can’t sort the list of organisations alphabetically and so raises an exception. --- app/main/views/performance.py | 2 +- tests/app/main/views/test_performance.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/main/views/performance.py b/app/main/views/performance.py index 86f3b8bc9..29fd73a85 100644 --- a/app/main/views/performance.py +++ b/app/main/views/performance.py @@ -18,7 +18,7 @@ def performance(): stats['organisations_using_notify'] = sorted( [ { - 'organisation_name': organisation_name, + 'organisation_name': organisation_name or 'No organisation', 'count_of_live_services': len(list(group)), } for organisation_name, group in groupby( diff --git a/tests/app/main/views/test_performance.py b/tests/app/main/views/test_performance.py index 17519a7a9..6418d6d5f 100644 --- a/tests/app/main/views/test_performance.py +++ b/tests/app/main/views/test_performance.py @@ -93,6 +93,15 @@ def _get_example_performance_data(): "service_id": uuid.uuid4(), "service_name": "Example service 3" }, + { + # On production there should be no live services without an + # organisation, but this isn’t always true in people’s local + # environments + "organisation_id": None, + "organisation_name": None, + "service_id": uuid.uuid4(), + "service_name": "Example service 4" + }, ], } @@ -150,5 +159,6 @@ def test_should_render_performance_page( 'Organisations using Notify ' 'Organisation Number of live services ' 'Department of Examples and Patterns 2 ' - 'Department of One Service 1' + 'Department of One Service 1 ' + 'No organisation 1' )