Skip to content

Commit

Permalink
[#1052] Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Jan 18, 2023
1 parent ee8f988 commit 88172a4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/open_inwoner/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ def __init__(self, user, *args, **kwargs):
super().__init__(*args, **kwargs)

if user.login_type == LoginTypeChoices.digid:
self.fields["first_name"].disabled = True
self.fields["last_name"].disabled = True
self.fields["birthday"].disabled = True
self.fields["street"].disabled = True
self.fields["housenumber"].disabled = True
self.fields["postcode"].disabled = True
self.fields["city"].disabled = True
disabled_fields = (
"first_name",
"last_name",
"birthday",
"street",
"housenumber",
"postcode",
"city",
)
for field in disabled_fields:
self.fields[field].disabled = True


class NecessaryUserForm(forms.ModelForm):
Expand Down
34 changes: 34 additions & 0 deletions src/open_inwoner/accounts/tests/test_profile_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,40 @@ def test_updating_a_field_without_modifying_email_succeeds(self):
self.assertEqual(self.user.email, initial_email)
self.assertEqual(self.user.first_name, "Testing")

def test_form_for_digid__user_saves_only_non_disabled_fields(self):
user = UserFactory(
bsn="999993847",
first_name="name",
last_name="surname",
login_type=LoginTypeChoices.digid,
)
response = self.app.get(self.url, user=user)
form = response.forms["profile-edit"]

form["first_name"] = "First name"
form["last_name"] = "Last name"
form["email"] = "[email protected]"
form["phonenumber"] = "06987878787"
form["birthday"] = "21-01-1992"
form["street"] = "Keizersgracht"
form["housenumber"] = "17 d"
form["postcode"] = "1013 RM"
form["city"] = "Amsterdam"
response = form.submit()

self.assertEqual(response.url, self.return_url)

user.refresh_from_db()

self.assertEqual(user.first_name, "name")
self.assertEqual(user.last_name, "surname")
self.assertEqual(user.email, "[email protected]")
self.assertIsNone(user.birthday)
self.assertEqual(user.street, "")
self.assertEqual(user.housenumber, "")
self.assertIsNone(user.postcode, "")
self.assertEqual(user.city, "")


@requests_mock.Mocker()
class MyDataTests(HaalCentraalMixin, WebTest):
Expand Down

0 comments on commit 88172a4

Please sign in to comment.