From 9783ab56b79dd3471fdfddf783bac2f9a7e94033 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 20 Mar 2019 12:21:25 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20wipe=20domains=20when=20updatin?= =?UTF-8?q?g=20other=20attributes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The domains for an organisation should only be updated (or wiped) if a new list is explicitly passed in by the admin app. --- app/dao/organisation_dao.py | 2 +- tests/app/organisation/test_rest.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/dao/organisation_dao.py b/app/dao/organisation_dao.py index 26b6dca1f..c4c0b03e5 100644 --- a/app/dao/organisation_dao.py +++ b/app/dao/organisation_dao.py @@ -53,7 +53,7 @@ def dao_create_organisation(organisation): @transactional def dao_update_organisation(organisation_id, **kwargs): - domains = kwargs.pop('domains', []) + domains = kwargs.pop('domains', None) organisation = Organisation.query.filter_by(id=organisation_id).update( kwargs diff --git a/tests/app/organisation/test_rest.py b/tests/app/organisation/test_rest.py index d8cf2b704..e8569a48b 100644 --- a/tests/app/organisation/test_rest.py +++ b/tests/app/organisation/test_rest.py @@ -201,6 +201,29 @@ def test_post_update_organisation_updates_domains( ] == domain_list +def test_update_other_organisation_attributes_doesnt_clear_domains( + admin_request, + notify_db_session, +): + org = create_organisation(name='test_org_2') + create_domain('example.gov.uk', org.id) + + admin_request.post( + 'organisation.update_organisation', + _data={ + 'agreement_signed': True, + }, + organisation_id=org.id, + _expected_status=204 + ) + + assert [ + domain.domain for domain in org.domains + ] == [ + 'example.gov.uk' + ] + + def test_post_update_organisation_raises_400_on_existing_org_name( admin_request, sample_organisation): org = create_organisation()