Exemplo n.º 1
0
    def test_send_mail_reporter_created_text_contains_url(self):
        """
        URL's in the signal text are removed from the context and do not end up in the email
        """
        self.signal.text = 'These links should be removed: https://www.example.com/just/a/path/ and http://test.com'
        self.signal.save()

        actions = self._get_mail_rules(['Send mail signal created'])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        # Is it the only one that activates?
        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)

        self.assertEqual(len(mail.outbox), 1)
        self.assertIn('These links should be removed:  and ', mail.outbox[0].body)
        self.assertNotIn('https://www.example.com/just/a/path/', mail.outbox[0].body)
        self.assertNotIn('http://test.com', mail.outbox[0].body)

        # we want a history entry when a email was sent
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 2
0
    def test_send_mail_reporter_status_changed_afgehandeld(self):
        # Prepare signal with status change from `BEHANDELING` to `AFGEHANDELD`.
        StatusFactory.create(_signal=self.signal, state=workflow.BEHANDELING)
        status = StatusFactory.create(_signal=self.signal, state=workflow.AFGEHANDELD)
        self.signal.status = status
        self.signal.save()

        # Is the intended rule activated?
        actions = self._get_mail_rules(['Send mail signal handled'])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        # Is it the only one that activates?
        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)
        self.assertEqual(1, Feedback.objects.count())
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, f'Uw melding {self.signal.id}')
        self.assertEqual(mail.outbox[0].to, [self.signal.reporter.email, ])
        self.assertEqual(mail.outbox[0].from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertIn(settings.ORGANIZATION_NAME, mail.outbox[0].body)

        # we want a history entry when a email was sent
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 3
0
    def test_send_mail_reporter_created_no_note(self):
        # Is the intended rule activated?
        actions = self._get_mail_rules(['Send mail signal created'
                                        ])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        # We do not want to add a note so we should remove the 'history_entry_text'
        COPIED_SIGNAL_MAIL_RULES = [
            copy.deepcopy(r) for r in SIGNAL_MAIL_RULES
            if r['name'] == 'Send mail signal created'
        ]
        COPIED_SIGNAL_MAIL_RULES[0]['additional_info'].pop(
            'history_entry_text')

        # Is it the only one that activates?
        ma = MailActions(mail_rules=COPIED_SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)
        self.assertEqual(len(mail.outbox), 1)

        # we want a history entry when a email was sent
        self.assertEqual(Note.objects.count(), 0)
Exemplo n.º 4
0
    def test_send_mail_reporter_created(self):
        # Is the intended rule activated?
        actions = self._get_mail_rules(['Send mail signal created'
                                        ])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        # Is it the only one that activates?
        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         f'Uw melding {self.signal.id}')
        self.assertEqual(mail.outbox[0].to, [
            self.signal.reporter.email,
        ])
        self.assertEqual(mail.outbox[0].from_email,
                         settings.DEFAULT_FROM_EMAIL)
        self.assertIn('10 oktober 2018 12:00', mail.outbox[0].body)
        category = self.signal.category_assignment.category
        self.assertIn(category.handling_message, mail.outbox[0].body)
        self.assertIn(settings.ORGANIZATION_NAME, mail.outbox[0].body)

        # we want a history entry when a email was sent
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 5
0
    def test_never_send_mail_for_child_signal(self):
        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)

        actions = ma._get_actions(self.child_signal)
        self.assertEqual(len(actions), 0)

        ma.apply(signal_id=self.child_signal.id, send_mail=True)
        self.assertEqual(len(mail.outbox), 0)

        # we want no history entry when no email was sent:
        self.assertEqual(Note.objects.count(), 0)
Exemplo n.º 6
0
    def test_send_default_mail_template(self):
        actions = self._get_mail_rules(['Send mail signal created'])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 7
0
    def test_do_not_send_default_mail_template(self):
        new_status = StatusFactory.create(_signal=self.signal, state=workflow.GEANNULEERD, send_email=False)
        self.signal.status = new_status
        self.signal.save()

        actions = self._get_mail_rules(['Send mail optional'])._get_actions(self.signal)
        self.assertEqual(len(actions), 0)

        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(len(activated), 0)

        # Check mail contents
        ma.apply(signal_id=self.signal.id)
        self.assertEqual(len(mail.outbox), 0)
        self.assertEqual(Note.objects.count(), 0)
Exemplo n.º 8
0
    def test_send_mail_reporter_created_send_mail_false(self):
        # Is the intended rule activated?
        actions = self._get_mail_rules(['Send mail signal created'])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id, send_mail=False)

        # No mail should be sent
        self.assertEqual(len(mail.outbox), 0)

        # we want no history entry because no mail was sent
        self.assertEqual(Note.objects.count(), 0)
Exemplo n.º 9
0
    def test_send_mail_reporter_status_changed_afgehandeld_txt_and_html(self):
        # Prepare signal with status change from `BEHANDELING` to `AFGEHANDELD`.
        StatusFactory.create(_signal=self.signal, state=workflow.BEHANDELING)
        status = StatusFactory.create(_signal=self.signal,
                                      state=workflow.AFGEHANDELD)
        self.signal.status = status
        self.signal.save()

        # Is the intended rule activated?
        actions = self._get_mail_rules(['Send mail signal handled'
                                        ])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        # Is it the only one that activates?
        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(1, Feedback.objects.count())
        feedback = Feedback.objects.get(_signal__id=self.signal.id)

        message = mail.outbox[0]
        self.assertEqual(message.subject, f'Uw melding {self.signal.id}')
        self.assertEqual(message.to, [
            self.signal.reporter.email,
        ])
        self.assertEqual(mail.outbox[0].from_email,
                         settings.DEFAULT_FROM_EMAIL)

        positive_feedback_url, negative_feedback_url = get_feedback_urls(
            feedback)

        self.assertIn(positive_feedback_url, message.body)
        self.assertIn(negative_feedback_url, message.body)

        content, mime_type = message.alternatives[0]
        self.assertEqual(mime_type, 'text/html')
        self.assertIn(positive_feedback_url, content)
        self.assertIn(negative_feedback_url, content)

        # we want a history entry when a email was sent
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 10
0
    def test_send_mail_reporter_created_no_additional_context(self):
        # Is the intended rule activated?
        actions = self._get_mail_rules(['Send mail signal created'])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        # We do not want to add extra context so we should remove the 'context'
        COPIED_SIGNAL_MAIL_RULES = [copy.deepcopy(r)
                                    for r in SIGNAL_MAIL_RULES if r['name'] == 'Send mail signal created']
        COPIED_SIGNAL_MAIL_RULES[0]['kwargs'].pop('context')

        # Is it the only one that activates?
        ma = MailActions(mail_rules=COPIED_SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)
        self.assertEqual(len(mail.outbox), 1)
Exemplo n.º 11
0
    def test_reaction_requested_email(self):
        # "Reactie gevraagd" flow. Reporter is asked for additional information.
        status = StatusFactory.create(_signal=self.signal, state=workflow.REACTIE_GEVRAAGD, text='Was het mooi weer?')
        self.signal.status = status
        self.signal.save()

        # Is the intended rule activated?
        actions = self._get_mail_rules(['Send mail signal reaction request'])._get_actions(self.signal)
        self.assertEqual(len(actions), 1)

        # Is it the only one that activates?
        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(set(actions), set(activated))

        # Check mail contents
        ma.apply(signal_id=self.signal.id)
        self.assertEqual(len(mail.outbox), 1)
Exemplo n.º 12
0
    def test_send_no_mail_reporter_status_changed_afgehandeld_after_verzoek_tot_heropenen(self):
        # Prepare signal with status change from `VERZOEK_TOT_HEROPENEN` to `AFGEHANDELD`,
        # this should not lead to an email being sent.
        StatusFactory.create(_signal=self.signal, state=workflow.VERZOEK_TOT_HEROPENEN)
        status = StatusFactory.create(_signal=self.signal, state=workflow.AFGEHANDELD)
        self.signal.status = status
        self.signal.save()

        # no mail rule should activate
        ma = MailActions(mail_rules=SIGNAL_MAIL_RULES)
        activated = ma._get_actions(self.signal)
        self.assertEqual(len(activated), 0)

        # Check mail contents
        ma.apply(signal_id=self.signal.id)
        self.assertEqual(0, Feedback.objects.count())
        self.assertEqual(len(mail.outbox), 0)

        # we want no history entry when no email was sent
        self.assertEqual(Note.objects.count(), 0)