def test_not_send_notification_if_wrong_role(self): self.assertFalse(models.EmailHook.objects.count()) self.system_notification.roles = ['manager'] self.system_notification.save() tasks.process_event(self.event.id) self.assertEqual(len(mail.outbox), 1) self.assertFalse(self.admin.email in mail.outbox[0].to)
def test_send_notification_if_user_is_not_subscribed_but_event_type_is_system_type( self, ): self.assertFalse(models.EmailHook.objects.count()) tasks.process_event(self.event.id) self.assertEqual(len(mail.outbox), 1) self.assertTrue(self.admin.email in mail.outbox[0].to)
def test_event_groups(self): groups = loggers.get_event_groups() group = list(groups.keys())[0] self.system_notification.event_groups = [group] self.system_notification.event_types = [] self.system_notification.save() self.event.event_type = list(groups[group])[0] self.event.save() tasks.process_event(self.event.id) self.assertEqual(len(mail.outbox), 1) self.assertTrue(self.admin.email in mail.outbox[0].to)
def test_email_hook_filters_events_by_user_and_event_type(self): # Create email hook for customer owner email_hook = logging_models.EmailHook.objects.create( user=self.owner, email=self.owner.email, event_types=[self.event_type]) # Trigger processing process_event(self.event.id) # Test that one message has been sent for email hook of customer owner self.assertEqual(len(mail.outbox), 1) # Verify that destination address of message is correct self.assertEqual(mail.outbox[0].to, [email_hook.email])
def test_webhook_makes_post_request_against_destination_url( self, requests_post): # Create web hook for customer owner self.web_hook = logging_models.WebHook.objects.create( user=self.owner, destination_url='http://example.com/', event_types=[self.event_type]) # Trigger processing process_event(self.event.id) # Event is captured and POST request is triggered because event_type and user_uuid match requests_post.assert_called_once_with( self.web_hook.destination_url, json=self.payload, verify=settings.VERIFY_WEBHOOK_REQUESTS)
def test_notification(self): self.event_type = 'device_booking_is_accepted' self.event = EventFactory(event_type=self.event_type) logging_models.Feed.objects.create( scope=self.resource.project.customer, event=self.event) consumer_owner = structure_factories.UserFactory() self.resource.project.customer.add_user( consumer_owner, structure_models.CustomerRole.OWNER) email_hook = logging_models.EmailHook.objects.create( user=consumer_owner, email=consumer_owner.email, event_types=[self.event_type]) url = '%s%s/accept/' % (reverse('booking-resource-list'), self.resource.uuid.hex) self.client.post(url) process_event(self.event.id) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, [email_hook.email])
def test_notification_subject(self): self.assertFalse(models.EmailHook.objects.count()) tasks.process_event(self.event.id) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].subject, 'Test Subject')
def test_not_send_notification_if_wrong_project(self): self.assertFalse(models.EmailHook.objects.count()) self.feed.delete() self.event.save() tasks.process_event(self.event.id) self.assertEqual(len(mail.outbox), 0)
def test_not_send_notification_if_event_type_is_not_system_type(self): self.assertFalse(models.EmailHook.objects.count()) self.event.event_type = 'test_event_type' self.event.save() tasks.process_event(self.event.id) self.assertEqual(len(mail.outbox), 0)