Example #1
0
    def test_create_diagnosis_with_administrative_criteria(self):

        job_seeker = JobSeekerFactory()
        prescriber_organization = AuthorizedPrescriberOrganizationWithMembershipFactory()
        user = prescriber_organization.members.first()
        user_info = UserInfo(
            user=user,
            kind=KIND_PRESCRIBER,
            prescriber_organization=prescriber_organization,
            is_authorized_prescriber=True,
            siae=None,
        )

        level1 = AdministrativeCriteria.Level.LEVEL_1
        level2 = AdministrativeCriteria.Level.LEVEL_2
        criteria1 = AdministrativeCriteria.objects.get(level=level1, name="Bénéficiaire du RSA")
        criteria2 = AdministrativeCriteria.objects.get(level=level2, name="Niveau d'étude 3 ou infra")
        criteria3 = AdministrativeCriteria.objects.get(level=level2, name="Senior (+50 ans)")

        diagnosis = EligibilityDiagnosis.create_diagnosis(
            job_seeker, user_info, administrative_criteria=[criteria1, criteria2, criteria3]
        )

        self.assertEqual(diagnosis.job_seeker, job_seeker)
        self.assertEqual(diagnosis.author, user)
        self.assertEqual(diagnosis.author_kind, KIND_PRESCRIBER)
        self.assertEqual(diagnosis.author_siae, None)
        self.assertEqual(diagnosis.author_prescriber_organization, prescriber_organization)

        administrative_criteria = diagnosis.administrative_criteria.all()
        self.assertEqual(3, administrative_criteria.count())
        self.assertIn(criteria1, administrative_criteria)
        self.assertIn(criteria2, administrative_criteria)
        self.assertIn(criteria3, administrative_criteria)
Example #2
0
 def set_validated_by(self, create, extracted, **kwargs):
     if not create:
         # Simple build, do nothing.
         return
     authorized_prescriber_org = AuthorizedPrescriberOrganizationWithMembershipFactory(
     )
     self.validated_by = authorized_prescriber_org.members.first()
     self.save()
Example #3
0
    def test_new_signup_warning_email_to_existing_members(self):
        authorized_organization = AuthorizedPrescriberOrganizationWithMembershipFactory()

        self.assertEqual(1, authorized_organization.members.count())
        user = authorized_organization.members.first()

        new_user = PrescriberFactory()
        message = authorized_organization.new_signup_warning_email_to_existing_members(new_user)
        message.send()

        self.assertEqual(len(mail.outbox), 1)
        email = mail.outbox[0]
        self.assertIn("Un nouvel utilisateur vient de rejoindre votre organisation", email.subject)
        self.assertIn("Si vous ne connaissez pas cette personne veuillez nous contacter", email.body)
        self.assertIn(new_user.first_name, email.body)
        self.assertIn(new_user.last_name, email.body)
        self.assertIn(new_user.email, email.body)
        self.assertIn(authorized_organization.display_name, email.body)
        self.assertIn(authorized_organization.siret, email.body)
        self.assertIn(authorized_organization.kind, email.body)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(len(email.to), 1)
        self.assertEqual(email.to[0], user.email)
Example #4
0
    def setUp(self):
        """
        Create test objects.
        """

        self.prescriber_organization = AuthorizedPrescriberOrganizationWithMembershipFactory()
        self.prescriber = self.prescriber_organization.members.first()

        today = timezone.now().date()

        # Set "now" to be "after" the day approval is open to prolongation.
        approval_end_at = (
            today + relativedelta(months=Approval.IS_OPEN_TO_PROLONGATION_BOUNDARIES_MONTHS) - relativedelta(days=1)
        )
        self.job_application = JobApplicationWithApprovalFactory(
            state=JobApplicationWorkflow.STATE_ACCEPTED,
            # Ensure that the job_application cannot be canceled.
            hiring_start_at=today - relativedelta(days=1),
            approval__end_at=approval_end_at,
        )
        self.siae = self.job_application.to_siae
        self.siae_user = self.job_application.to_siae.members.first()
        self.approval = self.job_application.approval
        self.assertEqual(0, self.approval.prolongation_set.count())
Example #5
0
    def setUp(self):
        """
        Create three organizations with two members each:
        - pole_emploi: job seekers agency.
        - l_envol: an emergency center for homeless people.
        - hit_pit: a boxing gym looking for boxers.

        Pole Emploi prescribers:
        - Thibault
        - laurie

        L'envol prescribers:
        - Audrey
        - Manu

        Hit Pit staff:
        - Eddie
        """

        # Pole Emploi
        pole_emploi = AuthorizedPrescriberOrganizationWithMembershipFactory(
            name="Pôle emploi", membership__user__first_name="Thibault"
        )
        PrescriberMembershipFactory(organization=pole_emploi, user__first_name="Laurie")
        thibault_pe = pole_emploi.members.get(first_name="Thibault")
        laurie_pe = pole_emploi.members.get(first_name="Laurie")

        # L'Envol
        l_envol = PrescriberOrganizationWithMembershipFactory(name="L'Envol", membership__user__first_name="Manu")
        PrescriberMembershipFactory(organization=l_envol, user__first_name="Audrey")
        audrey_envol = l_envol.members.get(first_name="Audrey")

        # Hit Pit
        hit_pit = SiaeWithMembershipAndJobsFactory(name="Hit Pit", membership__user__first_name="Eddie")
        eddie_hit_pit = hit_pit.members.get(first_name="Eddie")

        # Now send applications
        for i, state in enumerate(JobApplicationWorkflow.states):
            creation_date = timezone.now() - timezone.timedelta(days=i)
            job_application = JobApplicationSentByPrescriberFactory(
                to_siae=hit_pit,
                state=state,
                created_at=creation_date,
                sender=thibault_pe,
                sender_prescriber_organization=pole_emploi,
            )

        maggie = job_application.job_seeker
        maggie.save(update_fields={"first_name": "Maggie"})
        JobApplicationSentByPrescriberFactory(
            to_siae=hit_pit, sender=laurie_pe, sender_prescriber_organization=pole_emploi, job_seeker=maggie
        )

        self.prescriber_base_url = reverse("apply:list_for_prescriber")
        self.job_seeker_base_url = reverse("apply:list_for_job_seeker")
        self.siae_base_url = reverse("apply:list_for_siae")
        self.prescriber_exports_url = reverse("apply:list_for_prescriber_exports")
        self.siae_exports_url = reverse("apply:list_for_siae_exports")

        # Variables available for unit tests
        self.pole_emploi = pole_emploi
        self.hit_pit = hit_pit
        self.l_envol = l_envol
        self.thibault_pe = thibault_pe
        self.laurie_pe = laurie_pe
        self.eddie_hit_pit = eddie_hit_pit
        self.audrey_envol = audrey_envol
        self.maggie = maggie
Example #6
0
    def test_edit(self, mock_call_ban_geocoding_api):
        """Edit a prescriber organization."""

        organization = AuthorizedPrescriberOrganizationWithMembershipFactory(
            kind=PrescriberOrganization.Kind.CAP_EMPLOI)
        user = organization.members.first()

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

        url = reverse("prescribers_views:edit_organization")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        post_data = {
            "name": "foo",
            "siret": organization.siret,
            "description":
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
            "address_line_1": "2 Rue de Soufflenheim",
            "address_line_2": "",
            "city": "Betschdorf",
            "post_code": "67660",
            "department": "67",
            "email": "",
            "phone": "0610203050",
            "website": "https://famous-siae.com",
        }
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 302)

        mock_call_ban_geocoding_api.assert_called_once()

        organization = PrescriberOrganization.objects.get(
            siret=organization.siret)

        self.assertEqual(organization.name, post_data["name"])
        self.assertEqual(organization.description, post_data["description"])
        self.assertEqual(organization.address_line_1,
                         post_data["address_line_1"])
        self.assertEqual(organization.address_line_2,
                         post_data["address_line_2"])
        self.assertEqual(organization.city, post_data["city"])
        self.assertEqual(organization.post_code, post_data["post_code"])
        self.assertEqual(organization.department, post_data["department"])
        self.assertEqual(organization.email, post_data["email"])
        self.assertEqual(organization.phone, post_data["phone"])
        self.assertEqual(organization.website, post_data["website"])

        # This data comes from BAN_GEOCODING_API_RESULT_MOCK.
        self.assertEqual(organization.coords,
                         "SRID=4326;POINT (2.316754 48.838411)")
        self.assertEqual(organization.latitude, 48.838411)
        self.assertEqual(organization.longitude, 2.316754)
        self.assertEqual(organization.geocoding_score, 0.587663373207207)

        # Only admins should be able to edit organization details
        membership = organization.prescribermembership_set.first()
        membership.is_admin = False
        membership.save()
        url = reverse("prescribers_views:edit_organization")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)
Example #7
0
    def test_second_member_signup_without_code_to_authorized_organization(self):
        """
        A second user signup to join an authorized organization.
        First one is notified when second one signs up.
        """

        # Create an authorized organization with one admin.
        authorized_organization = AuthorizedPrescriberOrganizationWithMembershipFactory()
        self.assertEqual(1, authorized_organization.members.count())
        first_user = authorized_organization.members.first()
        membership = first_user.prescribermembership_set.get(organization=authorized_organization)
        self.assertTrue(membership.is_admin)

        # A second user wants to join the authorized organization.
        url = reverse("signup:prescriber_orienter")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        password = "******"

        # Ensures that the parent form's clean() method is called by testing
        # with a password that does not comply with CNIL recommendations.
        post_data = {
            "first_name": "John",
            "last_name": "Doe",
            "email": "*****@*****.**",
            "password1": "foofoofoo",
            "password2": "foofoofoo",
            "secret_code": authorized_organization.secret_code,
        }
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 200)
        self.assertIn(CnilCompositionPasswordValidator.HELP_MSG, response.context["form"].errors["password1"])

        post_data = {
            "first_name": "Jane",
            "last_name": "Doe",
            "email": "*****@*****.**",
            "password1": password,
            "password2": password,
            "secret_code": authorized_organization.secret_code,
        }

        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, reverse("account_email_verification_sent"))

        # Check `User` state.
        second_user = get_user_model().objects.get(email=post_data["email"])
        self.assertFalse(second_user.is_job_seeker)
        self.assertFalse(second_user.is_siae_staff)
        self.assertTrue(second_user.is_prescriber)
        # Check `Membership` state.
        self.assertIn(second_user, authorized_organization.members.all())
        self.assertEqual(2, authorized_organization.members.count())
        self.assertEqual(1, second_user.prescriberorganization_set.count())
        membership = second_user.prescribermembership_set.get(organization=authorized_organization)
        self.assertFalse(membership.is_admin)

        # Check sent emails.
        self.assertEqual(len(mail.outbox), 2)
        subjects = [email.subject for email in mail.outbox]
        self.assertIn("Un nouvel utilisateur vient de rejoindre votre organisation", subjects)
        self.assertIn("Confirmer l'adresse email pour la Plateforme de l'inclusion", subjects)
Example #8
0
    def test_authorized_prescriber_with_organization(self):
        url = reverse("signup:prescriber_authorized")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        authorized_organization = AuthorizedPrescriberOrganizationWithMembershipFactory()
        password = "******"

        # Ensures that the parent form's clean() method is called by testing
        # with a password that does not comply with CNIL recommendations.
        post_data = {
            "first_name": "John",
            "last_name": "Doe",
            "email": "*****@*****.**",
            "password1": "foofoofoo",
            "password2": "foofoofoo",
            "authorized_organization_id": authorized_organization.pk,
        }
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 200)
        self.assertIn(CnilCompositionPasswordValidator.HELP_MSG, response.context["form"].errors["password1"])

        # Ensures that the parent form's clean() method is called by testing
        # with a password that does not comply with CNIL recommendations.
        post_data = {
            "first_name": "John",
            "last_name": "Doe",
            "email": "*****@*****.**",
            "password1": "foofoofoo",
            "password2": "foofoofoo",
            "authorized_organization_id": authorized_organization.pk,
        }
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 200)
        self.assertIn(CnilCompositionPasswordValidator.HELP_MSG, response.context["form"].errors["password1"])

        post_data = {
            "first_name": "John",
            "last_name": "Doe",
            "email": "*****@*****.**",
            "password1": password,
            "password2": password,
            "authorized_organization_id": authorized_organization.pk,
        }
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, reverse("account_email_verification_sent"))

        # User checks.
        user = get_user_model().objects.get(email=post_data["email"])
        self.assertFalse(user.is_job_seeker)
        self.assertTrue(user.is_prescriber)
        self.assertFalse(user.is_siae_staff)
        # Check `EmailAddress` state.
        self.assertEqual(user.emailaddress_set.count(), 1)
        user_email = user.emailaddress_set.first()
        self.assertFalse(user_email.verified)

        # Check org.
        self.assertTrue(authorized_organization.is_authorized)
        self.assertEqual(
            authorized_organization.authorization_status, PrescriberOrganization.AuthorizationStatus.VALIDATED
        )

        # Check membership.
        self.assertIn(user, authorized_organization.members.all())
        self.assertEqual(2, authorized_organization.members.count())
        self.assertEqual(1, user.prescriberorganization_set.count())
        membership = user.prescribermembership_set.get(organization=authorized_organization)
        self.assertFalse(membership.is_admin)