示例#1
0
文件: tests.py 项目: NathHense/itou
    def test_get_or_create_from_valid(self):

        # With an existing valid `PoleEmploiApproval`.

        user = JobSeekerFactory()
        valid_pe_approval = PoleEmploiApprovalFactory(
            pole_emploi_id=user.pole_emploi_id, birthdate=user.birthdate, number="625741810182A01"
        )
        approvals_wrapper = ApprovalsWrapper(user)

        approval = Approval.get_or_create_from_valid(approvals_wrapper)

        self.assertTrue(isinstance(approval, Approval))
        self.assertEqual(approval.start_at, valid_pe_approval.start_at)
        self.assertEqual(approval.end_at, valid_pe_approval.end_at)
        self.assertEqual(approval.number, valid_pe_approval.number[:12])
        self.assertEqual(approval.user, user)
        self.assertEqual(approval.created_by, None)

        # With an existing valid `Approval`.

        user = JobSeekerFactory()
        valid_approval = ApprovalFactory(user=user, start_at=datetime.date.today() - relativedelta(days=1))
        approvals_wrapper = ApprovalsWrapper(user)

        approval = Approval.get_or_create_from_valid(approvals_wrapper)
        self.assertTrue(isinstance(approval, Approval))
        self.assertEqual(approval, valid_approval)
示例#2
0
文件: tests.py 项目: NathHense/itou
 def test_status_without_approval(self):
     user = JobSeekerFactory()
     approvals_wrapper = ApprovalsWrapper(user)
     self.assertEqual(approvals_wrapper.status, ApprovalsWrapper.NONE_FOUND)
     self.assertFalse(approvals_wrapper.has_valid)
     self.assertFalse(approvals_wrapper.has_in_waiting_period)
     self.assertEqual(approvals_wrapper.latest_approval, None)
示例#3
0
文件: tests.py 项目: NathHense/itou
    def test_merge_approvals(self):

        user = JobSeekerFactory()

        # Approval.
        approval = ApprovalFactory(user=user, start_at=datetime.date(2016, 12, 20), end_at=datetime.date(2018, 12, 20))

        # PoleEmploiApproval 1.
        pe_approval_1 = PoleEmploiApprovalFactory(
            pole_emploi_id=user.pole_emploi_id,
            birthdate=user.birthdate,
            start_at=datetime.date(2018, 12, 20),
            end_at=datetime.date(2020, 12, 20),
        )

        # PoleEmploiApproval 2.
        # Same `start_at` as PoleEmploiApproval 1.
        # But `end_at` earlier than PoleEmploiApproval 1.
        pe_approval_2 = PoleEmploiApprovalFactory(
            pole_emploi_id=user.pole_emploi_id,
            birthdate=user.birthdate,
            start_at=datetime.date(2018, 12, 20),
            end_at=datetime.date(2019, 12, 19),
        )

        # Check timeline.
        approvals_wrapper = ApprovalsWrapper(user)
        self.assertEqual(len(approvals_wrapper.merged_approvals), 3)
        self.assertEqual(approvals_wrapper.merged_approvals[0], pe_approval_1)
        self.assertEqual(approvals_wrapper.merged_approvals[1], pe_approval_2)
        self.assertEqual(approvals_wrapper.merged_approvals[2], approval)
示例#4
0
文件: tests.py 项目: ikarius/itou
    def test_merge_approvals(self):

        user = JobSeekerFactory()

        # Create Approval.
        start_at = datetime.date.today() - relativedelta(years=4)
        end_at = start_at + relativedelta(years=2)
        approval = ApprovalFactory(user=user, start_at=start_at, end_at=end_at)

        # Create PoleEmploiApproval.
        start_at = datetime.date.today()
        end_at = start_at + relativedelta(years=2)
        pe_approval = PoleEmploiApprovalFactory(
            pole_emploi_id=user.pole_emploi_id,
            birthdate=user.birthdate,
            start_at=start_at,
            end_at=end_at,
        )

        # Check timeline.
        self.assertTrue(approval.start_at < pe_approval.start_at)

        approvals_wrapper = ApprovalsWrapper(user)
        self.assertEqual(len(approvals_wrapper.merged_approvals), 2)
        self.assertEqual(approvals_wrapper.merged_approvals[0], pe_approval)
        self.assertEqual(approvals_wrapper.merged_approvals[1], approval)
示例#5
0
文件: tests.py 项目: NathHense/itou
 def test_status_with_valid_pole_emploi_approval(self):
     user = JobSeekerFactory()
     approval = PoleEmploiApprovalFactory(pole_emploi_id=user.pole_emploi_id, birthdate=user.birthdate)
     approvals_wrapper = ApprovalsWrapper(user)
     self.assertEqual(approvals_wrapper.status, ApprovalsWrapper.VALID)
     self.assertFalse(approvals_wrapper.has_in_waiting_period)
     self.assertTrue(approvals_wrapper.has_valid)
     self.assertEqual(approvals_wrapper.latest_approval, approval)
示例#6
0
文件: tests.py 项目: NathHense/itou
 def test_status_with_valid_approval(self):
     user = JobSeekerFactory()
     approval = ApprovalFactory(user=user, start_at=datetime.date.today() - relativedelta(days=1))
     approvals_wrapper = ApprovalsWrapper(user)
     self.assertEqual(approvals_wrapper.status, ApprovalsWrapper.VALID)
     self.assertTrue(approvals_wrapper.has_valid)
     self.assertFalse(approvals_wrapper.has_in_waiting_period)
     self.assertEqual(approvals_wrapper.latest_approval, approval)
示例#7
0
文件: tests.py 项目: NathHense/itou
 def test_status_approval_with_elapsed_waiting_period(self):
     user = JobSeekerFactory()
     end_at = datetime.date.today() - relativedelta(years=3)
     start_at = end_at - relativedelta(years=2)
     approval = ApprovalFactory(user=user, start_at=start_at, end_at=end_at)
     approvals_wrapper = ApprovalsWrapper(user)
     self.assertEqual(approvals_wrapper.status, ApprovalsWrapper.WAITING_PERIOD_HAS_ELAPSED)
     self.assertFalse(approvals_wrapper.has_valid)
     self.assertFalse(approvals_wrapper.has_in_waiting_period)
     self.assertEqual(approvals_wrapper.latest_approval, approval)
示例#8
0
def pe_approval_search(request, template_name="approvals/pe_approval_search.html"):
    """
    Entry point of the `PoleEmploiApproval`'s conversion process which consists of 3 steps
    and allows to convert a `PoleEmploiApproval` into an `Approval`.
    This process is required following the end of the software allowing Pôle emploi to manage
    their approvals.

    Search for a PoleEmploiApproval by number.
    Redirects to the existing Pass if it exists.
    If not, it will ask you to search for an user in order to import the "agrément" as a "PASS IAE".
    """
    approval = None
    form = PoleEmploiApprovalSearchForm(request.GET or None)
    number = None
    siae = get_current_siae_or_404(request)
    back_url = reverse("approvals:pe_approval_search")

    if form.is_valid():
        number = form.cleaned_data["number"]
        approvals_wrapper = ApprovalsWrapper(number=number)
        approval = approvals_wrapper.latest_approval

        if approval:
            if approval.is_pass_iae:
                job_application = approval.user.last_accepted_job_application
                if job_application and job_application.to_siae == siae:
                    # Suspensions and prolongations links are available in the job application details page.
                    application_details_url = reverse(
                        "apply:details_for_siae", kwargs={"job_application_id": job_application.pk}
                    )
                    return HttpResponseRedirect(application_details_url)
                # The employer cannot handle the PASS as it's already used by another one.
                # Suggest him to make a self-prescription. A link is offered in the template.

            context = {
                "approval": approval,
                "back_url": back_url,
                "form": form,
                "number": number,
                "siae": siae,
            }
            return render(request, "approvals/pe_approval_search_found.html", context)

    context = {
        "form": form,
        "number": number,
        "siae": siae,
    }
    return render(request, template_name, context)
示例#9
0
 def approvals_wrapper(self):
     if not self.is_job_seeker:
         return None
     return ApprovalsWrapper(self)