From 8f3f2712f6d8942f01aa343cbeb8af7f9c92d0b3 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Fri, 15 Mar 2024 09:41:28 +0100 Subject: [PATCH] :ok_hand: [#2041] PR feedback --- src/open_inwoner/accounts/models.py | 8 +++----- .../accounts/tests/test_profile_views.py | 15 +++++++++++---- .../cms/cases/tests/test_contactform.py | 14 +++++--------- src/open_inwoner/openklant/tests/data.py | 9 ++------- .../openklant/tests/test_contactform.py | 8 ++++++-- src/open_inwoner/openklant/tests/test_views.py | 7 +++---- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/open_inwoner/accounts/models.py b/src/open_inwoner/accounts/models.py index bb8d62528a..cdd1ca920b 100644 --- a/src/open_inwoner/accounts/models.py +++ b/src/open_inwoner/accounts/models.py @@ -278,11 +278,9 @@ class Meta: | Q(login_type=LoginTypeChoices.eherkenning), name="check_kvk_or_rsin_only_set_when_login_eherkenning", ), - # CheckConstraint( - # check=((Q(kvk="") & ~Q(rsin="")) | (~Q(kvk="") & Q(rsin=""))) - # | ~Q(login_type=LoginTypeChoices.eherkenning), - # name="check_kvk_or_rsin_exclusive_when_login_eherkenning", - # ), + # NOTE: we do not need a constraint that enforces exclusivity between + # `KVK` and `RSIN`, because companies have both of these attributes and we + # need both of them to fetch cases for these companies ] def __init__(self, *args, **kwargs): diff --git a/src/open_inwoner/accounts/tests/test_profile_views.py b/src/open_inwoner/accounts/tests/test_profile_views.py index f64dcb5d9d..36e6cdd1d4 100644 --- a/src/open_inwoner/accounts/tests/test_profile_views.py +++ b/src/open_inwoner/accounts/tests/test_profile_views.py @@ -540,6 +540,8 @@ def test_modify_phone_and_email_updates_klant_api(self, m): @requests_mock.Mocker() def test_eherkenning_user_updates_klant_api(self, m): MockAPIReadPatchData.setUpServices() + data = MockAPIReadPatchData() + original_email = data.eherkenning_user.email for use_rsin_for_innNnpId_query_parameter in [True, False]: with self.subTest( @@ -549,9 +551,14 @@ def test_eherkenning_user_updates_klant_api(self, m): # `m` is overridden somewhere, which causes issues when `MockAPIReadPatchData.install_mocks` # is run for the second time with requests_mock.Mocker() as m: - data = MockAPIReadPatchData().install_mocks_eherkenning( + # Reset the email, otherwise we get errors that a user already exists + # with the updated email + data.eherkenning_user.email = original_email + data.eherkenning_user.save() + + matchers = data.install_mocks_eherkenning( m, use_rsin=use_rsin_for_innNnpId_query_parameter - ) + ).matchers config = OpenKlantConfig.get_solo() config.use_rsin_for_innNnpId_query_parameter = ( @@ -571,8 +578,8 @@ def test_eherkenning_user_updates_klant_api(self, m): form.submit() # user data tested in other cases - self.assertTrue(data.matchers[0].called) - klant_patch_data = data.matchers[1].request_history[0].json() + self.assertTrue(matchers[0].called) + klant_patch_data = matchers[1].request_history[0].json() self.assertEqual( klant_patch_data, { diff --git a/src/open_inwoner/cms/cases/tests/test_contactform.py b/src/open_inwoner/cms/cases/tests/test_contactform.py index 314f51f3d6..e64da721c8 100644 --- a/src/open_inwoner/cms/cases/tests/test_contactform.py +++ b/src/open_inwoner/cms/cases/tests/test_contactform.py @@ -13,7 +13,6 @@ ) from zgw_consumers.constants import APITypes -from open_inwoner.accounts.models import User from open_inwoner.accounts.tests.factories import ( DigidUserFactory, eHerkenningUserFactory, @@ -438,18 +437,15 @@ def test_form_success_with_api(self, m): def test_form_success_with_api_eherkenning_user(self, m): self._setUpMocks(m) self._setUpExtraMocks(m) - + eherkenning_user = eHerkenningUserFactory.create( + kvk="12345678", + rsin="000000000", + email=self.klant["emailadres"], + ) for use_rsin_for_innNnpId_query_parameter in [True, False]: with self.subTest( use_rsin_for_innNnpId_query_parameter=use_rsin_for_innNnpId_query_parameter ): - # FIXME for some reason creating the user outside of the loop - # makes the second iteration fail? - User.objects.filter(kvk="12345678").delete() - eherkenning_user = eHerkenningUserFactory( - kvk="12345678", rsin="000000000" - ) - config = OpenKlantConfig.get_solo() config.use_rsin_for_innNnpId_query_parameter = ( use_rsin_for_innNnpId_query_parameter diff --git a/src/open_inwoner/openklant/tests/data.py b/src/open_inwoner/openklant/tests/data.py index f79e3ee940..2dcf381f37 100644 --- a/src/open_inwoner/openklant/tests/data.py +++ b/src/open_inwoner/openklant/tests/data.py @@ -1,7 +1,6 @@ from requests.exceptions import RequestException from zgw_consumers.constants import APITypes -from open_inwoner.accounts.models import User from open_inwoner.accounts.tests.factories import ( DigidUserFactory, eHerkenningUserFactory, @@ -39,13 +38,11 @@ def setUpServices(cls): class MockAPIReadPatchData(MockAPIData): def __init__(self): - User.objects.filter(email="old@example.com").delete() self.user = DigidUserFactory( email="old@example.com", phonenumber="0100000000", ) - User.objects.filter(kvk="12345678").delete() self.eherkenning_user = eHerkenningUserFactory( email="old2@example.com", kvk="12345678", @@ -107,14 +104,14 @@ def install_mocks_eherkenning(self, m, use_rsin=True) -> "MockAPIReadPatchData": class MockAPIReadData(MockAPIData): def __init__(self): - User.objects.filter(bsn="100000001").delete() self.user = DigidUserFactory( bsn="100000001", ) - User.objects.filter(kvk="12345678").delete() + self.eherkenning_user = eHerkenningUserFactory( kvk="12345678", rsin="000000000", + email="foo@bar.com", ) self.klant = generate_oas_component_cached( @@ -310,11 +307,9 @@ def install_mocks(self, m, link_objectcontactmomenten=False) -> "MockAPIReadData class MockAPICreateData(MockAPIData): def __init__(self): - User.objects.filter(bsn="100000001").delete() self.user = DigidUserFactory( bsn="100000001", ) - User.objects.filter(kvk="12345678").delete() self.eherkenning_user = eHerkenningUserFactory( kvk="12345678", rsin="000000000", diff --git a/src/open_inwoner/openklant/tests/test_contactform.py b/src/open_inwoner/openklant/tests/test_contactform.py index 432aa274a8..967a7a08db 100644 --- a/src/open_inwoner/openklant/tests/test_contactform.py +++ b/src/open_inwoner/openklant/tests/test_contactform.py @@ -435,6 +435,8 @@ def test_submit_and_register_bsn_user_via_api(self, m): def test_submit_and_register_kvk_or_rsin_user_via_api(self, _m): MockAPICreateData.setUpServices() + data = MockAPICreateData() + original_phonenumber = data.eherkenning_user.phonenumber config = OpenKlantConfig.get_solo() config.register_contact_moment = True @@ -456,7 +458,9 @@ def test_submit_and_register_kvk_or_rsin_user_via_api(self, _m): ) config.save() - data = MockAPICreateData() + data.eherkenning_user.phonenumber = original_phonenumber + data.eherkenning_user.save() + data.install_mocks_eherkenning( m, use_rsin=use_rsin_for_innNnpId_query_parameter ) @@ -604,6 +608,7 @@ def test_submit_and_register_bsn_user_via_api_and_update_klant(self, m): def test_submit_and_register_kvk_or_rsin_user_via_api_and_update_klant(self, _m): MockAPICreateData.setUpServices() + data = MockAPICreateData() config = OpenKlantConfig.get_solo() config.register_contact_moment = True @@ -625,7 +630,6 @@ def test_submit_and_register_kvk_or_rsin_user_via_api_and_update_klant(self, _m) ) config.save() - data = MockAPICreateData() data.install_mocks_eherkenning_missing_contact_info( m, use_rsin=use_rsin_for_innNnpId_query_parameter ) diff --git a/src/open_inwoner/openklant/tests/test_views.py b/src/open_inwoner/openklant/tests/test_views.py index f4130af5d9..282bea1b73 100644 --- a/src/open_inwoner/openklant/tests/test_views.py +++ b/src/open_inwoner/openklant/tests/test_views.py @@ -73,6 +73,8 @@ def test_list_for_bsn(self, m): self.assertEqual(status_item.text(), f"{_('Status')}\n{_('Afgehandeld')}") def test_list_for_kvk_or_rsin(self, m): + data = MockAPIReadData().install_mocks(m) + for use_rsin_for_innNnpId_query_parameter in [True, False]: with self.subTest( use_rsin_for_innNnpId_query_parameter=use_rsin_for_innNnpId_query_parameter @@ -83,8 +85,6 @@ def test_list_for_kvk_or_rsin(self, m): ) config.save() - data = MockAPIReadData().install_mocks(m) - detail_url = reverse( "cases:contactmoment_detail", kwargs={"kcm_uuid": data.klant_contactmoment2["uuid"]}, @@ -274,6 +274,7 @@ def test_show_detail_for_bsn_with_zaak_reformat_esuite_id(self, m): ) def test_show_detail_for_kvk_or_rsin(self, m): + data = MockAPIReadData().install_mocks(m) for use_rsin_for_innNnpId_query_parameter in [True, False]: with self.subTest( use_rsin_for_innNnpId_query_parameter=use_rsin_for_innNnpId_query_parameter @@ -284,8 +285,6 @@ def test_show_detail_for_kvk_or_rsin(self, m): ) config.save() - data = MockAPIReadData().install_mocks(m) - detail_url = reverse( "cases:contactmoment_detail", kwargs={"kcm_uuid": data.klant_contactmoment2["uuid"]},