From bfcf4be44788e18be03f341a288ccbfaf76a9a21 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 16 Aug 2016 13:43:15 +0100 Subject: [PATCH] separate branding/org test into two tests it's a bit more legible and the running time of these tests is negligable so split up the test into its two logical components --- tests/__init__.py | 2 +- tests/app/main/views/test_service_settings.py | 45 ++++++++++++------- tests/conftest.py | 2 +- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index e44dc1f3b..6e1fef4e6 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -50,7 +50,7 @@ def service_json( reply_to_email_address=None, sms_sender=None, research_mode=False, - organisation='organisation-name', + organisation='organisation-id', branding='govuk' ): return { diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index c527365b4..8b214b647 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -761,7 +761,7 @@ def test_set_text_message_sender_flash_messages( assert element.text.strip() == expected_flash_message -def test_should_show_branding_and_organisations( +def test_should_show_branding( mocker, app_, platform_admin_user, service_one, mock_get_organisations ): with app_.test_request_context(), app_.test_client() as client: @@ -773,22 +773,35 @@ def test_should_show_branding_and_organisations( page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.find('input', attrs={"id": "branding_type-0"})['value'] == 'govuk' - assert page.find('input', attrs={"id": "branding_type-0"})['checked'] == '' assert page.find('input', attrs={"id": "branding_type-1"})['value'] == 'both' - with pytest.raises(KeyError): - page.find('input', attrs={"id": "branding_type-1"})['checked'] assert page.find('input', attrs={"id": "branding_type-2"})['value'] == 'org' - with pytest.raises(KeyError): - page.find('input', attrs={"id": "branding_type-2"})['checked'] - assert page.find('label', attrs={"for": "organisation-1"}).text.strip() == 'None' - assert page.find('input', attrs={"id": "organisation-1"})['value'] == 'None' - assert page.find('label', attrs={"for": "organisation-2"}).text.strip() == 'Organisation name' - assert page.find('input', attrs={"id": "organisation-2"})['value'] == 'organisation-name' - assert page.find('label', attrs={"for": "organisation-2"}).find('img')['src'] == ( - '/static/images/email-template/crests/example.png' - ) - assert '#f00' in str(page.find('label', attrs={"for": "organisation-2"})) + assert 'checked' in page.find('input', attrs={"id": "branding_type-0"}).attrs + assert 'checked' not in page.find('input', attrs={"id": "branding_type-1"}).attrs + assert 'checked' not in page.find('input', attrs={"id": "branding_type-2"}).attrs + + app.organisations_client.get_organisations.assert_called_once_with() + app.service_api_client.get_service.assert_called_once_with(service_one['id']) + + +def test_should_show_organisations( + mocker, app_, platform_admin_user, service_one, mock_get_organisations +): + with app_.test_request_context(), app_.test_client() as client: + client.login(platform_admin_user, mocker, service_one) + response = client.get(url_for( + 'main.service_set_branding_and_org', service_id=service_one['id'] + )) + assert response.status_code == 200 + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + + assert page.find('input', attrs={"id": "branding_type-0"})['value'] == 'govuk' + assert page.find('input', attrs={"id": "branding_type-1"})['value'] == 'both' + assert page.find('input', attrs={"id": "branding_type-2"})['value'] == 'org' + + assert 'checked' in page.find('input', attrs={"id": "branding_type-0"}).attrs + assert 'checked' not in page.find('input', attrs={"id": "branding_type-1"}).attrs + assert 'checked' not in page.find('input', attrs={"id": "branding_type-2"}).attrs app.organisations_client.get_organisations.assert_called_once_with() app.service_api_client.get_service.assert_called_once_with(service_one['id']) @@ -805,7 +818,7 @@ def test_should_set_branding_and_organisations( ), data={ 'branding_type': 'org', - 'organisation': 'organisation-name' + 'organisation': 'organisation-id' } ) assert response.status_code == 302 @@ -815,5 +828,5 @@ def test_should_set_branding_and_organisations( app.service_api_client.update_service.assert_called_once_with( service_one['id'], branding='org', - organisation='organisation-name' + organisation='organisation-id' ) diff --git a/tests/conftest.py b/tests/conftest.py index b25460c5f..25bde5c81 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1142,7 +1142,7 @@ def mock_get_organisations(mocker): { 'logo': 'example.png', 'name': 'Organisation name', - 'id': 'organisation-name', + 'id': 'organisation-id', 'colour': '#f00' } ]