Exemplo n.º 1
0
 def setUp(self):
     self.signal = SignalFactory.create()
     self.feedback_submitted = FeedbackFactory.create(
         _signal=self.signal,
         created_at=datetime(2019, 4, 9, 12, 0, tzinfo=pytz.UTC),
         submitted_at=datetime(2019, 4, 9, 18, 0, 0, tzinfo=pytz.UTC),
         text='Tevreden want mooi weer',
         text_extra='Waarom? Daarom!')
     self.feedback_requested = FeedbackFactory.create(
         _signal=self.signal,
         created_at=datetime(2019, 4, 9, 12, 0, 0),
     )
     self.csv_tmp_dir = tempfile.mkdtemp()
Exemplo n.º 2
0
    def test_send_system_mail_feedback_received(self):
        """
        Test the sending of the sending mail from the mail services
        """
        EmailTemplate.objects.create(
            key=EmailTemplate.SIGNAL_FEEDBACK_RECEIVED,
            title='Uw Feedback is ontvangen',
            body='test text {{ feedback_text }} {{ feedback_text_extra }}')
        signal = SignalFactory.create(status__state=workflow.GEMELD,
                                      reporter__email='*****@*****.**')

        text = 'my text _1234567'
        text_extra = 'my extra text _extra_987654321'
        feedback = FeedbackFactory.create(
            _signal=signal,
            text=text,
            text_extra=text_extra,
        )
        result = MailService.system_mail(signal=signal,
                                         action_name='feedback_received',
                                         feedback=feedback)

        self.assertTrue(result)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, [
            signal.reporter.email,
        ])
        self.assertEqual(mail.outbox[0].from_email,
                         settings.DEFAULT_FROM_EMAIL)
        self.assertIn(text, mail.outbox[0].body)
        self.assertIn(text_extra, mail.outbox[0].body)
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 3
0
    def test_send_system_email_with_context(self):
        """
        Check if the email with context is send to the user
        """
        action = MailService._system_actions.get('feedback_received')()
        signal = SignalFactory.create(status__state=workflow.GEMELD,
                                      reporter__email='*****@*****.**')

        text = 'my text _1234567'
        text_extra = 'my extra text _extra_987654321'
        feedback = FeedbackFactory.create(_signal=signal,
                                          text=text,
                                          text_extra=text_extra,
                                          token=uuid.uuid4())
        result = action(signal=signal, dry_run=False, feedback=feedback)
        self.assertTrue(result)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].to, [
            signal.reporter.email,
        ])
        self.assertEqual(mail.outbox[0].from_email,
                         settings.DEFAULT_FROM_EMAIL)
        self.assertIn(text, mail.outbox[0].body)
        self.assertIn(text_extra, mail.outbox[0].body)
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 4
0
    def test_apply_for_parent_signals(self):
        status_text = FuzzyText(length=400)

        parent_signal = SignalFactory.create(
            status__state=self.prev_state,
            status__text=status_text,
            status__send_email=self.send_email,
            reporter__email='*****@*****.**')
        SignalFactory.create(status__state=self.state,
                             status__text=status_text,
                             reporter__email='*****@*****.**',
                             parent=parent_signal)

        # create the new current state
        status = StatusFactory.create(_signal=parent_signal, state=self.state)
        parent_signal.status = status
        parent_signal.save()

        feedback = FeedbackFactory.create(
            allows_contact=True,
            _signal=parent_signal,
        )
        feedback.save()

        self.assertTrue(self.rule(parent_signal))
Exemplo n.º 5
0
    def test_only_send_feedback_negative_contact_mail(self):
        """
        Test to see if when a status is changed from VERZOEK_TOT_AFHANDELING to AFGEHANDELD and has allows_contact on
        the feedback to only send one email
        """
        self.assertEqual(len(mail.outbox), 0)
        signal = SignalFactory.create(
            status__state=workflow.VERZOEK_TOT_AFHANDELING,
            reporter__email='*****@*****.**')
        status = StatusFactory.create(_signal=signal,
                                      state=workflow.AFGEHANDELD)
        feedback = FeedbackFactory.create(
            allows_contact=True,
            _signal=signal,
        )
        feedback.save()
        signal.status = status  # change to new status AFGEHANDELD
        signal.save()

        self.assertTrue(MailService.status_mail(signal))
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         f'Meer over uw melding {signal.get_id_display()}')
        self.assertEqual(mail.outbox[0].to, [
            signal.reporter.email,
        ])
        self.assertEqual(mail.outbox[0].from_email,
                         settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(Note.objects.count(), 1)
Exemplo n.º 6
0
    def test_filter_feedback_not_received(self):
        feedback = FeedbackFactory.create(_signal=self.signals[0])

        params = {'feedback': 'not_received'}
        result_ids = self._request_filter_signals(params)

        self.assertEqual(1, len(result_ids))
        self.assertEqual(feedback._signal_id, result_ids[0])
Exemplo n.º 7
0
 def test_allows_contact_False_unsummited(self):
     """
     Unsubmitedd Feedback with Allows Contact False
     """
     signal = factories.SignalFactory.create()
     feedback = FeedbackFactory.create(_signal=signal, allows_contact=False)
     feedback.save()
     self.assertTrue(signal.allows_contact)
Exemplo n.º 8
0
    def test_filter_feedback_negative_feedback(self):
        feedback = FeedbackFactory.create(_signal=self.signals[0],
                                          is_satisfied=False,
                                          submitted_at=timezone.now())

        params = {'feedback': 'not_satisfied'}
        result_ids = self._request_filter_signals(params)

        self.assertEqual(1, len(result_ids))
        self.assertEqual(feedback._signal_id, result_ids[0])
Exemplo n.º 9
0
 def test_allows_contact_True(self):
     """
     Submitted feedback with allows_contantact True
     """
     signal = factories.SignalFactory.create()
     feedback = FeedbackFactory.create(_signal=signal,
                                       submitted_at='2022-01-01',
                                       allows_contact=True)
     feedback.save()
     self.assertTrue(signal.allows_contact)
Exemplo n.º 10
0
    def test_allows_contact_False(self):

        feedback = FeedbackFactory.create(
            _signal=self.signal,
            submitted_at='2022-01-01',
            allows_contact=False
        )
        feedback.save()
        data = self.serializer().to_representation(self.reporter)
        self.assertFalse(data['allows_contact'])
Exemplo n.º 11
0
    def test_filter_feedback_multiple_negative(self):
        now = timezone.now()

        FeedbackFactory.create(_signal=self.signals[0],
                               is_satisfied=True,
                               submitted_at=now - timedelta(days=1))

        feedback_negative = FeedbackFactory.create(_signal=self.signals[0],
                                                   is_satisfied=False,
                                                   submitted_at=now)

        params = {'feedback': 'satisfied'}
        result_ids = self._request_filter_signals(params)
        self.assertEqual(0, len(result_ids))

        params = {'feedback': 'not_satisfied'}
        result_ids = self._request_filter_signals(params)

        self.assertEqual(1, len(result_ids))
        self.assertEqual(feedback_negative._signal_id, result_ids[0])
Exemplo n.º 12
0
    def test_allowed_contact_disabled_flag(self):
        """
        When the flag is set to false the feature should always return true even if allows_contact is set to false
        """

        signal = factories.SignalFactory.create()
        feedback = FeedbackFactory.create(_signal=signal,
                                          allows_contact=False,
                                          submitted_at='2022-01-01')
        feedback.save()
        self.assertTrue(signal.allows_contact)
Exemplo n.º 13
0
 def test__get_description_of_receive_feedback_no_satisfied(self):
     feedback = FeedbackFactory.create(
         is_satisfied=False,
         text="My Text",
         text_list=None,
         text_extra=None,
         allows_contact=False,
     )
     response = _get_description_of_receive_feedback(feedback.token)
     validate_text = "Nee, de melder is ontevreden\nWaarom: My Text\n" \
                     "Toestemming contact opnemen: Nee"
     self.assertEqual(response, validate_text)
Exemplo n.º 14
0
 def test__get_description_of_receive_feedback(self):
     feedback = FeedbackFactory.create(
         is_satisfied=True,
         text=None,
         text_list=['my', 'test', 'list'],
         text_extra='extra_text',
         allows_contact=True,
     )
     response = _get_description_of_receive_feedback(feedback.token)
     validate_text = "Ja, de melder is tevreden\nWaarom: my,test,list\nToelichting: extra_text\n" \
                     "Toestemming contact opnemen: Ja"
     self.assertEqual(response, validate_text)
Exemplo n.º 15
0
    def setUp(self):
        status_text = FuzzyText(length=400)
        self.signal = SignalFactory.create(status__state=self.prev_state,
                                           status__text=status_text,
                                           status__send_email=self.send_email,
                                           reporter__email='*****@*****.**')

        # create the new current state
        status = StatusFactory.create(_signal=self.signal, state=self.state)
        self.signal.status = status
        self.signal.save()
        self.feedback = FeedbackFactory.create(_signal=self.signal,
                                               allows_contact=True,
                                               is_satisfied=False)
        self.feedback.save()
        super().setUp()
Exemplo n.º 16
0
 def test_allowed_contact_disable_flag(self):
     """
     When the flag is set to false the feature should always return true and still mail the users
     """
     status_text = FuzzyText(length=400)
     signal = SignalFactory.create(status__state=self.state,
                                   status__text=status_text,
                                   status__send_email=self.send_email,
                                   reporter__email='*****@*****.**')
     feedback = FeedbackFactory.create(_signal=signal,
                                       allows_contact=False,
                                       submitted_at='2022-01-01')
     feedback.save()
     signal.save()
     self.assertTrue(self.action(signal, dry_run=False))
     self.assertTrue(len(mail.outbox) > 0)
Exemplo n.º 17
0
 def test_allowed_contact_false(self):
     """
     Disable all emails when a signal has a feedback object with allows_contact False
     """
     status_text = FuzzyText(length=400)
     signal = SignalFactory.create(status__state=self.state,
                                   status__text=status_text,
                                   status__send_email=self.send_email,
                                   reporter__email='*****@*****.**')
     feedback = FeedbackFactory.create(_signal=signal,
                                       allows_contact=False,
                                       submitted_at='2022-01-01')
     feedback.save()
     signal.save()
     self.assertFalse(self.action(signal, dry_run=False))
     self.assertEqual(len(mail.outbox), 0)
Exemplo n.º 18
0
    def test_feedback_received_action_disabled(self):
        """
        FeedbackReceivedAction is disabled in settings
        """
        action = MailService._system_actions.get('feedback_received')()
        signal = SignalFactory.create(status__state=workflow.GEMELD,
                                      reporter__email='*****@*****.**')

        text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
        text_extra = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
        feedback = FeedbackFactory.create(_signal=signal,
                                          text=text,
                                          text_extra=text_extra,
                                          token=uuid.uuid4())

        result = action(signal=signal, dry_run=False, feedback=feedback)
        self.assertFalse(result)
        self.assertEqual(len(mail.outbox), 0)
Exemplo n.º 19
0
    def test_happy_flow(self):
        status_text = FuzzyText(length=400)

        # create signal in prev status
        signal = SignalFactory.create(status__state=self.prev_state,
                                      status__text=status_text,
                                      status__send_email=self.send_email,
                                      reporter__email='*****@*****.**')

        # create the new current state
        status = StatusFactory.create(_signal=signal, state=self.state)
        signal.status = status
        signal.save()

        feedback = FeedbackFactory.create(
            allows_contact=True,
            _signal=signal,
        )
        feedback.save()
        self.assertTrue(self.rule(signal))
Exemplo n.º 20
0
    def test_feedback_received_action_context(self):
        text = 'my text'
        text_extra = 'my extra text'
        signal = SignalFactory()
        feedback = FeedbackFactory.create(text=text,
                                          text_extra=text_extra,
                                          allows_contact=True,
                                          is_satisfied=False,
                                          token=uuid.uuid4(),
                                          _signal=signal)

        action = MailService._system_actions.get('feedback_received')()
        action(signal=signal, feedback=feedback)
        result = action.get_additional_context(signal)

        self.assertIn('feedback_text', result)
        self.assertIn('feedback_text_extra', result)
        self.assertIn('feedback_allows_contact', result)
        self.assertIn('feedback_is_satisfied', result)
        self.assertEqual(result['feedback_text'], text)
        self.assertEqual(result['feedback_text_extra'], text_extra)
        self.assertTrue(result['feedback_allows_contact'])
        self.assertFalse(result['feedback_is_satisfied'])
Exemplo n.º 21
0
    def setUp(self):
        now = timezone.now()

        self.reporter_1_email = '*****@*****.**'
        self.reporter_2_email = '*****@*****.**'

        self.test_category = CategoryFactory.create()

        stadhuis_point = Point(STADHUIS['lon'], STADHUIS['lat'])
        arena_point = Point(ARENA['lon'], ARENA['lat'])
        filmhuis_eye_point = Point(FILMMUSEUM_EYE['lon'], FILMMUSEUM_EYE['lat'])
        blauwe_theehuis_point = Point(BLAUWE_THEEHUIS['lon'], BLAUWE_THEEHUIS['lat'])

        with freeze_time(now - timedelta(days=5)):
            signal = SignalFactory.create(reporter__email=self.reporter_1_email,
                                          status__state=workflow.BEHANDELING,
                                          location__geometrie=stadhuis_point,
                                          location__buurt_code=STADHUIS['buurt_code'],
                                          category_assignment__category=self.test_category)
            FeedbackFactory.create(_signal=signal, submitted_at=now, is_satisfied=False)

            # Child signals ("deelmeldingen") should not show up in the reporter context, as they are used internally.
            self.child_signals = SignalFactory.create_batch(size=2,
                                                            reporter__email=self.reporter_1_email,
                                                            parent=signal,
                                                            location__geometrie=stadhuis_point,
                                                            location__buurt_code=ARENA['buurt_code'],
                                                            category_assignment__category=self.test_category)

        with freeze_time(now - timedelta(days=4)):
            SignalFactory.create(reporter__email=self.reporter_1_email,
                                 status__state=workflow.BEHANDELING,
                                 location__geometrie=stadhuis_point,
                                 location__buurt_code=STADHUIS['buurt_code'],
                                 category_assignment__category=self.test_category)

        with freeze_time(now - timedelta(days=3)):
            signal = SignalFactory.create(reporter__email=self.reporter_1_email,
                                          status__state=workflow.AFGEHANDELD,
                                          location__geometrie=arena_point,
                                          location__area_code='arena',
                                          location__buurt_code=ARENA['buurt_code'],
                                          category_assignment__category=self.test_category)
            FeedbackFactory.create(_signal=signal, submitted_at=now, is_satisfied=False)

            SignalFactory.create(reporter__email=self.reporter_1_email,
                                 status__state=workflow.AFGEHANDELD,
                                 location__geometrie=filmhuis_eye_point,
                                 location__buurt_code=FILMMUSEUM_EYE['buurt_code'],
                                 category_assignment__category=self.test_category)

            signal = SignalFactory.create(reporter__email=self.reporter_1_email,
                                          status__state=workflow.AFGEHANDELD,
                                          location__geometrie=blauwe_theehuis_point,
                                          location__buurt_code=BLAUWE_THEEHUIS['buurt_code'],
                                          category_assignment__category=self.test_category)
            FeedbackFactory.create(_signal=signal, submitted_at=now, is_satisfied=True)

        self.reporter_1_signals = Signal.objects.filter(
            (Q(parent__isnull=True) & Q(children__isnull=True)) | Q(children__isnull=False),
            reporter__email=self.reporter_1_email
        )

        self.anonymous_signals = [
            SignalFactory.create(reporter__email=None,
                                 status__state=workflow.BEHANDELING,
                                 location__geometrie=filmhuis_eye_point,
                                 location__buurt_code=FILMMUSEUM_EYE['buurt_code'],
                                 category_assignment__category=self.test_category),
            SignalFactory.create(reporter__email='',
                                 status__state=workflow.BEHANDELING,
                                 location__geometrie=blauwe_theehuis_point,
                                 location__buurt_code=BLAUWE_THEEHUIS['buurt_code'],
                                 category_assignment__category=self.test_category)
        ]

        self.reporter_2_signals = SignalFactory.create_batch(size=5,
                                                             reporter__email=self.reporter_2_email,
                                                             location__geometrie=filmhuis_eye_point,
                                                             location__buurt_code=FILMMUSEUM_EYE['buurt_code'],
                                                             category_assignment__category=self.test_category)
Exemplo n.º 22
0
 def setUp(self):
     self.feedback = FeedbackFactory.create()
Exemplo n.º 23
0
 def test_send_system_email_dry_run(self):
     action = MailService._system_actions.get('feedback_received')()
     signal = SignalFactory()
     feedback = FeedbackFactory.create(token=uuid.uuid4(), _signal=signal)
     self.assertTrue(action(signal=signal, dry_run=True, feedback=feedback))