def send_mail_reporter_status_changed_afgehandeld(signal_pk, status_pk, prev_status_pk): signal = Signal.objects.get(pk=signal_pk) status = Status.objects.get(pk=status_pk) prev_status = Status.objects.get(pk=prev_status_pk) mail.send_mail_reporter_status_changed_afgehandeld(signal, status, prev_status)
def test_links_environment_env_var_not_set(self): """Deals with the case where nothing is overridden and `environment` not set.""" # Prepare signal with status change to `AFGEHANDELD`. prev_status = self.signal.status status = StatusFactory.create(_signal=self.signal, state=workflow.AFGEHANDELD) self.signal.status = status self.signal.save() # Check that generated emails contain the correct links for all # configured environments: env_fe_mapping = feedback_settings.FEEDBACK_ENV_FE_MAPPING self.assertEqual(len(env_fe_mapping), 1) for environment, fe_location in env_fe_mapping.items(): with mock.patch.dict('os.environ', {}, clear=True): mail.outbox = [] num_of_messages = reporter_mail.send_mail_reporter_status_changed_afgehandeld( self.signal, status, prev_status ) self.assertEqual(num_of_messages, 1) self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertIn('http://dummy_link', message.body) self.assertIn('http://dummy_link', message.alternatives[0][0])
def test_links_in_different_environments(self): """Test that generated feedback links contain the correct host.""" # Prepare signal with status change to `AFGEHANDELD`. prev_status = self.signal.status status = StatusFactory.create(_signal=self.signal, state=workflow.AFGEHANDELD) self.signal.status = status self.signal.save() # Check that generated emails contain the correct links for all # configured environments: env_fe_mapping = getattr(settings, 'FEEDBACK_ENV_FE_MAPPING', feedback_settings.FEEDBACK_ENV_FE_MAPPING) self.assertEqual(len(env_fe_mapping), 3) # sanity check Amsterdam installation has three for environment, fe_location in env_fe_mapping.items(): local_env = {'ENVIRONMENT': environment} with mock.patch.dict('os.environ', local_env): mail.outbox = [] num_of_messages = reporter_mail.send_mail_reporter_status_changed_afgehandeld( self.signal, status, prev_status ) self.assertEqual(num_of_messages, 1) self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertIn(fe_location, message.body) self.assertIn(fe_location, message.alternatives[0][0])
def test_send_mail_reporter_status_changed_afgehandeld_no_email(self): # Prepare signal with status change to `AFGEHANDELD`. prev_status = StatusFactory.create(_signal=self.signal, state=workflow.BEHANDELING) status = StatusFactory.create(_signal=self.signal_no_email, state=workflow.AFGEHANDELD) self.signal_no_email.status = status self.signal_no_email.save() num_of_messages = reporter_mail.send_mail_reporter_status_changed_afgehandeld( self.signal_no_email, status, prev_status ) self.assertEqual(0, Feedback.objects.count()) self.assertEqual(num_of_messages, None)
def test_send_mail_reporter_status_changed_afgehandeld_no_status_afgehandeld(self): # Note: SignalFactory always creates a signal with GEMELD status. prev_status = self.signal.status status = StatusFactory.create(_signal=self.signal, state=workflow.BEHANDELING) self.signal.status = status self.signal.save() num_of_messages = reporter_mail.send_mail_reporter_status_changed_afgehandeld( signal=self.signal, status=self.signal.status, prev_status=prev_status ) self.assertEqual(0, Feedback.objects.count()) self.assertEqual(num_of_messages, None)
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`. prev_status = 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() num_of_messages = reporter_mail.send_mail_reporter_status_changed_afgehandeld( self.signal, status, prev_status) self.assertEqual(0, Feedback.objects.count()) self.assertEqual(num_of_messages, None) self.assertEqual(len(mail.outbox), 0)
def test_send_mail_reporter_status_changed_afgehandeld(self): # Prepare signal with status change from `BEHANDELING` to `AFGEHANDELD`. prev_status = StatusFactory.create(_signal=self.signal, state=workflow.BEHANDELING) status = StatusFactory.create(_signal=self.signal, state=workflow.AFGEHANDELD) self.signal.status = status self.signal.save() num_of_messages = reporter_mail.send_mail_reporter_status_changed_afgehandeld( self.signal, status, prev_status) self.assertEqual(1, Feedback.objects.count()) self.assertEqual(num_of_messages, 1) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, f'Betreft melding: {self.signal.id}') self.assertEqual(mail.outbox[0].to, ['*****@*****.**', ])
def test_send_mail_reporter_status_changed_afgehandeld_txt_and_html(self): mail.outbox = [] # Prepare signal with status change from `BEHANDELING` to `AFGEHANDELD`. prev_status = StatusFactory.create(_signal=self.signal, state=workflow.BEHANDELING) status = StatusFactory.create(_signal=self.signal, state=workflow.AFGEHANDELD) self.signal.status = status self.signal.save() num_of_messages = reporter_mail.send_mail_reporter_status_changed_afgehandeld( self.signal, status, prev_status) self.assertEqual(1, Feedback.objects.count()) feedback = Feedback.objects.get(_signal__id=self.signal.id) self.assertEqual(num_of_messages, 1) self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertEqual(message.subject, f'Betreft melding: {self.signal.id}') self.assertEqual(message.to, [ '*****@*****.**', ]) positive_feedback_url, negative_feedback_url = get_feedback_urls( feedback) context = { 'negative_feedback_url': negative_feedback_url, 'positive_feedback_url': positive_feedback_url, 'signal': self.signal, 'status': status, } txt_message = reporter_mail._create_message( 'email/signal_status_changed_afgehandeld.txt', context=context) html_message = reporter_mail._create_message( 'email/signal_status_changed_afgehandeld.html', context=context) self.assertEqual(message.body, txt_message) content, mime_type = message.alternatives[0] self.assertEqual(mime_type, 'text/html') self.assertEqual(content, html_message)