Skip to content

Commit

Permalink
apply: block hiring in more than 6 months
Browse files Browse the repository at this point in the history
  • Loading branch information
tonial committed Jul 16, 2024
1 parent b775080 commit f957930
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions itou/job_applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ class JobApplication(xwf_models.WorkflowEnabled, models.Model):
MAX_CONTRACT_POSTPONE_IN_DAYS = 30

ERROR_START_IN_PAST = "Il n'est pas possible d'antidater un contrat. Indiquez une date dans le futur."
ERROR_START_IN_FAR_FUTURE = (
"Il n'est pas possible de faire commencer un contrat aussi loin dans le futur. "
"Indiquez une date plus proche."
)
ERROR_END_IS_BEFORE_START = "La date de fin du contrat doit être postérieure à la date de début."
ERROR_START_AFTER_APPROVAL_END = (
"Attention, le PASS IAE sera expiré lors du début du contrat. Veuillez modifier la date de début."
Expand Down
2 changes: 2 additions & 0 deletions itou/www/apply/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ def clean_hiring_start_at(self):
# Hiring in the past is *temporarily* possible for GEIQ
if hiring_start_at and hiring_start_at < datetime.date.today() and not self.is_geiq:
self.add_error("hiring_start_at", forms.ValidationError(JobApplication.ERROR_START_IN_PAST))
elif hiring_start_at and hiring_start_at > datetime.date.today() + relativedelta(months=6):
self.add_error("hiring_start_at", forms.ValidationError(JobApplication.ERROR_START_IN_FAR_FUTURE))
else:
return hiring_start_at

Expand Down
21 changes: 18 additions & 3 deletions tests/www/apply/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,9 @@ def test_accept(self, *args, **kwargs):
)

# Wrong dates.
hiring_start_at = today
hiring_end_at = Approval.get_default_end_date(hiring_start_at)
# Force `hiring_start_at` in past.
hiring_start_at = hiring_start_at - relativedelta(days=1)
hiring_start_at = today - relativedelta(days=1)
hiring_end_at = hiring_start_at + relativedelta(months=1)
post_data = {
"hiring_start_at": hiring_start_at.strftime(DuetDatePickerWidget.INPUT_DATE_FORMAT),
"hiring_end_at": hiring_end_at.strftime(DuetDatePickerWidget.INPUT_DATE_FORMAT),
Expand All @@ -1273,6 +1272,22 @@ def test_accept(self, *args, **kwargs):
)
self.assertFormError(response.context["form_accept"], "hiring_start_at", JobApplication.ERROR_START_IN_PAST)

# Force `hiring_start_at` in more than 6 monts.
hiring_start_at = today + relativedelta(months=6, days=1)
hiring_end_at = hiring_start_at + relativedelta(months=1)
post_data = {
"hiring_start_at": hiring_start_at.strftime(DuetDatePickerWidget.INPUT_DATE_FORMAT),
"hiring_end_at": hiring_end_at.strftime(DuetDatePickerWidget.INPUT_DATE_FORMAT),
"answer": "",
**address,
}
response, _ = self.accept_job_application(
job_application=job_application, post_data=post_data, assert_successful=False
)
self.assertFormError(
response.context["form_accept"], "hiring_start_at", JobApplication.ERROR_START_IN_FAR_FUTURE
)

# Wrong dates: end < start.
hiring_start_at = today
hiring_end_at = hiring_start_at - relativedelta(days=1)
Expand Down

0 comments on commit f957930

Please sign in to comment.