From 5045d7f7ade0306ef3075bd3d306de333fcf89dc Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Tue, 2 Jul 2024 08:39:04 +0200 Subject: [PATCH] :white_check_mark: [#4246] Add tests for new machtiging structure --- .../haalcentraal_brp/tests/test_plugin.py | 51 +++++++++++++++++-- .../contrib/stufbg/tests/test_plugin.py | 27 +++++++++- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py index fb5999ff5d..9c589d40b3 100644 --- a/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py +++ b/src/openforms/prefill/contrib/haalcentraal_brp/tests/test_plugin.py @@ -134,7 +134,7 @@ def test_prefill_values_not_authenticated(self): self.assertEqual(values, {}) # type: ignore - def test_prefill_values_for_gemachtigde(self): + def test_prefill_values_for_gemachtigde_legacy_format(self): Attributes = get_attributes_cls() submission = SubmissionFactory.create( auth_info__value="111111111", @@ -157,6 +157,31 @@ def test_prefill_values_for_gemachtigde(self): }, ) # type: ignore + def test_prefill_values_for_gemachtigde_by_bsn(self): + Attributes = get_attributes_cls() + submission = SubmissionFactory.create( + auth_info__value="111111111", + auth_info__is_digid_machtigen=True, + auth_info__legal_subject_identifier_value="999990676", + auth_info__machtigen={}, # make sure legacy format is empty + ) + assert submission.is_authenticated + plugin = HaalCentraalPrefill(PLUGIN_IDENTIFIER) + + values = plugin.get_prefill_values( + submission, + attributes=[Attributes.naam_voornamen, Attributes.naam_geslachtsnaam], + identifier_role=IdentifierRoles.authorizee, + ) + + self.assertEqual( + values, + { + "naam.voornamen": "Cornelia Francisca", + "naam.geslachtsnaam": "Wiegman", + }, + ) # type: ignore + def test_person_not_found_returns_empty(self): Attributes = get_attributes_cls() submission = SubmissionFactory.create(auth_info__value="999990676") @@ -212,13 +237,21 @@ def test_person_not_found_returns_empty(self): ) super().test_person_not_found_returns_empty() - def test_prefill_values_for_gemachtigde(self): + def test_prefill_values_for_gemachtigde_legacy_format(self): + self.requests_mock.get( + "https://personen/api/ingeschrevenpersonen/999990676", + status_code=200, + json=load_json_mock("ingeschrevenpersonen.v1-full.json"), + ) + super().test_prefill_values_for_gemachtigde_legacy_format() + + def test_prefill_values_for_gemachtigde_by_bsn(self): self.requests_mock.get( "https://personen/api/ingeschrevenpersonen/999990676", status_code=200, json=load_json_mock("ingeschrevenpersonen.v1-full.json"), ) - super().test_prefill_values_for_gemachtigde() + super().test_prefill_values_for_gemachtigde_by_bsn() def test_pre_request_hooks_called(self): self.requests_mock.get( @@ -248,13 +281,21 @@ def test_person_not_found_returns_empty(self): ) super().test_person_not_found_returns_empty() - def test_prefill_values_for_gemachtigde(self): + def test_prefill_values_for_gemachtigde_legacy_format(self): + self.requests_mock.post( + "https://personen/api/personen", + status_code=200, + json=load_json_mock("ingeschrevenpersonen.v2-full.json"), + ) + super().test_prefill_values_for_gemachtigde_legacy_format() + + def test_prefill_values_for_gemachtigde_by_bsn(self): self.requests_mock.post( "https://personen/api/personen", status_code=200, json=load_json_mock("ingeschrevenpersonen.v2-full.json"), ) - super().test_prefill_values_for_gemachtigde() + super().test_prefill_values_for_gemachtigde_by_bsn() def test_pre_request_hooks_called(self): self.requests_mock.post( diff --git a/src/openforms/prefill/contrib/stufbg/tests/test_plugin.py b/src/openforms/prefill/contrib/stufbg/tests/test_plugin.py index fa3972ce4c..c6014a8d00 100644 --- a/src/openforms/prefill/contrib/stufbg/tests/test_plugin.py +++ b/src/openforms/prefill/contrib/stufbg/tests/test_plugin.py @@ -219,7 +219,7 @@ def test_prefill_values_not_authenticated(self): self.assertEqual(values, {}) - def test_get_available_attributes_for_gemachtigde(self): + def test_get_available_attributes_for_gemachtigde_legacy_format(self): client_patcher = mock_stufbg_client("StufBgResponse.xml") self.addCleanup(client_patcher.stop) attributes = [c.value for c in FieldChoices] @@ -242,6 +242,31 @@ def test_get_available_attributes_for_gemachtigde(self): self.assertEqual(values["postcode"], "1015 CJ") self.assertEqual(values["woonplaatsNaam"], "Amsterdam") + def test_prefill_values_for_gemachtigde_by_bsn(self): + client_patcher = mock_stufbg_client("StufBgResponse.xml") + self.addCleanup(client_patcher.stop) + attributes = [c.value for c in FieldChoices] + submission = SubmissionFactory.create( + auth_info__value="111111111", + auth_info__is_digid_machtigen=True, + auth_info__legal_subject_identifier_value="999990676", + auth_info__machtigen={}, # make sure legacy format is empty + ) + + values = self.plugin.get_prefill_values( + submission, attributes, IdentifierRoles.authorizee + ) + + self.assertEqual(values["bsn"], "999992314") + self.assertEqual(values["voornamen"], "Media") + self.assertEqual(values["geslachtsnaam"], "Maykin") + self.assertEqual(values["straatnaam"], "Keizersgracht") + self.assertEqual(values["huisnummer"], "117") + self.assertEqual(values["huisletter"], "A") + self.assertEqual(values["huisnummertoevoeging"], "B") + self.assertEqual(values["postcode"], "1015 CJ") + self.assertEqual(values["woonplaatsNaam"], "Amsterdam") + class StufBgCheckTests(TestCase): @classmethod