From febc6f4e23cbb203beadd31bf3f1a520da6ba1af Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Fri, 10 Aug 2018 17:27:58 +0100 Subject: [PATCH] This PR fixes the check for the text key in the post data. --- app/email_branding/rest.py | 4 ++-- tests/app/email_branding/test_rest.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/email_branding/rest.py b/app/email_branding/rest.py index 356e19bac..0991c9d0b 100644 --- a/app/email_branding/rest.py +++ b/app/email_branding/rest.py @@ -37,7 +37,7 @@ def create_email_branding(): validate(data, post_create_email_branding_schema) email_branding = EmailBranding(**data) - if not data.get('text'): + if 'text' not in data.keys(): email_branding.text = email_branding.name dao_create_email_branding(email_branding) @@ -51,7 +51,7 @@ def update_email_branding(email_branding_id): validate(data, post_update_email_branding_schema) fetched_email_branding = dao_get_email_branding_by_id(email_branding_id) - if not data.get('text') and data.get('name'): + if 'text' not in data.keys() and 'name' in data.keys(): data['text'] = data['name'] dao_update_email_branding(fetched_email_branding, **data) diff --git a/tests/app/email_branding/test_rest.py b/tests/app/email_branding/test_rest.py index 3c460b137..0661a6f2c 100644 --- a/tests/app/email_branding/test_rest.py +++ b/tests/app/email_branding/test_rest.py @@ -120,6 +120,24 @@ def test_post_create_email_branding_with_text_and_name(admin_request, notify_db_ assert response['data']['text'] == 'text for brand' +def test_post_create_email_branding_with_text_as_none_and_name(admin_request, notify_db_session): + data = { + 'name': 'name for brand', + 'text': None, + 'logo': 'images/text_x2.png' + } + response = admin_request.post( + 'email_branding.create_email_branding', + _data=data, + _expected_status=201 + ) + + assert response['data']['logo'] == data['logo'] + assert response['data']['name'] == 'name for brand' + assert response['data']['colour'] is None + assert response['data']['text'] is None + + @pytest.mark.parametrize('data_update', [ ({'name': 'test email_branding 1'}), ({'logo': 'images/text_x3.png', 'colour': '#ffffff'}), @@ -155,6 +173,7 @@ def test_post_update_email_branding_updates_field(admin_request, notify_db_sessi @pytest.mark.parametrize('data_update', [ ({'text': 'text email branding'}), ({'text': 'new text', 'name': 'new name'}), + ({'text': None, 'name': 'test name'}), ]) def test_post_update_email_branding_updates_field_with_text(admin_request, notify_db_session, data_update): data = {