Skip to content

Commit

Permalink
www.dashboard: validate pole_emploi_id in EditJobSeekerInfoForm
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Jun 6, 2024
1 parent 14eae4c commit 9158998
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions itou/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def _post_clean(self):
jobseeker_profile = JobSeekerProfile()
for k, v in self.cleaned_data_from_profile_fields.items():
setattr(jobseeker_profile, k, v)
# super()._post_clean() calls full_clean() on self.instance, which calls self.instance.clean_fields()
# Let's do the same on self.instance.jobseeker_profile (but only for our fields)
try:
jobseeker_profile.clean_fields(
exclude={f.name for f in JobSeekerProfile._meta.fields if f.name not in self.PROFILE_FIELDS}
)
except ValidationError as e:
self._update_errors(e)
try:
jobseeker_profile.validate_constraints()
except ValidationError as e:
Expand Down
11 changes: 11 additions & 0 deletions tests/www/dashboard/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,17 @@ def test_edit_with_invalid_pole_emploi_id(self):
None,
"Renseignez soit un identifiant France Travail (ex pôle emploi), soit la raison de son absence.",
)
post_data["pole_emploi_id"] = "invalide" # No length issue but validate_pole_emploi_id shouldn't be happy
response = self.client.post(url, data=post_data)
assert response.status_code == 200
self.assertFormError(
response.context["form"],
"pole_emploi_id",
(
"L'identifiant France Travail (ex pôle emploi) doit être composé de 8 caractères : "
"7 chiffres suivis d'une 1 lettre ou d'un chiffre."
),
)

def test_edit_as_prescriber(self):
user = PrescriberFactory()
Expand Down

0 comments on commit 9158998

Please sign in to comment.