-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validation): add tests to signup form
- Loading branch information
Showing
4 changed files
with
234 additions
and
103 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,64 @@ | ||
from django.test import TestCase | ||
|
||
valid_payload = { | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
"email": "[email protected]", | ||
"organism": "Test", | ||
"function": "Test", | ||
"password1": "password", | ||
"password2": "password", | ||
} | ||
|
||
form_url = "/users/signup/" | ||
|
||
|
||
class SignupTest(TestCase): | ||
fixtures = ["users/tests/parameters.json"] | ||
|
||
def test_signup_form_with_working_payload(self) -> None: | ||
response = self.client.post(path=form_url, data=valid_payload) | ||
self.assertFormError( | ||
response=response, | ||
form="form", | ||
field=None, | ||
errors=[], | ||
) | ||
|
||
def test_signup_form_with_html_in_payload(self) -> None: | ||
fields_to_test = { | ||
"first_name": "<h1>John</h1>", | ||
"last_name": "<h1>Doe</h1>", | ||
"function": "<h1>Test</h1>", | ||
} | ||
|
||
for field, value in fields_to_test.items(): | ||
with self.subTest(field=field): | ||
data = {**valid_payload, field: value} | ||
response = self.client.post(path=form_url, data=data) | ||
self.assertFormError( | ||
response=response, | ||
form="form", | ||
field=field, | ||
errors="Le champ ne doit contenir que des lettres, des espaces ou des tirets.", | ||
) | ||
|
||
def test_signup_form_with_invalid_email(self) -> None: | ||
data = {**valid_payload, "email": "john.doe"} | ||
response = self.client.post(path=form_url, data=data) | ||
self.assertFormError( | ||
response=response, | ||
form="form", | ||
field="email", | ||
errors="Saisissez une adresse e-mail valide.", | ||
) | ||
|
||
def test_signup_form_with_different_passwords(self) -> None: | ||
data = {**valid_payload, "password2": "password2"} | ||
response = self.client.post(path=form_url, data=data) | ||
self.assertFormError( | ||
response=response, | ||
form="form", | ||
field="password2", | ||
errors="Les mots de passe ne sont pas identiques", | ||
) |
Empty file.
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,170 @@ | ||
[ | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 1, | ||
"fields": { | ||
"name": "Adresse e-mail de l'équipe", | ||
"slug": "TEAM_EMAIL", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "[email protected]", | ||
"is_global": false | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 2, | ||
"fields": { | ||
"name": "Exemple de bilan", | ||
"slug": "BILAN_EXAMPLE", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "https://drive.google.com/file/d/11tnGnZDTyJy61f2f796kMak1dV250zHX/view?usp=sharing", | ||
"is_global": false | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 3, | ||
"fields": { | ||
"name": "Titre lien téléchargement du bilan", | ||
"slug": "BILAN_EXAMPLE_TITLE", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "bilan d'Andernos-les-bains", | ||
"is_global": true | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 4, | ||
"fields": { | ||
"name": "Budget consommé", | ||
"slug": "BUDGET_CONSOMME", | ||
"value_type": "INT", | ||
"description": "", | ||
"value": "14100", | ||
"is_global": true | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 5, | ||
"fields": { | ||
"name": "Date de mise à jour du budget conso", | ||
"slug": "BUDGET_DATE", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "1er juin 2022", | ||
"is_global": true | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 6, | ||
"fields": { | ||
"name": "Lien vers la documentation externe", | ||
"slug": "EXTERNAL_DOC", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "https://fabrique-numerique.gitbook.io/sparte/", | ||
"is_global": true | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 7, | ||
"fields": { | ||
"name": "Téléphone de contact", | ||
"slug": "PHONE_CONTACT", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "+33 6 07 33 56 19", | ||
"is_global": false | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 8, | ||
"fields": { | ||
"name": "URL vers métabase", | ||
"slug": "METABASE_URL", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "https://sparte-metabase.osc-secnum-fr1.scalingo.io/", | ||
"is_global": true | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 9, | ||
"fields": { | ||
"name": "Hauteur de l'iframe des statistiques (px)", | ||
"slug": "STATS_HEIGHT", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "1300", | ||
"is_global": false | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 10, | ||
"fields": { | ||
"name": "URL de l'iframe des statistiques (px)", | ||
"slug": "STATS_URL", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "http://sparte-metabase.osc-secnum-fr1.scalingo.io/public/dashboard/67c2adfb-b21d-4d53-bd88-2be2186eccd6", | ||
"is_global": false | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 11, | ||
"fields": { | ||
"name": "Mise en maintenance du site", | ||
"slug": "MAINTENANCE_MODE", | ||
"value_type": "BOO", | ||
"description": "", | ||
"value": "0", | ||
"is_global": false | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 12, | ||
"fields": { | ||
"name": "Envoyer une alerte lorsqu'un diag est dl.", | ||
"slug": "ALERTE_ON_DIAG_DL", | ||
"value_type": "BOO", | ||
"description": "", | ||
"value": "0", | ||
"is_global": false | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 13, | ||
"fields": { | ||
"name": "URL vers le formulaire d'inscription aux webinaires", | ||
"slug": "JOTFORM_URL", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "https://form.jotform.com/231703451991355", | ||
"is_global": true | ||
} | ||
}, | ||
{ | ||
"model": "django_app_parameter.parameter", | ||
"pk": 14, | ||
"fields": { | ||
"name": "URL vers la faq Crisp", | ||
"slug": "FAQ_URL", | ||
"value_type": "STR", | ||
"description": "", | ||
"value": "https://faq.mondiagartif.beta.gouv.fr/", | ||
"is_global": true | ||
} | ||
} | ||
] |