-
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.
[#964] Added first-last name validation
- Loading branch information
Showing
7 changed files
with
265 additions
and
7 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
56 changes: 56 additions & 0 deletions
56
src/open_inwoner/accounts/migrations/0052_auto_20221213_0758.py
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Generated by Django 3.2.15 on 2022-12-13 06:58 | ||
|
||
from django.db import migrations, models | ||
import open_inwoner.utils.validators | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("accounts", "0051_merge_20221207_0918"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="invite", | ||
name="invitee_first_name", | ||
field=models.CharField( | ||
help_text="The first name of the invitee.", | ||
max_length=250, | ||
validators=[open_inwoner.utils.validators.validate_charfield_entry], | ||
verbose_name="First name", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="invite", | ||
name="invitee_last_name", | ||
field=models.CharField( | ||
help_text="The last name of the invitee", | ||
max_length=250, | ||
validators=[open_inwoner.utils.validators.validate_charfield_entry], | ||
verbose_name="Last name", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="user", | ||
name="first_name", | ||
field=models.CharField( | ||
blank=True, | ||
default="", | ||
max_length=255, | ||
validators=[open_inwoner.utils.validators.validate_charfield_entry], | ||
verbose_name="First name", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="user", | ||
name="last_name", | ||
field=models.CharField( | ||
blank=True, | ||
default="", | ||
max_length=255, | ||
validators=[open_inwoner.utils.validators.validate_charfield_entry], | ||
verbose_name="Last name", | ||
), | ||
), | ||
] |
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 |
---|---|---|
|
@@ -62,6 +62,50 @@ def test_registration_fails_without_filling_out_last_name(self): | |
user_query = User.objects.filter(email=self.user.email) | ||
self.assertEqual(user_query.count(), 0) | ||
|
||
def test_registration_fails_with_invalid_first_name_characters(self): | ||
invalid_characters = "/\"\\,.:;'" | ||
|
||
for char in invalid_characters: | ||
with self.subTest(char=char): | ||
register_page = self.app.get(reverse("django_registration_register")) | ||
form = register_page.forms["registration-form"] | ||
form["email"] = self.user.email | ||
form["first_name"] = char | ||
form["last_name"] = self.user.last_name | ||
form["password1"] = self.user.password | ||
form["password2"] = self.user.password | ||
response = form.submit() | ||
expected_errors = { | ||
"first_name": [ | ||
_("Uw invoer bevat een ongeldig teken: {char}").format( | ||
char=char | ||
) | ||
] | ||
} | ||
self.assertEqual(response.context["form"].errors, expected_errors) | ||
|
||
def test_registration_fails_with_invalid_last_name_characters(self): | ||
invalid_characters = "/\"\\,.:;'" | ||
|
||
for char in invalid_characters: | ||
with self.subTest(char=char): | ||
register_page = self.app.get(reverse("django_registration_register")) | ||
form = register_page.forms["registration-form"] | ||
form["email"] = self.user.email | ||
form["first_name"] = self.user.first_name | ||
form["last_name"] = char | ||
form["password1"] = self.user.password | ||
form["password2"] = self.user.password | ||
response = form.submit() | ||
expected_errors = { | ||
"last_name": [ | ||
_("Uw invoer bevat een ongeldig teken: {char}").format( | ||
char=char | ||
) | ||
] | ||
} | ||
self.assertEqual(response.context["form"].errors, expected_errors) | ||
|
||
def test_registration_inactive_user(self): | ||
inactive_user = UserFactory.create(is_active=False) | ||
|
||
|
@@ -319,6 +363,58 @@ def test_submit_not_unique_email_different_case(self): | |
"* Een gebruiker met dit e-mailadres bestaat al", | ||
) | ||
|
||
def test_submit_invalid_first_name_chars_fails(self): | ||
UserFactory.create(email="[email protected]") | ||
user = UserFactory.create( | ||
first_name="", | ||
last_name="", | ||
login_type=LoginTypeChoices.digid, | ||
) | ||
invalid_characters = "/\"\\,.:;'" | ||
|
||
for char in invalid_characters: | ||
with self.subTest(char=char): | ||
get_response = self.app.get(self.url, user=user) | ||
form = get_response.forms["necessary-form"] | ||
form["email"] = "[email protected]" | ||
form["first_name"] = char | ||
form["last_name"] = "Smith" | ||
response = form.submit() | ||
expected_errors = { | ||
"first_name": [ | ||
_("Uw invoer bevat een ongeldig teken: {char}").format( | ||
char=char | ||
) | ||
] | ||
} | ||
self.assertEqual(response.context["form"].errors, expected_errors) | ||
|
||
def test_submit_invalid_last_name_chars_fails(self): | ||
UserFactory.create(email="[email protected]") | ||
user = UserFactory.create( | ||
first_name="", | ||
last_name="", | ||
login_type=LoginTypeChoices.digid, | ||
) | ||
invalid_characters = "/\"\\,.:;'" | ||
|
||
for char in invalid_characters: | ||
with self.subTest(char=char): | ||
get_response = self.app.get(self.url, user=user) | ||
form = get_response.forms["necessary-form"] | ||
form["email"] = "[email protected]" | ||
form["first_name"] = "John" | ||
form["last_name"] = char | ||
response = form.submit() | ||
expected_errors = { | ||
"last_name": [ | ||
_("Uw invoer bevat een ongeldig teken: {char}").format( | ||
char=char | ||
) | ||
] | ||
} | ||
self.assertEqual(response.context["form"].errors, expected_errors) | ||
|
||
|
||
class TestLoginLogoutFunctionality(WebTest): | ||
def setUp(self): | ||
|
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 |
---|---|---|
|
@@ -189,6 +189,46 @@ def test_adding_inactive_contact_fails(self): | |
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.context["form"].errors, expected_errors) | ||
|
||
def test_adding_contact_with_invalid_first_name_chars_fails(self): | ||
invalid_characters = "/\"\\,.:;'" | ||
|
||
for char in invalid_characters: | ||
with self.subTest(char=char): | ||
response = self.app.get(self.create_url, user=self.user) | ||
form = response.forms["contact-form"] | ||
form["first_name"] = char | ||
form["last_name"] = "Smith" | ||
form["email"] = "[email protected]" | ||
response = form.submit() | ||
expected_errors = { | ||
"first_name": [ | ||
_("Uw invoer bevat een ongeldig teken: {char}").format( | ||
char=char | ||
) | ||
] | ||
} | ||
self.assertEqual(response.context["form"].errors, expected_errors) | ||
|
||
def test_adding_contact_with_invalid_last_name_chars_fails(self): | ||
invalid_characters = "/\"\\,.:;'" | ||
|
||
for char in invalid_characters: | ||
with self.subTest(char=char): | ||
response = self.app.get(self.create_url, user=self.user) | ||
form = response.forms["contact-form"] | ||
form["first_name"] = "John" | ||
form["last_name"] = char | ||
form["email"] = "[email protected]" | ||
response = form.submit() | ||
expected_errors = { | ||
"last_name": [ | ||
_("Uw invoer bevat een ongeldig teken: {char}").format( | ||
char=char | ||
) | ||
] | ||
} | ||
self.assertEqual(response.context["form"].errors, expected_errors) | ||
|
||
def test_email_required(self): | ||
response = self.app.get(self.create_url, user=self.user) | ||
form = response.forms["contact-form"] | ||
|
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