def test_valid_for_prescriber(self): user = PrescriberFactory() criterion1 = AdministrativeCriteria.objects.get(pk=13) form_data = { f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion1.pk}": "true" } form = AdministrativeCriteriaForm(user, siae=None, data=form_data) form.is_valid() expected_cleaned_data = [criterion1] self.assertEqual(form.cleaned_data, expected_cleaned_data)
def test_valid_for_siae_of_kind_etti(self): siae = SiaeWithMembershipFactory(kind=Siae.KIND_ETTI) user = siae.members.first() criterion1 = AdministrativeCriteria.objects.get(pk=1) criterion2 = AdministrativeCriteria.objects.get(pk=5) criterion3 = AdministrativeCriteria.objects.get(pk=9) # At least 1 criterion level 1. form_data = { f"{AdministrativeCriteriaForm.LEVEL_1_PREFIX}{criterion1.pk}": "true" } form = AdministrativeCriteriaForm(user, siae=siae, data=form_data) form.is_valid() expected_cleaned_data = [criterion1] self.assertEqual(form.cleaned_data, expected_cleaned_data) # Or at least 2 criterion level 1. form_data = { f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion2.pk}": "true", f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion3.pk}": "true", } form = AdministrativeCriteriaForm(user, siae=siae, data=form_data) form.is_valid() expected_cleaned_data = [criterion2, criterion3] self.assertEqual(form.cleaned_data, expected_cleaned_data)
def test_error_criteria_number_for_siae(self): """ Test errors for SIAEs. """ siae = SiaeWithMembershipFactory(kind=Siae.KIND_ACI) user = siae.members.first() criterion1 = AdministrativeCriteria.objects.get(pk=1) criterion2 = AdministrativeCriteria.objects.get(pk=5) criterion3 = AdministrativeCriteria.objects.get(pk=9) form_data = { f"{AdministrativeCriteriaForm.LEVEL_1_PREFIX}{criterion1.pk}": "false" } form = AdministrativeCriteriaForm(user, siae=siae, data=form_data) form.is_valid() self.assertIn(form.ERROR_CRITERIA_NUMBER, form.errors["__all__"]) form_data = { f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion2.pk}": "true", f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion3.pk}": "true", } form = AdministrativeCriteriaForm(user, siae=siae, data=form_data) form.is_valid() self.assertIn(form.ERROR_CRITERIA_NUMBER, form.errors["__all__"])
def test_error_criteria_number_for_siae_of_kind_etti(self): """ Test errors for SIAEs of kind ETTI. """ siae = SiaeWithMembershipFactory(kind=Siae.KIND_ETTI) user = siae.members.first() criterion1 = AdministrativeCriteria.objects.get(pk=1) criterion2 = AdministrativeCriteria.objects.get(pk=5) # No level 1 criterion. form_data = { f"{AdministrativeCriteriaForm.LEVEL_1_PREFIX}{criterion1.pk}": "false" } form = AdministrativeCriteriaForm(user, siae=siae, data=form_data) form.is_valid() self.assertIn(form.ERROR_CRITERIA_NUMBER_ETTI, form.errors["__all__"]) # Only one level 2 criterion. form_data = { f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion2.pk}": "true" } form = AdministrativeCriteriaForm(user, siae=siae, data=form_data) form.is_valid() self.assertIn(form.ERROR_CRITERIA_NUMBER_ETTI, form.errors["__all__"])
def step_eligibility(request, siae_pk, template_name="apply/submit_step_eligibility.html"): """ Check eligibility (as an authorized prescriber). """ session_data = request.session[settings.ITOU_SESSION_JOB_APPLICATION_KEY] siae = get_object_or_404(Siae, pk=session_data["to_siae_pk"]) next_url = reverse("apply:step_application", kwargs={"siae_pk": siae_pk}) if not siae.is_subject_to_eligibility_rules: return HttpResponseRedirect(next_url) user_info = get_user_info(request) job_seeker = get_object_or_404(User, pk=session_data["job_seeker_pk"]) approvals_wrapper = get_approvals_wrapper(request, job_seeker, siae) skip = ( # Only "authorized prescribers" can perform an eligibility diagnosis. not user_info.is_authorized_prescriber # Eligibility diagnosis already performed. or job_seeker.has_valid_diagnosis()) if skip: return HttpResponseRedirect(next_url) data = request.POST if request.method == "POST" else None form_administrative_criteria = AdministrativeCriteriaForm(request.user, siae=None, data=data) if request.method == "POST" and form_administrative_criteria.is_valid(): EligibilityDiagnosis.create_diagnosis( job_seeker, user_info, administrative_criteria=form_administrative_criteria.cleaned_data) messages.success(request, "Éligibilité confirmée !") return HttpResponseRedirect(next_url) context = { "siae": siae, "job_seeker": job_seeker, "approvals_wrapper": approvals_wrapper, "form_administrative_criteria": form_administrative_criteria, } return render(request, template_name, context)
def eligibility(request, job_application_id, template_name="apply/process_eligibility.html"): """ Check eligibility (as an SIAE). """ queryset = JobApplication.objects.siae_member_required(request.user) job_application = get_object_or_404( queryset, id=job_application_id, state__in=[ JobApplicationWorkflow.STATE_PROCESSING, JobApplicationWorkflow.STATE_POSTPONED ], ) if not job_application.to_siae.is_subject_to_eligibility_rules: raise Http404() form_administrative_criteria = AdministrativeCriteriaForm( request.user, siae=job_application.to_siae, data=request.POST or None) form_confirm_eligibility = ConfirmEligibilityForm( data=request.POST or None) if request.method == "POST" and form_confirm_eligibility.is_valid( ) and form_administrative_criteria.is_valid(): user_info = get_user_info(request) EligibilityDiagnosis.create_diagnosis( job_application.job_seeker, user_info, administrative_criteria=form_administrative_criteria.cleaned_data) messages.success(request, _("Éligibilité confirmée !")) next_url = reverse("apply:details_for_siae", kwargs={"job_application_id": job_application.id}) return HttpResponseRedirect(next_url) context = { "approvals_wrapper": job_application.job_seeker.approvals_wrapper, "job_application": job_application, "form_administrative_criteria": form_administrative_criteria, "form_confirm_eligibility": form_confirm_eligibility, } return render(request, template_name, context)
def test_error_senior_junior(self): """ Test ERROR_SENIOR_JUNIOR. """ user = PrescriberFactory() criterion1 = AdministrativeCriteria.objects.get( name="Senior (+50 ans)") criterion2 = AdministrativeCriteria.objects.get(name="Jeune (-26 ans)") form_data = { f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion1.pk}": "true", f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion2.pk}": "true", } form = AdministrativeCriteriaForm(user, siae=None, data=form_data) form.is_valid() self.assertIn(form.ERROR_SENIOR_JUNIOR, form.errors["__all__"])
def test_error_error_long_term_job_seeker(self): """ Test ERROR_LONG_TERM_JOB_SEEKER. """ user = PrescriberFactory() criterion1 = AdministrativeCriteria.objects.get( name="DETLD (+ 24 mois)") criterion2 = AdministrativeCriteria.objects.get( name="DELD (12-24 mois)") form_data = { # Level 1. f"{AdministrativeCriteriaForm.LEVEL_1_PREFIX}{criterion1.pk}": "true", # Level 2. f"{AdministrativeCriteriaForm.LEVEL_2_PREFIX}{criterion2.pk}": "true", } form = AdministrativeCriteriaForm(user, siae=None, data=form_data) form.is_valid() self.assertIn(form.ERROR_LONG_TERM_JOB_SEEKER, form.errors["__all__"])