コード例 #1
0
ファイル: tests.py プロジェクト: betagouv/itou
    def test_subscribe(self):
        NewSpontaneousJobAppEmployersNotification.subscribe(
            recipient=self.membership)
        self.assertTrue(self.membership.notifications)  # Dict is not empty
        self.assertTrue(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

        key = self.notification.NAME
        self.assertTrue(self.membership.notifications.get(key))  # Key exists
コード例 #2
0
ファイル: tests.py プロジェクト: betagouv/itou
    def setUp(self):
        self.siae = SiaeWithMembershipFactory()
        self.job_application = JobApplicationFactory(to_siae=self.siae)
        self.notification = NewSpontaneousJobAppEmployersNotification(
            job_application=self.job_application)

        # Make sure notifications are empty
        self.siaemembership_set = self.siae.siaemembership_set
        self.membership = self.siaemembership_set.first()
        self.assertFalse(self.membership.notifications)
コード例 #3
0
    def save(self):
        if self.cleaned_data.get("spontaneous"):
            NewSpontaneousJobAppEmployersNotification.subscribe(
                recipient=self.recipient)
        else:
            NewSpontaneousJobAppEmployersNotification.unsubscribe(
                recipient=self.recipient)

        if self.siae.job_description_through.exists():
            to_subscribe_pks = self.cleaned_data.get("qualified")
            NewQualifiedJobAppEmployersNotification.replace_subscriptions(
                recipient=self.recipient, subscribed_pks=to_subscribe_pks)
コード例 #4
0
    def test_employer_opt_out_siae_no_job_descriptions(self):
        siae = SiaeWithMembershipFactory()
        user = siae.members.first()
        recipient = user.siaemembership_set.get(siae=siae)
        form_name = "new_job_app_notification_form"
        self.client.login(username=user.email, password=DEFAULT_PASSWORD)

        # Recipient's notifications are empty for the moment.
        self.assertFalse(recipient.notifications)

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

        # Recipients are subscribed to spontaneous notifications by default,
        # the form should reflect that.
        self.assertTrue(
            response.context[form_name].fields["spontaneous"].initial)

        data = {"spontaneous": False}
        response = self.client.post(url, data=data)

        self.assertEqual(response.status_code, 302)

        recipient.refresh_from_db()
        self.assertTrue(recipient.notifications)
        self.assertFalse(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=recipient))
コード例 #5
0
ファイル: tests.py プロジェクト: betagouv/itou
    def test_unsubscribe_and_subscribe(self):
        """
        Make sure it's possible to toggle preferences.
        """
        NewSpontaneousJobAppEmployersNotification.unsubscribe(
            recipient=self.membership)
        self.assertFalse(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

        NewSpontaneousJobAppEmployersNotification.subscribe(
            recipient=self.membership)
        self.assertTrue(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

        NewSpontaneousJobAppEmployersNotification.unsubscribe(
            recipient=self.membership)
        self.assertFalse(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))
コード例 #6
0
    def __init__(self, *args, **kwargs):
        self.recipient = kwargs.pop("recipient")
        self.siae = kwargs.pop("siae")
        super().__init__(*args, **kwargs)
        self.fields[
            "spontaneous"].initial = NewSpontaneousJobAppEmployersNotification.is_subscribed(
                self.recipient)

        if self.siae.job_description_through.exists():
            default_pks = self.siae.job_description_through.values_list(
                "pk", flat=True)
            self.subscribed_pks = NewQualifiedJobAppEmployersNotification.recipient_subscribed_pks(
                recipient=self.recipient, default_pks=default_pks)
            choices = [
                (job_description.pk, job_description.display_name)
                for job_description in self.siae.job_description_through.all()
            ]
            self.fields["qualified"] = forms.MultipleChoiceField(
                label="Fiches de poste",
                required=False,
                widget=MultipleSwitchCheckboxWidget(),
                choices=choices,
                initial=self.subscribed_pks,
            )
コード例 #7
0
ファイル: tests.py プロジェクト: betagouv/itou
class NotificationsBaseClassTest(TestCase):
    # Use a child class to test parent class. Maybe refactor that later.

    def setUp(self):
        self.siae = SiaeWithMembershipFactory()
        self.job_application = JobApplicationFactory(to_siae=self.siae)
        self.notification = NewSpontaneousJobAppEmployersNotification(
            job_application=self.job_application)

        # Make sure notifications are empty
        self.siaemembership_set = self.siae.siaemembership_set
        self.membership = self.siaemembership_set.first()
        self.assertFalse(self.membership.notifications)

    def test_subscribe(self):
        NewSpontaneousJobAppEmployersNotification.subscribe(
            recipient=self.membership)
        self.assertTrue(self.membership.notifications)  # Dict is not empty
        self.assertTrue(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

        key = self.notification.NAME
        self.assertTrue(self.membership.notifications.get(key))  # Key exists

    def test_unsubscribe(self):
        self.notification.unsubscribe(recipient=self.membership)
        self.assertTrue(self.membership.notifications)  # Dict is not empty
        self.assertFalse(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

        key = self.notification.NAME
        self.assertTrue(self.membership.notifications.get(key))  # Key exists

    def test_unsubscribe_and_subscribe(self):
        """
        Make sure it's possible to toggle preferences.
        """
        NewSpontaneousJobAppEmployersNotification.unsubscribe(
            recipient=self.membership)
        self.assertFalse(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

        NewSpontaneousJobAppEmployersNotification.subscribe(
            recipient=self.membership)
        self.assertTrue(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

        NewSpontaneousJobAppEmployersNotification.unsubscribe(
            recipient=self.membership)
        self.assertFalse(
            NewSpontaneousJobAppEmployersNotification.is_subscribed(
                recipient=self.membership))

    def test_recipients_email(self):
        recipients_emails = self.notification.recipients_emails
        self.assertEqual(
            self.siaemembership_set.filter(
                user__email__in=recipients_emails).count(),
            len(recipients_emails))

    def test_inactive_user_not_in_recipients(self):
        SiaeMembershipFactory(siae=self.siae,
                              user__is_active=False,
                              is_admin=False)
        self.assertEqual(self.siaemembership_set.count(), 2)

        recipients = self.notification.get_recipients()
        self.assertEqual(len(recipients), 1)

    def test_get_recipients_default_send_to_unset_recipients(self):
        # Unset recipients are present in get_recipients if SEND_TO_UNSET_RECIPIENTS = True
        SiaeMembershipFactory(siae=self.siae,
                              user__is_active=False,
                              is_admin=False)
        recipients = self.notification.get_recipients()

        self.assertEqual(self.siaemembership_set.count(), 2)
        self.assertEqual(len(recipients), 1)

    def test_get_recipients_default_dont_send_to_unset_recipients(self):
        # Unset recipients are not present in get_recipients if SEND_TO_UNSET_RECIPIENTS = False
        self.notification.SEND_TO_UNSET_RECIPIENTS = False
        recipients = self.notification.get_recipients()
        self.assertEqual(len(recipients), 0)

    def test_send(self):
        self.notification.send()

        receivers = [
            receiver for message in mail.outbox for receiver in message.to
        ]
        self.assertEqual(self.notification.email.to, receivers)
コード例 #8
0
        job_application.sender_kind = session_data["sender_kind"]
        if sender_prescriber_organization_pk := session_data.get(
                "sender_prescriber_organization_pk"):
            job_application.sender_prescriber_organization = get_object_or_404(
                PrescriberOrganization, pk=sender_prescriber_organization_pk)
        if sender_siae_pk := session_data.get("sender_siae_pk"):
            job_application.sender_siae = get_object_or_404(Siae,
                                                            pk=sender_siae_pk)
        job_application.to_siae = siae
        job_application.save()

        for job in form.cleaned_data["selected_jobs"]:
            job_application.selected_jobs.add(job)

        if job_application.is_spontaneous:
            notification = NewSpontaneousJobAppEmployersNotification(
                job_application=job_application)
        else:
            notification = NewQualifiedJobAppEmployersNotification(
                job_application=job_application)

        notification.send()
        base_url = request.build_absolute_uri("/")[:-1]
        job_application.email_new_for_job_seeker(base_url=base_url).send()

        if job_application.is_sent_by_proxy:
            job_application.email_new_for_prescriber.send()

        return HttpResponseRedirect(next_url)

    s3_upload = S3Upload(kind="resume")
    s3_form_values = s3_upload.form_values