Skip to content

Commit

Permalink
feat(validation): add tests to signup form
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisig committed Sep 30, 2024
1 parent cdc752f commit ccc45e6
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 103 deletions.
103 changes: 0 additions & 103 deletions project/tests/tests.py

This file was deleted.

64 changes: 64 additions & 0 deletions users/tests/SignupTest.py
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 added users/tests/__init__.py
Empty file.
170 changes: 170 additions & 0 deletions users/tests/parameters.json
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
}
}
]

0 comments on commit ccc45e6

Please sign in to comment.