From c8003122816111374adfcd1e59da4d8c519ba357 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 13 Sep 2018 15:35:39 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20attempt=20to=20store=20domain?= =?UTF-8?q?=20as=20empty=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When there is a uniqueness constraint on a DB column you can still have multiple null values. You can’t have multiple empty string values. We are trying to save the domain as empty string when creating or updating a new branding. This means that it’s currently not possible to create or update a branding with no domain, because the uniqueness constraint is violated. --- app/main/forms.py | 2 ++ tests/app/main/views/test_email_branding.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index e16364980..06d7e5ddc 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -728,6 +728,8 @@ class GovernmentDomainField(StringField): ] def post_validate(self, form, validation_stopped): + if self.data == '': + self.data = None if self.data and not self.errors: self.data = AgreementInfo(self.data).canonical_domain diff --git a/tests/app/main/views/test_email_branding.py b/tests/app/main/views/test_email_branding.py index e190b0d30..c056d9e27 100644 --- a/tests/app/main/views/test_email_branding.py +++ b/tests/app/main/views/test_email_branding.py @@ -84,18 +84,24 @@ def test_create_email_branding_does_not_show_any_branding_info( assert page.select_one('#domain').attrs.get('value') == '' +@pytest.mark.parametrize('posted_domain, persisted_domain', [ + ('voa.gov.uk', 'voa.gov.uk'), + ('', None), +]) def test_create_new_email_branding_without_logo( logged_in_platform_admin_client, mocker, fake_uuid, - mock_create_email_branding + mock_create_email_branding, + posted_domain, + persisted_domain, ): data = { 'logo': None, 'colour': '#ff0000', 'text': 'new text', 'name': 'new name', - 'domain': 'voa.gov.uk', + 'domain': posted_domain, 'brand_type': 'org' } @@ -114,7 +120,7 @@ def test_create_new_email_branding_without_logo( name=data['name'], text=data['text'], colour=data['colour'], - domain=data['domain'], + domain=persisted_domain, brand_type=data['brand_type'] ) assert mock_persist.call_args_list == []