-
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.
- Loading branch information
Showing
7 changed files
with
93 additions
and
79 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
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 |
---|---|---|
|
@@ -541,52 +541,78 @@ def test_modify_phone_and_email_updates_klant_api(self, m): | |
) | ||
|
||
@requests_mock.Mocker() | ||
def test_eherkenning_user_updates_klant_api(self, m): | ||
def test_eherkenning_user_updates_klant_api_with_rsin(self, m): | ||
MockAPIReadPatchData.setUpServices() | ||
data = MockAPIReadPatchData() | ||
|
||
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" | ||
) | ||
matchers = data.install_mocks_eherkenning(m, use_rsin=True).matchers | ||
|
||
config = OpenKlantConfig.get_solo() | ||
config.use_rsin_for_innNnpId_query_parameter = True | ||
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(matchers[0].called) | ||
klant_patch_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_eherkenning_user_updates_klant_api_with_kvk(self, m): | ||
MockAPIReadPatchData.setUpServices() | ||
data = MockAPIReadPatchData() | ||
|
||
matchers = data.install_mocks_eherkenning(m, use_rsin=False).matchers | ||
|
||
config = OpenKlantConfig.get_solo() | ||
config.use_rsin_for_innNnpId_query_parameter = False | ||
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(matchers[0].called) | ||
klant_patch_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): | ||
|
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 |
---|---|---|
@@ -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="[email protected]").delete() | ||
self.user = DigidUserFactory( | ||
email="[email protected]", | ||
phonenumber="0100000000", | ||
) | ||
|
||
User.objects.filter(kvk="12345678").delete() | ||
self.eherkenning_user = eHerkenningUserFactory( | ||
email="[email protected]", | ||
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="[email protected]", | ||
) | ||
|
||
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", | ||
|
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