Beispiel #1
0
class TestUserNotificationHandler(TestCase):
    def setUp(self):
        self.department = DepartmentFactory()
        self.user = UserFactory()
        self.user.groups.add(self.department.groups.get(system_name='user'))
        self.user.save()
        self.application = ApplicationFactory(department=self.department)
        self.environment = EnvironmentFactory(application=self.application)
        self.task = TaskFactory(application=self.application)

    def test_process(self):
        execution = ExecutionFactory(environment=self.environment, task=self.task, user=self.user)
        event = ExecutionFinish(self.department.id, execution=execution)
        UserNotificationHandler().process(event)
        self.assertEqual(len(mail.outbox), 1)

    def test_process_with_user_who_cant_view_environment(self):
        remove_perm('core.view_environment', self.user.groups.first(), self.environment)
        execution = ExecutionFactory(environment=self.environment, task=self.task, user=self.user)
        event = ExecutionFinish(self.department.id, execution=execution)
        UserNotificationHandler().process(event)
        self.assertEqual(len(mail.outbox), 0)

    def test_process_with_user_who_cant_view_task(self):
        remove_perm('task.view_task', self.user.groups.first(), self.task)
        execution = ExecutionFactory(environment=self.environment, task=self.task, user=self.user)
        event = ExecutionFinish(self.department.id, execution=execution)
        UserNotificationHandler().process(event)
        self.assertEqual(len(mail.outbox), 0)
Beispiel #2
0
 def setUp(self):
     self.department = DepartmentFactory()
     self.user = UserFactory()
     self.user.groups.add(self.department.groups.get(system_name='user'))
     self.user.save()
     self.application = ApplicationFactory(department=self.department)
     self.environment = EnvironmentFactory(application=self.application)
     self.task = TaskFactory(application=self.application)
Beispiel #3
0
class TestNotificationPreferences(TestCase):
    def setUp(self):
        self.department = DepartmentFactory()
        self.user = UserFactory()
        self.user.groups.add(self.department.groups.get(system_name='user'))
        self.user.save()
        self.application = ApplicationFactory(department=self.department)

    def test_on_save_application(self):
        content_type = ContentType.objects.get_for_model(type(self.application))
        notifications = NotificationPreferences.objects.filter(user=self.user,
                                                               content_type=content_type,
                                                               object_id=self.application.id,
                                                               event_type='ExecutionFinish',
                                                               is_active=True)
        self.assertEqual(len(notifications), 1)
Beispiel #4
0
 def setUp(self):
     self.department = DepartmentFactory()
     self.user = UserFactory()
     self.user.groups.add(self.department.groups.get(system_name='user'))
     self.user.save()
     self.application = ApplicationFactory(department=self.department)
     self.environment = EnvironmentFactory(application=self.application)
     self.task = TaskFactory(application=self.application)
Beispiel #5
0
class TestUserNotificationHandler(TestCase):
    def setUp(self):
        self.department = DepartmentFactory()
        self.user = UserFactory()
        self.user.groups.add(self.department.groups.get(system_name='user'))
        self.user.save()
        self.application = ApplicationFactory(department=self.department)
        self.environment = EnvironmentFactory(application=self.application)
        self.task = TaskFactory(application=self.application)

    def test_process(self):
        execution = ExecutionFactory(environment=self.environment,
                                     task=self.task,
                                     user=self.user)
        event = ExecutionFinish(self.department.id, execution=execution)
        UserNotificationHandler().process(event)
        self.assertEqual(len(mail.outbox), 1)

    def test_process_with_user_who_cant_view_environment(self):
        remove_perm('core.view_environment', self.user.groups.first(),
                    self.environment)
        execution = ExecutionFactory(environment=self.environment,
                                     task=self.task,
                                     user=self.user)
        event = ExecutionFinish(self.department.id, execution=execution)
        UserNotificationHandler().process(event)
        self.assertEqual(len(mail.outbox), 0)

    def test_process_with_user_who_cant_view_task(self):
        remove_perm('task.view_task', self.user.groups.first(), self.task)
        execution = ExecutionFactory(environment=self.environment,
                                     task=self.task,
                                     user=self.user)
        event = ExecutionFinish(self.department.id, execution=execution)
        UserNotificationHandler().process(event)
        self.assertEqual(len(mail.outbox), 0)
Beispiel #6
0
 def setUpClass(cls):
     cls.user = UserFactory(is_superuser=cls.logged_is_superuser)
     cls.setup_department()