Beispiel #1
0
    def test_flip_bookmark(self):
        """
        Test if a user can flip the bookmarked status.

        :return: None
        """
        self.client.force_authenticate(self.coordinator)
        inbox = create_inbox("TestInbox", "TestInbox")
        self.coordinator.add_inbox(inbox, Role.MANAGER)
        relation = self.coordinator.get_entry_by_inbox(inbox)
        self.assertFalse(relation.is_bookmarked)

        data = {
            "inbox_id": inbox.id,
        }

        # Check if bookmarked can be flipped to true
        response = self.client.post(reverse("api_me_inboxes"), data)
        self.assertTrue(response.status_code, 200)

        relation = self.coordinator.get_entry_by_inbox(inbox)
        self.assertTrue(relation.is_bookmarked)

        # Check if bookrmarked can be flipped to false
        response = self.client.post(reverse("api_me_inboxes"), data)
        self.assertTrue(response.status_code, 200)

        relation = self.coordinator.get_entry_by_inbox(inbox)
        self.assertFalse(relation.is_bookmarked)
Beispiel #2
0
 def test_inboxes_page_student_200(self):
     """
     Authorized users should see the inboxes page.
     """
     self.client.force_authenticate(self.student)
     inbox = create_inbox("TestInbox", "TestInbox")
     self.student.add_inbox(inbox, Role.GUEST)
     response = self.client.get(reverse("api_me_inboxes"))
     self.assertEqual(response.status_code, 200)
Beispiel #3
0
    def test_inbox_sorting(self):
        """
        Test if Inboxes are sorted by user joined date
        """
        self.client.force_authenticate(self.student)

        inbox1 = create_inbox("TestInbox1", "TestInbox1")
        inbox2 = create_inbox("TestInbox2", "TestInbox2")
        inbox3 = create_inbox("TestInbox3", "TestInbox3")
        self.student.add_inbox(inbox1, Role.GUEST)
        self.student.add_inbox(inbox3, Role.GUEST)
        self.student.add_inbox(inbox2, Role.GUEST)

        response = self.client.get(reverse("api_me_inboxes"))
        self.assertTrue(response.status_code, 200)

        self.assertEqual(response.data[0]["inbox"]["name"], "TestInbox2")
        self.assertEqual(response.data[1]["inbox"]["name"], "TestInbox3")
Beispiel #4
0
    def setUp(self):
        """
        Setup for each of these tests.

        :return: None.
        """
        self.client = APIClient()
        self.inbox1 = create_inbox("coures1", "c1")
        self.inbox2 = create_inbox("coures2", "c2")
        self.inbox3 = create_inbox("coures3", "c3")
        self.manager1 = User.objects.create(username="******", email="*****@*****.**", password="******")
        self.manager1.add_inbox(self.inbox1)
        self.manager1.set_role_for_inbox(self.inbox1, Role.MANAGER)
        self.ta1 = User.objects.create(username="******", password="******")
        self.ta1.add_inbox(self.inbox1)
        self.ta1.add_inbox(self.inbox3)
        self.ta1.set_role_for_inbox(self.inbox1, Role.AGENT)
        self.ta2 = User.objects.create(username="******", password="******")
        self.ta2.add_inbox(self.inbox1)
        self.ta2.set_role_for_inbox(self.inbox1, Role.AGENT)
        self.ta3 = User.objects.create(username="******", password="******")
        self.ta3.add_inbox(self.inbox1)
        self.ta3.set_role_for_inbox(self.inbox1, Role.MANAGER)
        self.ta4 = User.objects.create(username="******", password="******")
        self.ta4.add_inbox(self.inbox2)
        self.ta4.set_role_for_inbox(self.inbox2, Role.MANAGER)
        self.ta5 = User.objects.create(username="******", password="******")
        self.ta5.add_inbox(self.inbox2)
        self.ta5.set_role_for_inbox(self.inbox2, Role.AGENT)
        self.student1 = User.objects.create(username="******", password="******")
        self.student1.add_inbox(self.inbox1)
        self.student1.set_role_for_inbox(self.inbox1, Role.GUEST)
        self.student2 = User.objects.create(username="******", password="******")
        self.student2.add_inbox(self.inbox1)
        self.student2.set_role_for_inbox(self.inbox1, Role.GUEST)
        self.student3 = User.objects.create(username="******", password="******")

        self.ticket1 = create_ticket(author=self.student1, assignee=self.ta5, inbox=self.inbox2)
        self.ticket2 = create_ticket(author=self.student1, assignee=self.ta4, inbox=self.inbox2)
        self.ticket3 = create_ticket(author=self.student1, assignee=self.ta4, inbox=self.inbox2)
        self.ticket4 = create_ticket(author=self.student1, assignee=self.ta4, inbox=self.inbox1)
        self.ticket5 = create_ticket(author=self.student1, assignee=self.ta4, inbox=self.inbox1)
Beispiel #5
0
    def test_inboxes_page_coordinator_200(self):
        """
        Authorized users should see the inboxes page.

        :return: None.
        """
        self.client.force_authenticate(self.coordinator)
        inbox = create_inbox("TestInbox", "TestInbox")
        self.coordinator.add_inbox(inbox, Role.MANAGER)
        response = self.client.get(reverse("api_me_inboxes"))
        self.assertEqual(response.status_code, 200)
Beispiel #6
0
    def test_bookmark_unrelated(self):
        """
        Test if unrelated user can bookmark inbox
        """
        student2 = User.objects.create_user(username="******",
                                            email="*****@*****.**",
                                            password="******",
                                            is_staff=False)
        self.client.force_authenticate(student2)
        inbox = create_inbox("TestInbox", "TestInbox")
        data = {
            "inbox_id": inbox.id,
        }

        with self.assertRaises(ValueError):
            self.client.post("/api/me/inboxes", data)
Beispiel #7
0
    def setUp(self):
        """
        Set up the database for the inbox related tests.
        """
        self.client = APIClient()
        self.student = User.objects.create_user(username="******",
                                                email="*****@*****.**",
                                                password="******",
                                                is_staff=False)
        self.student.set_password("test12345")
        self.student.save()

        self.student2 = User.objects.create_user(username="******",
                                                 email="*****@*****.**")
        self.student3 = User.objects.create_user(username="******",
                                                 email="*****@*****.**")

        self.assistant = User.objects.create_user(
            username="******",
            email="*****@*****.**",
            password="******",
            is_staff=False)
        self.assistant.set_password("test12345")
        self.assistant.save()

        self.coordinator = User.objects.create_user(
            username="******",
            email="*****@*****.**",
            password="******",
            is_staff=False)
        self.coordinator.set_password("test12345")
        self.coordinator.save()

        self.coordinator_2 = User.objects.create_user(
            username="******",
            email="*****@*****.**",
            password="******",
            is_staff=False)

        self.inbox = create_inbox("inbox_1_name", "inbox_1_code")
        self.inbox_2 = create_inbox("inbox_2_name", "inbox_2_code")

        self.student.add_inbox(self.inbox, Role.GUEST)
        self.student.add_inbox(self.inbox_2, Role.GUEST)
        self.student2.add_inbox(self.inbox_2, Role.GUEST)
        self.student3.add_inbox(self.inbox, Role.GUEST)
        self.assistant.add_inbox(self.inbox, Role.AGENT)
        self.coordinator.add_inbox(self.inbox, Role.MANAGER)
        self.coordinator_2.add_inbox(self.inbox_2, Role.MANAGER)
        self.label = create_label(inbox=self.inbox)
        self.label_2 = create_label(inbox=self.inbox_2)
        self.invisible_label = Label.objects.create(name="invisible",
                                                    inbox=self.inbox,
                                                    is_visible_to_guest=False)
        self.disabled_label = Label.objects.create(name="disabled",
                                                   inbox=self.inbox,
                                                   is_active=False)

        self.template_names = [
            ("api_inbox_user", (self.inbox.id, self.student.id)),
            ("api_inbox_users", (self.inbox.id, )),
            ("api_inbox_labels", (self.inbox.id, )),
            ("api_inbox_labels", (self.inbox.id, )),
            ("api_inbox_settings", (self.inbox.id, )),
            ("api_new_inbox_label", (self.inbox.id, )),
            ("api_inbox_statistics", (self.inbox.id, )),
            ("api_inbox_label", (self.inbox.id, self.label.id)),
        ]