From 9f3cd7332e334f2db0ce94d125b53df192734a2b Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Mon, 7 Jun 2021 12:53:04 +0100 Subject: [PATCH] Add missing test for dodgy broadcast account types This moves the redundant assertions for the service not changing to where they're actually relevant, by comparing with the happy path [1]. [1]: https://github.com/alphagov/notifications-admin/blob/c5196fbf0790b7c0c566209c0d298c8d7190349c/tests/app/main/views/test_service_settings.py#L5858 --- tests/app/main/views/test_service_settings.py | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 4c2b8eeaf..b40884c41 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -5900,7 +5900,7 @@ def test_post_service_set_broadcast_network_makes_you_choose( ]), ] ) -def test_post_service_set_broadcast_account_type_confirmation_page( +def test_post_service_confirm_broadcast_account_type_confirmation_page( client_request, platform_admin_user, value, @@ -5926,7 +5926,7 @@ def test_post_service_set_broadcast_account_type_confirmation_page( ("live-government", "live", "government", "all"), ] ) -def test_post_service_set_broadcast_account_type_posts_data_to_api_and_redirects( +def test_post_service_confirm_broadcast_account_type_posts_data_to_api_and_redirects( platform_admin_client, mocker, value, @@ -5962,13 +5962,35 @@ def test_post_service_set_broadcast_account_type_posts_data_to_api_and_redirects ) -def test_post_service_set_broadcast_channel_makes_you_choose( +@pytest.mark.parametrize('account_type', ( + 'foo-severe', + 'training-foo', + 'live-foo', + 'live-government-foo' +)) +def test_post_service_confirm_broadcast_account_type_errors_for_unknown_type( platform_admin_client, mocker, + account_type, ): set_service_broadcast_settings_mock = mocker.patch('app.service_api_client.set_service_broadcast_settings') mock_event_handler = mocker.patch('app.main.views.service_settings.create_broadcast_account_type_change_event') + response = platform_admin_client.post( + url_for( + 'main.service_confirm_broadcast_account_type', + service_id=SERVICE_ONE_ID, + account_type=account_type, + ) + ) + assert response.status_code == 404 + assert not set_service_broadcast_settings_mock.called + assert not mock_event_handler.called + + +def test_post_service_set_broadcast_channel_makes_you_choose( + platform_admin_client, +): response = platform_admin_client.post( url_for( 'main.service_set_broadcast_channel', @@ -5978,5 +6000,3 @@ def test_post_service_set_broadcast_channel_makes_you_choose( assert response.status_code == 200 page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert 'Error: Select mode or channel' in page.find("span", {"class": "govuk-error-message"}).text - assert not set_service_broadcast_settings_mock.called - assert not mock_event_handler.called