Пример #1
0
    def test_has_valid_eligibility_diagnosis(self):

        # No diagnosis.
        job_seeker = JobSeekerFactory()
        self.assertFalse(job_seeker.has_valid_eligibility_diagnosis)

        # Has Itou diagnosis.
        job_seeker = JobSeekerFactory()
        EligibilityDiagnosisFactory(job_seeker=job_seeker)
        self.assertTrue(job_seeker.has_valid_eligibility_diagnosis)

        # Has valid Pôle emploi diagnosis.
        job_seeker = JobSeekerFactory()
        PoleEmploiApprovalFactory(pole_emploi_id=job_seeker.pole_emploi_id, birthdate=job_seeker.birthdate)
        self.assertTrue(job_seeker.has_valid_eligibility_diagnosis)

        # Has expired Pôle emploi diagnosis.
        job_seeker = JobSeekerFactory()
        end_at = datetime.date.today() - relativedelta(years=2)
        start_at = end_at - relativedelta(years=2)
        PoleEmploiApprovalFactory(
            pole_emploi_id=job_seeker.pole_emploi_id, birthdate=job_seeker.birthdate, start_at=start_at, end_at=end_at
        )
        self.assertFalse(job_seeker.has_valid_eligibility_diagnosis)

        # Has an expired diagnosis
        job_seeker = JobSeekerFactory()
        ExpiredEligibilityDiagnosisFactory(job_seeker=job_seeker)
        self.assertFalse(job_seeker.has_valid_eligibility_diagnosis)
Пример #2
0
    def test_is_valid(self):
        # Valid diagnosis.
        diagnosis = EligibilityDiagnosisFactory()
        self.assertTrue(diagnosis.is_valid)

        # Expired diagnosis.
        diagnosis = ExpiredEligibilityDiagnosisFactory()
        self.assertFalse(diagnosis.is_valid)
Пример #3
0
    def test_is_considered_valid(self):
        # Valid diagnosis.
        diagnosis = EligibilityDiagnosisFactory()
        self.assertTrue(diagnosis.is_considered_valid)

        # Expired diagnosis.
        diagnosis = ExpiredEligibilityDiagnosisFactory()
        self.assertFalse(diagnosis.is_considered_valid)

        # Expired diagnosis but ongoing PASS IAE.
        diagnosis = ExpiredEligibilityDiagnosisFactory()
        ApprovalFactory(user=diagnosis.job_seeker)
        self.assertTrue(diagnosis.is_considered_valid)
Пример #4
0
 def test_details_template_for_state_canceled_valid_diagnosis(self):
     """Test actions available for other states."""
     self.client.login(username=self.siae_user.email, password=DEFAULT_PASSWORD)
     EligibilityDiagnosisFactory(job_seeker=self.job_application.job_seeker)
     self.job_application.state = JobApplicationWorkflow.STATE_CANCELLED
     self.job_application.save()
     response = self.client.get(self.url_details)
     # Test template content.
     self.assertNotContains(response, self.url_process)
     self.assertNotContains(response, self.url_eligibility)
     self.assertNotContains(response, self.url_refuse)
     self.assertNotContains(response, self.url_postpone)
     self.assertContains(response, self.url_accept)
Пример #5
0
    def test_pdfshift_api_is_down(self, *args, **kwargs):
        job_application = JobApplicationWithApprovalFactory()
        siae_member = job_application.to_siae.members.first()
        job_seeker = job_application.job_seeker
        EligibilityDiagnosisFactory(job_seeker=job_seeker)

        self.client.login(username=siae_member.email,
                          password=DEFAULT_PASSWORD)

        with self.assertRaises(ConnectionAbortedError):
            self.client.get(
                reverse("approvals:approval_as_pdf",
                        kwargs={"job_application_id": job_application.pk}))
Пример #6
0
    def test_download_job_app_approval_as_pdf(self, *args, **kwargs):
        job_application = JobApplicationWithApprovalFactory()
        siae_member = job_application.to_siae.members.first()
        job_seeker = job_application.job_seeker
        EligibilityDiagnosisFactory(job_seeker=job_seeker)

        self.client.login(username=siae_member.email,
                          password=DEFAULT_PASSWORD)

        response = self.client.get(
            reverse("approvals:approval_as_pdf",
                    kwargs={"job_application_id": job_application.pk}))

        self.assertEqual(response.status_code, 200)
        self.assertIn("pdf", response.get("Content-Type"))
Пример #7
0
    def test_impossible_download_when_approval_is_missing(
            self, *args, **kwargs):
        """
        The button to download an approval is show only when
        certain conditions are met.
        Nevertheless, don't trust the client. Make sure we raise an error
        if the same conditions are not met in this view.
        """
        # Create a job application without an approval.
        job_application = JobApplicationFactory()
        siae_member = job_application.to_siae.members.first()
        job_seeker = job_application.job_seeker
        EligibilityDiagnosisFactory(job_seeker=job_seeker)

        self.client.login(username=siae_member.email,
                          password=DEFAULT_PASSWORD)
        response = self.client.get(
            reverse("approvals:approval_as_pdf",
                    kwargs={"job_application_id": job_application.pk}))
        self.assertEqual(response.status_code, 404)
Пример #8
0
    def test_has_expired(self):
        diagnosis = EligibilityDiagnosisFactory()
        self.assertFalse(diagnosis.has_expired)

        self.diagnosis = ExpiredEligibilityDiagnosisFactory()
        self.assertTrue(self.diagnosis.has_expired)
Пример #9
0
    def test_valid_and_expired_methods(self):
        """
        Test both `has_considered_valid()`, `last_considered_valid()` and `last_expired()` methods.
        """

        # No diagnosis.
        job_seeker = JobSeekerFactory()
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(job_seeker=job_seeker)
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(job_seeker=job_seeker)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker)
        self.assertIsNone(last_considered_valid)
        self.assertIsNone(last_expired)
        self.assertFalse(has_considered_valid)

        # Has Itou diagnosis.
        diagnosis = EligibilityDiagnosisFactory()
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(job_seeker=diagnosis.job_seeker)
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(job_seeker=diagnosis.job_seeker)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=diagnosis.job_seeker)
        self.assertEqual(last_considered_valid, diagnosis)
        self.assertIsNone(last_expired)
        self.assertTrue(has_considered_valid)

        # Has a valid PASS IAE but NO diagnosis.
        approval = ApprovalFactory()
        job_seeker = approval.user
        self.assertEqual(0, job_seeker.eligibility_diagnoses.count())
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(job_seeker=job_seeker)
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(job_seeker=job_seeker)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker)
        self.assertTrue(has_considered_valid)
        self.assertIsNone(last_considered_valid)
        self.assertIsNone(last_expired)

        # Has valid Pôle emploi diagnosis.
        job_seeker = JobSeekerFactory()
        PoleEmploiApprovalFactory(pole_emploi_id=job_seeker.pole_emploi_id, birthdate=job_seeker.birthdate)
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(job_seeker=job_seeker)
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(job_seeker=job_seeker)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker)
        self.assertTrue(has_considered_valid)
        self.assertIsNone(last_considered_valid)
        self.assertIsNone(last_expired)

        # Has expired Pôle emploi diagnosis.
        job_seeker = JobSeekerFactory()
        end_at = datetime.date.today() - relativedelta(years=2)
        start_at = end_at - relativedelta(years=2)
        PoleEmploiApprovalFactory(
            pole_emploi_id=job_seeker.pole_emploi_id, birthdate=job_seeker.birthdate, start_at=start_at, end_at=end_at
        )
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(job_seeker=job_seeker)
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(job_seeker=job_seeker)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker)
        self.assertFalse(has_considered_valid)
        self.assertIsNone(last_considered_valid)
        self.assertIsNone(last_expired)

        # Has expired Itou diagnosis.
        expired_diagnosis = ExpiredEligibilityDiagnosisFactory()
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(
            job_seeker=expired_diagnosis.job_seeker
        )
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(
            job_seeker=expired_diagnosis.job_seeker
        )
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=expired_diagnosis.job_seeker)
        self.assertFalse(has_considered_valid)
        self.assertIsNone(last_considered_valid)
        self.assertIsNotNone(last_expired)

        # Has expired Itou diagnosis but has an ongoing PASS IAE.
        expired_diagnosis = ExpiredEligibilityDiagnosisFactory()
        ApprovalFactory(user=expired_diagnosis.job_seeker)
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(
            job_seeker=expired_diagnosis.job_seeker
        )
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(
            job_seeker=expired_diagnosis.job_seeker
        )
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=expired_diagnosis.job_seeker)

        self.assertTrue(has_considered_valid)
        self.assertEqual(last_considered_valid, expired_diagnosis)
        self.assertIsNone(last_expired)

        # Has Itou diagnosis made by an SIAE.
        siae1 = SiaeWithMembershipFactory()
        siae2 = SiaeWithMembershipFactory()
        diagnosis = EligibilityDiagnosisMadeBySiaeFactory(author_siae=siae1)
        # From `siae1` perspective.
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(
            job_seeker=diagnosis.job_seeker, for_siae=siae1
        )
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(
            job_seeker=diagnosis.job_seeker, for_siae=siae1
        )
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=diagnosis.job_seeker, for_siae=siae1)
        self.assertTrue(has_considered_valid)
        self.assertEqual(last_considered_valid, diagnosis)
        self.assertIsNone(last_expired)
        # From `siae2` perspective.
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(
            job_seeker=diagnosis.job_seeker, for_siae=siae2
        )
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(
            job_seeker=diagnosis.job_seeker, for_siae=siae2
        )
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=diagnosis.job_seeker, for_siae=siae2)
        self.assertFalse(has_considered_valid)
        self.assertIsNone(last_considered_valid)
        self.assertIsNone(last_expired)

        # Has Itou diagnosis made by a prescriber.
        siae = SiaeWithMembershipFactory()
        prescriber_diagnosis = EligibilityDiagnosisFactory()
        # From siae perspective.
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(
            job_seeker=prescriber_diagnosis.job_seeker, for_siae=siae
        )
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(
            job_seeker=prescriber_diagnosis.job_seeker, for_siae=siae
        )
        last_expired = EligibilityDiagnosis.objects.last_expired(
            job_seeker=prescriber_diagnosis.job_seeker, for_siae=siae
        )
        self.assertTrue(has_considered_valid)
        self.assertEqual(last_considered_valid, prescriber_diagnosis)
        self.assertIsNone(last_expired)

        # Has 2 Itou diagnoses: 1 made by an SIAE prior to another one by a prescriber.
        job_seeker = JobSeekerFactory()
        siae = SiaeWithMembershipFactory()
        prescriber_diagnosis = EligibilityDiagnosisFactory(job_seeker=job_seeker)
        # From `siae` perspective.
        has_considered_valid = EligibilityDiagnosis.objects.has_considered_valid(job_seeker=job_seeker, for_siae=siae)
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(
            job_seeker=job_seeker, for_siae=siae
        )
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker, for_siae=siae)
        self.assertTrue(has_considered_valid)
        # A diagnosis made by a prescriber takes precedence.
        self.assertEqual(last_considered_valid, prescriber_diagnosis)
        self.assertIsNone(last_expired)

        # Has an expired Itou diagnoses made by another SIAE.
        job_seeker = JobSeekerFactory()
        siae1 = SiaeWithMembershipFactory()
        siae2 = SiaeWithMembershipFactory()
        expired_diagnosis = ExpiredEligibilityDiagnosisMadeBySiaeFactory(job_seeker=job_seeker, author_siae=siae1)

        # From `siae` perspective.
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker, for_siae=siae1)
        self.assertEqual(last_expired, expired_diagnosis)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker, for_siae=siae2)
        self.assertIsNone(last_expired)

        # Has 2 Itou diagnoses: 1 is considered expired and the second is considered valid.
        job_seeker = JobSeekerFactory()
        ExpiredEligibilityDiagnosisFactory(job_seeker=job_seeker)
        EligibilityDiagnosisFactory(job_seeker=job_seeker)

        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker)
        last_considered_valid = EligibilityDiagnosis.objects.last_considered_valid(job_seeker=job_seeker)
        # When has a valid diagnosis, `last_expired` return None
        self.assertIsNotNone(last_considered_valid)
        self.assertIsNone(last_expired)

        # Has 2 Itou diagnoses expired: the last one expired must be returned.
        job_seeker = JobSeekerFactory()

        date_6m = (
            timezone.now() - relativedelta(months=EligibilityDiagnosis.EXPIRATION_DELAY_MONTHS) - relativedelta(day=1)
        )
        date_12m = date_6m - relativedelta(months=6)

        expired_diagnosis_old = EligibilityDiagnosisFactory(job_seeker=job_seeker, created_at=date_12m)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker)
        self.assertEqual(last_expired, expired_diagnosis_old)

        expired_diagnosis_last = EligibilityDiagnosisFactory(job_seeker=job_seeker, created_at=date_6m)
        last_expired = EligibilityDiagnosis.objects.last_expired(job_seeker=job_seeker)
        self.assertEqual(last_expired, expired_diagnosis_last)
Пример #10
0
 def test_expired(self):
     expected_num = 3
     EligibilityDiagnosisFactory.create_batch(expected_num)
     ExpiredEligibilityDiagnosisFactory.create_batch(expected_num)
     self.assertEqual(expected_num * 2, EligibilityDiagnosis.objects.all().count())
     self.assertEqual(expected_num, EligibilityDiagnosis.objects.expired().count())