def setUpTestData(cls):
        AutomaticEmailFactory.create(
            type=EmailTypeChoices.review_required,
            body="Review is required!",
            subject="Review",
        )
        AutomaticEmailFactory.create(
            type=EmailTypeChoices.changes_required,
            body="Changes are required!",
            subject="Changes",
        )

        record_manager = RoleFactory.create(record_manager=True)
        process_owner = RoleFactory.create(process_owner=True)

        user_author = UserFactory.create(
            role=record_manager, email="*****@*****.**"
        )
        user_reviewer = UserFactory.create(
            role=process_owner, email="*****@*****.**"
        )

        destruction_list = DestructionListFactory.create(author=user_author)
        DestructionListAssigneeFactory.create(
            destruction_list=destruction_list, assignee=user_reviewer
        )

        cls.destruction_list = destruction_list
        cls.user_author = user_author
        cls.user_reviewer = user_reviewer
예제 #2
0
    def test_multiple_lists_with_assignees_that_need_reminders(self):
        role = RoleFactory.create(can_review_destruction=True)

        # Create 2 destruction lists
        destruction_list_1 = DestructionListFactory.create()
        destruction_list_2 = DestructionListFactory.create()
        assignees_1 = DestructionListAssigneeFactory.create_batch(
            size=2, destruction_list=destruction_list_1, assignee__role=role)
        assignees_2 = DestructionListAssigneeFactory.create_batch(
            size=2, destruction_list=destruction_list_2, assignee__role=role)

        # Create 2 reviewers per list and assign one of them
        first_reviewer_1 = assignees_1[0]
        destruction_list_1.assignee = first_reviewer_1.assignee
        destruction_list_1.save()
        first_reviewer_1.assigned_on = timezone.make_aware(
            datetime(2021, 11, 12))
        first_reviewer_1.save()

        first_reviewer_2 = assignees_2[0]
        destruction_list_2.assignee = first_reviewer_2.assignee
        destruction_list_2.save()
        first_reviewer_2.assigned_on = timezone.make_aware(
            datetime(2021, 11, 12))
        first_reviewer_2.save()

        check_if_reviewers_need_reminder()

        self.assertEqual(len(mail.outbox), 2)
        recipients = [email_sent.to[0] for email_sent in mail.outbox]
        self.assertCountEqual(
            recipients,
            [first_reviewer_1.assignee.email, first_reviewer_2.assignee.email],
        )
    def test_create_archivist_with_correct_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.archivist,
            can_review_destruction=True,
        )

        role.clean()  # Shouldn't raise exceptions
    def test_create_archivist_with_insufficient_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.record_manager,
            can_review_destruction=False,
        )

        with self.assertRaises(ValidationError):
            role.clean()
    def test_create_record_manager_with_correct_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.record_manager,
            can_start_destruction=True,
            can_view_case_details=True,
        )

        role.clean()  # Shouldn't raise exceptions
    def test_create_other_role_without_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.other,
            can_review_destruction=False,
            can_start_destruction=False,
            can_view_case_details=False,
        )

        role.clean()  # Shouldn't raise exceptions
    def test_create_functional_admin_with_correct_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.functional_admin,
            can_review_destruction=True,
            can_start_destruction=True,
            can_view_case_details=True,
        )

        role.clean()  # Shouldn't raise exceptions
    def test_create_process_owner_with_insufficient_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.process_owner,
            can_review_destruction=True,
            can_view_case_details=False,
        )

        with self.assertRaises(ValidationError):
            role.clean()
    def test_create_record_manager_with_insufficient_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.record_manager,
            can_start_destruction=False,
            can_view_case_details=True,
        )

        with self.assertRaises(ValidationError):
            role.clean()
    def test_create_functional_admin_with_insufficient_permissions(self):
        role = RoleFactory.create(
            type=RoleTypeChoices.functional_admin,
            can_review_destruction=True,
            can_view_case_details=False,
            can_start_destruction=True,
        )

        with self.assertRaises(ValidationError):
            role.clean()
    def test_assignee_is_no_reviewer(self):
        role = RoleFactory.create(can_review_destruction=False)
        destruction_list = DestructionListFactory.create()
        reviewer = DestructionListAssigneeFactory.create(
            destruction_list=destruction_list, assignee__role=role)
        destruction_list.assignee = reviewer.assignee
        destruction_list.save()
        reviewer.assigned_on = timezone.make_aware(datetime(2021, 11, 12))
        reviewer.save()

        self.assertFalse(destruction_list.is_review_overdue)
    def setUpTestData(cls):
        record_manager = RoleFactory.create(record_manager=True)
        process_owner = RoleFactory.create(process_owner=True)
        archivaris = RoleFactory.create(archivaris=True)

        user1 = UserFactory.create(role=record_manager)
        user2 = UserFactory.create(role=process_owner)
        user3 = UserFactory.create(role=archivaris)

        destruction_list = DestructionListFactory.create(author=user1)
        DestructionListAssigneeFactory.create(
            destruction_list=destruction_list, assignee=user2
        )
        DestructionListAssigneeFactory.create(
            destruction_list=destruction_list, assignee=user3
        )

        cls.destruction_list = destruction_list
        cls.user1 = user1
        cls.user2 = user2
        cls.user3 = user3
예제 #13
0
    def test_assignee_not_reviewer(self):
        role = RoleFactory.create(can_review_destruction=False)
        destruction_list = DestructionListFactory.create()
        not_reviewer = DestructionListAssigneeFactory.create(
            destruction_list=destruction_list, assignee__role=role)
        destruction_list.assignee = not_reviewer.assignee
        destruction_list.save()
        not_reviewer.assigned_on = timezone.make_aware(datetime(2021, 11, 12))
        not_reviewer.save()

        check_if_reviewers_need_reminder()

        self.assertEqual(len(mail.outbox), 0)
예제 #14
0
    def test_no_reminder_needed(self):
        role = RoleFactory.create(can_review_destruction=True)
        destruction_list = DestructionListFactory.create()
        assignees = DestructionListAssigneeFactory.create_batch(
            size=2, destruction_list=destruction_list, assignee__role=role)
        first_reviewer = assignees[0]
        destruction_list.assignee = first_reviewer.assignee
        destruction_list.save()
        first_reviewer.assigned_on = timezone.make_aware(datetime(
            2021, 11, 15))
        first_reviewer.save()

        check_if_reviewers_need_reminder()

        self.assertEqual(len(mail.outbox), 0)
예제 #15
0
    def test_only_one_reminder_sent(self):
        role = RoleFactory.create(can_review_destruction=True)
        destruction_list = DestructionListFactory.create()
        first_reviewer = DestructionListAssigneeFactory.create(
            destruction_list=destruction_list, assignee__role=role)
        destruction_list.assignee = first_reviewer.assignee
        destruction_list.save()
        first_reviewer.assigned_on = timezone.make_aware(datetime(
            2021, 11, 12))
        first_reviewer.reminder_sent = True
        first_reviewer.save()

        check_if_reviewers_need_reminder()

        self.assertEqual(0, len(mail.outbox))
예제 #16
0
    def test_no_email_template_configured(self):
        AutomaticEmail.objects.all().delete()

        role = RoleFactory.create(can_review_destruction=True)
        destruction_list = DestructionListFactory.create()
        assignees = DestructionListAssigneeFactory.create_batch(
            size=2, destruction_list=destruction_list, assignee__role=role)
        first_reviewer = assignees[0]
        destruction_list.assignee = first_reviewer.assignee
        destruction_list.save()
        first_reviewer.assigned_on = timezone.make_aware(datetime(
            2021, 11, 12))
        first_reviewer.save()

        check_if_reviewers_need_reminder()

        self.assertEqual(0, len(mail.outbox))
예제 #17
0
    def test_email_reviewer_when_assigned_too_long(self):
        role = RoleFactory.create(can_review_destruction=True)
        destruction_list = DestructionListFactory.create()
        assignees = DestructionListAssigneeFactory.create_batch(
            size=2, destruction_list=destruction_list, assignee__role=role)
        first_reviewer = assignees[0]
        destruction_list.assignee = first_reviewer.assignee
        destruction_list.save()
        first_reviewer.assigned_on = timezone.make_aware(datetime(
            2021, 11, 12))
        first_reviewer.save()

        check_if_reviewers_need_reminder()

        self.assertEqual(1, len(mail.outbox))
        self.assertEqual(first_reviewer.assignee.email, mail.outbox[0].to[0])
        first_reviewer.refresh_from_db()
        self.assertTrue(first_reviewer.reminder_sent)