From 9c846979be37eafb333b947399c9a8b79f75fc94 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 23 Apr 2019 16:44:39 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20error=20if=20service=20without?= =?UTF-8?q?=20an=20organisation=20requests=20to=20go=20live?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was trying to look at `organisation.domains`, which caused an `AttributeError` if there wasn’t an organisation. --- app/models/organisation.py | 2 +- tests/app/main/views/test_service_settings.py | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/models/organisation.py b/app/models/organisation.py index 555bafa44..59f199dfd 100644 --- a/app/models/organisation.py +++ b/app/models/organisation.py @@ -25,7 +25,7 @@ class Organisation(JSONModel): super().__init__(_dict) if self._dict == {}: - self.name, self.crown, self.agreement_signed = None, None, None + self.name, self.crown, self.agreement_signed, self.domains = None, None, None, [] def as_human_readable(self, fallback_domain): if 'dwp.' in ''.join(self.domains): diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 2919689d0..bf0c070cd 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1407,6 +1407,42 @@ def test_should_redirect_after_request_to_go_live( ) +def test_should_be_able_to_request_to_go_live_with_no_organisation( + client_request, + mocker, + single_reply_to_email_address, + single_letter_contact_block, + mock_get_organisations_and_services_for_user, + single_sms_sender, + mock_get_service_settings_page_common, + mock_get_service_templates, + mock_get_users_by_service, + mock_update_service, + mock_get_invites_without_manage_permission, +): + get_service_organisation = mocker.patch( + 'app.organisations_client.get_service_organisation', + return_value=None, + ) + for channel in {'email', 'sms', 'letter'}: + mocker.patch( + 'app.models.service.Service.volume_{}'.format(channel), + create=True, + new_callable=PropertyMock, + return_value=1, + ) + mock_post = mocker.patch('app.main.views.service_settings.zendesk_client.create_ticket', autospec=True) + + client_request.post( + 'main.request_to_go_live', + service_id=SERVICE_ONE_ID, + _follow_redirects=True + ) + + assert mock_post.called is True + get_service_organisation.assert_called_once_with(SERVICE_ONE_ID) + + @pytest.mark.parametrize( ( 'has_team_members,'