Skip to content

Commit

Permalink
temporary commit: corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenKorr committed Sep 24, 2024
1 parent 3629e7c commit 3bfe425
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 46 deletions.
5 changes: 1 addition & 4 deletions itou/common_apps/nir/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ def __init__(self, *args, editor=None, tally_form_query=None, **kwargs):
"veuillez décocher la case “Impossible de renseigner le numéro de sécurité sociale”."
)

# Using to_python() for when the field `lack_of_nir` is a forms.HiddenInput():
# it results in a hidden input of value="False", which is True in Python,
# we need to translate it
if self["lack_of_nir"].field.to_python(self["lack_of_nir"].value()):
if self["lack_of_nir"].value():
self.fields["nir"].disabled = True
# Make sure the collapse state is consistent
self.fields["lack_of_nir"].widget.attrs["aria-expanded"] = "true"
Expand Down
55 changes: 36 additions & 19 deletions itou/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,14 @@ class JobSeekerProfile(models.Model):
ERROR_JOBSEEKER_TITLE = "La civilité du demandeur d'emploi est obligatoire"
ERROR_JOBSEEKER_EDUCATION_LEVEL = "Le niveau de formation du demandeur d'emploi est obligatoire"
ERROR_JOBSEEKER_PE_FIELDS = "L'identifiant et la durée d'inscription à France Travail vont de pair"
ERROR_JOBSEEKER_INCONSISTENT_NIR = (
"Une incohérence a été détectée parmi les informations suivantes : "
"la civilité, le numéro de sécurité sociale et la date de naissance. "
"Veuillez corriger celle(s) en erreur pour continuer."
ERROR_JOBSEEKER_INCONSISTENT_NIR_TITLE = (
"La civilité ne correspond pas au numéro de sécurité sociale "
"(premier chiffre = 1 pour un Monsieur, 2 pour Madame)."
)
ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE = (
"La date de naissance ne correspond pas au numéro de sécurité sociale "
"(dont le format est 1AAMMDDXXXYYYCC, où AA est l’année de naissance "
"et MM le mois de naissance)."
)

user = models.OneToOneField(
Expand Down Expand Up @@ -1079,24 +1083,37 @@ def clean_pole_emploi_fields(cleaned_data):
cleaned_data["lack_of_pole_emploi_id_reason"] = ""

@staticmethod
def clean_nir_title_birthdate_fields(cleaned_data):
def clean_nir_title_birthdate_fields(cleaned_data, remind_nir_in_error=False):
"""
Validate consistency between NIR, title and birthdate
"""
if "nir" not in cleaned_data or len(cleaned_data["nir"]) == 0:
return
if "title" in cleaned_data:
if (cleaned_data["nir"][0] == "1" and cleaned_data["title"] != "M") or (
cleaned_data["nir"][0] == "2" and cleaned_data["title"] != "MME"
):
raise ValidationError(JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR)
if "birthdate" in cleaned_data:
nir_year = cleaned_data["nir"][1:3]
nir_month = cleaned_data["nir"][3:5]
birthdate_year = cleaned_data["birthdate"].strftime("%y")
birthdate_month = cleaned_data["birthdate"].strftime("%m")
if nir_year != birthdate_year or nir_month != birthdate_month:
raise ValidationError(JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR)
if cleaned_nir := cleaned_data.get("nir"):
if cleaned_title := cleaned_data.get("title"):
if (cleaned_nir[0] == "1" and cleaned_title != Title.M) or (
cleaned_nir[0] == "2" and cleaned_title != Title.MME
):
raise ValidationError(
JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_TITLE
+ (
f" Le numéro de sécurité social enregistré est {cleaned_nir}."
if remind_nir_in_error
else ""
)
)
if cleaned_birthdate := cleaned_data.get("birthdate"):
nir_year = cleaned_nir[1:3]
nir_month = cleaned_nir[3:5]
birthdate_year = cleaned_birthdate.strftime("%y")
birthdate_month = cleaned_birthdate.strftime("%m")
if nir_year != birthdate_year or nir_month != birthdate_month:
raise ValidationError(
JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE
+ (
f" Le numéro de sécurité social enregistré est {cleaned_nir}."
if remind_nir_in_error
else ""
)
)

def _clean_job_seeker_details(self):
# Title is not mandatory for User, but it is for ASP
Expand Down
2 changes: 1 addition & 1 deletion itou/www/apply/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def clean(self):
super().clean()
JobSeekerProfile.clean_pole_emploi_fields(self.cleaned_data)
JobSeekerProfile.clean_nir_title_birthdate_fields(
self.cleaned_data | {"nir": self.instance.jobseeker_profile.nir}
self.cleaned_data | {"nir": self.instance.jobseeker_profile.nir}, remind_nir_in_error=True
)


Expand Down
2 changes: 1 addition & 1 deletion tests/users/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class Params:

@factory.lazy_attribute
def nir(self):
gender = "1" if self.user.title == "M" else "2"
gender = "1" if self.user.title == Title.M else "2"
if self.birthdate:
year = self.birthdate.strftime("%y")
month = self.birthdate.strftime("%m")
Expand Down
31 changes: 15 additions & 16 deletions tests/www/apply/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from itou.job_applications.models import JobApplication
from itou.siae_evaluations.models import Sanctions
from itou.users.enums import LackOfNIRReason, LackOfPoleEmploiId
from itou.users.models import User
from itou.users.models import JobSeekerProfile, User
from itou.utils.mocks.address_format import mock_get_first_geocoding_data, mock_get_geocoding_data_by_ban_api_resolved
from itou.utils.models import InclusiveDateRange
from itou.utils.session import SessionNamespace
Expand Down Expand Up @@ -57,11 +57,6 @@


BACK_BUTTON_ARIA_LABEL = "Retourner à l’étape précédente"
ERROR_INCONSISTENT_NIR = (
"Une incohérence a été détectée parmi les informations suivantes : "
"la civilité, le numéro de sécurité sociale et la date de naissance. "
"Veuillez corriger celle(s) en erreur pour continuer."
)


class ApplyTest(TestCase):
Expand Down Expand Up @@ -1476,7 +1471,7 @@ def test_apply_as_prescriber(self, _mock):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_TITLE)

post_data = {
"title": "M",
Expand All @@ -1488,7 +1483,7 @@ def test_apply_as_prescriber(self, _mock):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE)

# Resume to valid data and proceed with "normal" flow.
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -1715,7 +1710,11 @@ def test_check_info_as_prescriber_for_job_seeker_with_incomplete_info(self):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(
response,
JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE
+ " Le numéro de sécurité social enregistré est 178122978200508.",
)


@pytest.mark.ignore_unknown_variable_template_error("job_seeker")
Expand Down Expand Up @@ -1995,7 +1994,7 @@ def _test_apply_as_company(self, user, company, dummy_job_seeker, _mock):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_TITLE)

post_data = {
"title": "MME",
Expand All @@ -2007,7 +2006,7 @@ def _test_apply_as_company(self, user, company, dummy_job_seeker, _mock):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE)

# Resume to valid data and proceed with "normal" flow.
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -2241,7 +2240,7 @@ def test_check_info_as_employer_for_job_seeker_with_incomplete_info(self):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE)

@pytest.mark.ignore_unknown_variable_template_error("job_seeker")
def test_cannot_create_job_seeker_with_pole_emploi_email(self):
Expand Down Expand Up @@ -2410,7 +2409,7 @@ def test_hire_as_company(self, _mock):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_TITLE)

post_data = {
"title": "M",
Expand All @@ -2422,7 +2421,7 @@ def test_hire_as_company(self, _mock):
}
response = self.client.post(next_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE)

# Resume to valid data and proceed with "normal" flow.
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -3180,7 +3179,7 @@ def _check_everything_allowed(self, user, extra_post_data_1=None):
}
response = self.client.post(self.step_1_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_TITLE)

post_data = {
"title": "M",
Expand All @@ -3192,7 +3191,7 @@ def _check_everything_allowed(self, user, extra_post_data_1=None):
}
response = self.client.post(self.step_1_url, data=post_data)
assert response.status_code == 200
self.assertContains(response, ERROR_INCONSISTENT_NIR)
self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE)

# Resume to valid data and proceed with "normal" flow.
# ----------------------------------------------------------------------
Expand Down
8 changes: 3 additions & 5 deletions tests/www/dashboard/test_edit_user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from itou.cities.models import City
from itou.users.enums import IdentityProvider, LackOfNIRReason, LackOfPoleEmploiId, Title
from itou.users.models import User
from itou.users.models import JobSeekerProfile, User
from itou.utils.mocks.address_format import mock_get_geocoding_data_by_ban_api_resolved
from tests.openid_connect.inclusion_connect.test import (
InclusionConnectBaseTestCase,
Expand Down Expand Up @@ -172,8 +172,7 @@ def test_inconsistent_nir_title_birthdate(self):
response = self.client.post(url, data=post_data)

assert response.status_code == 200
self.assertContains(response, self.ERROR_INCONSISTENT_NIR)

self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_TITLE)
user = User.objects.get(id=user.id)

# Ensure that the job seeker did not change the title.
Expand All @@ -193,8 +192,7 @@ def test_inconsistent_nir_title_birthdate(self):
response = self.client.post(url, data=post_data)

assert response.status_code == 200
self.assertContains(response, self.ERROR_INCONSISTENT_NIR)

self.assertContains(response, JobSeekerProfile.ERROR_JOBSEEKER_INCONSISTENT_NIR_BIRTHDATE)
user = User.objects.get(id=user.id)

# Ensure that the job seeker did not change the birthdate.
Expand Down

0 comments on commit 3bfe425

Please sign in to comment.