-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [#1957] Add/fix tests for klant resources for companies
- Loading branch information
Showing
5 changed files
with
257 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
from open_inwoner.accounts.choices import StatusChoices | ||
from open_inwoner.cms.profile.cms_appconfig import ProfileConfig | ||
from open_inwoner.haalcentraal.tests.mixins import HaalCentraalMixin | ||
from open_inwoner.openklant.models import OpenKlantConfig | ||
from open_inwoner.pdc.tests.factories import CategoryFactory | ||
from open_inwoner.plans.tests.factories import PlanFactory | ||
from open_inwoner.utils.logentry import LOG_ACTIONS | ||
|
@@ -281,7 +282,9 @@ def test_messages_enabled_disabled(self): | |
self.assertEqual(link_text(), _("Stuur een bericht")) | ||
|
||
|
||
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") | ||
@override_settings( | ||
ROOT_URLCONF="open_inwoner.cms.tests.urls", MIDDLEWARE=PATCHED_MIDDLEWARE | ||
) | ||
class EditProfileTests(AssertTimelineLogMixin, WebTest): | ||
def setUp(self): | ||
self.url = reverse("profile:edit") | ||
|
@@ -530,11 +533,59 @@ def test_modify_phone_and_email_updates_klant_api(self, m): | |
"telefoonnummer": "0612345678", | ||
}, | ||
) | ||
self.assertTimelineLog("retrieved klant for BSN-user") | ||
self.assertTimelineLog("retrieved klant for user") | ||
self.assertTimelineLog( | ||
"patched klant from user profile edit with fields: emailadres, telefoonnummer" | ||
) | ||
|
||
@requests_mock.Mocker() | ||
def test_eherkenning_user_updates_klant_api(self, m): | ||
MockAPIReadPatchData.setUpServices() | ||
|
||
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 | ||
): | ||
# NOTE Explicitly creating a new Mocker object here, because for some reason | ||
# `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( | ||
m, use_rsin=use_rsin_for_innNnpId_query_parameter | ||
) | ||
|
||
config = OpenKlantConfig.get_solo() | ||
config.use_rsin_for_innNnpId_query_parameter = ( | ||
use_rsin_for_innNnpId_query_parameter | ||
) | ||
config.save() | ||
|
||
response = self.app.get(self.url, user=data.eherkenning_user) | ||
|
||
# reset noise from signals | ||
m.reset_mock() | ||
self.clearTimelineLogs() | ||
|
||
form = response.forms["profile-edit"] | ||
form["email"] = "[email protected]" | ||
form["phonenumber"] = "0612345678" | ||
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.assertEqual( | ||
klant_patch_data, | ||
{ | ||
"emailadres": "[email protected]", | ||
"telefoonnummer": "0612345678", | ||
}, | ||
) | ||
self.assertTimelineLog("retrieved klant for user") | ||
self.assertTimelineLog( | ||
"patched klant from user profile edit with fields: emailadres, telefoonnummer" | ||
) | ||
|
||
@requests_mock.Mocker() | ||
def test_modify_phone_updates_klant_api_but_skips_unchanged(self, m): | ||
MockAPIReadPatchData.setUpServices() | ||
|
@@ -579,7 +630,7 @@ def test_modify_phone_updates_klant_api_but_skip_unchanged_email(self, m): | |
"telefoonnummer": "0612345678", | ||
}, | ||
) | ||
self.assertTimelineLog("retrieved klant for BSN-user") | ||
self.assertTimelineLog("retrieved klant for user") | ||
self.assertTimelineLog( | ||
"patched klant from user profile edit with fields: telefoonnummer" | ||
) | ||
|
@@ -609,7 +660,7 @@ def test_modify_phone_updates_klant_api_but_skip_unchanged_phone(self, m): | |
"emailadres": "[email protected]", | ||
}, | ||
) | ||
self.assertTimelineLog("retrieved klant for BSN-user") | ||
self.assertTimelineLog("retrieved klant for user") | ||
self.assertTimelineLog( | ||
"patched klant from user profile edit with fields: emailadres" | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,11 @@ def __init__(self): | |
email="[email protected]", | ||
phonenumber="0100000000", | ||
) | ||
self.eherkenning_user = eHerkenningUserFactory( | ||
email="[email protected]", | ||
kvk="12345678", | ||
rsin="000000000", | ||
) | ||
|
||
self.klant_old = generate_oas_component( | ||
"kc", | ||
|
@@ -71,6 +76,28 @@ def install_mocks(self, m) -> "MockAPIReadPatchData": | |
] | ||
return self | ||
|
||
def install_mocks_eherkenning(self, m, use_rsin=True) -> "MockAPIReadPatchData": | ||
self.setUpOASMocks(m) | ||
if use_rsin: | ||
first_eherkenning_matcher = m.get( | ||
f"{KLANTEN_ROOT}klanten?subjectNietNatuurlijkPersoon__innNnpId={self.eherkenning_user.rsin}", | ||
json=paginated_response([self.klant_old]), | ||
) | ||
else: | ||
first_eherkenning_matcher = m.get( | ||
f"{KLANTEN_ROOT}klanten?subjectNietNatuurlijkPersoon__innNnpId={self.eherkenning_user.kvk}", | ||
json=paginated_response([self.klant_old]), | ||
) | ||
self.matchers = [ | ||
first_eherkenning_matcher, | ||
m.patch( | ||
f"{KLANTEN_ROOT}klant/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", | ||
json=self.klant_updated, | ||
status_code=200, | ||
), | ||
] | ||
return self | ||
|
||
|
||
class MockAPIReadData(MockAPIData): | ||
def __init__(self): | ||
|
Oops, something went wrong.