예제 #1
0
    def test_only_a_user_who_created_a_class_can_update_it(self):
        user_1 = UserFactory()
        user_2 = UserFactory()
        class_1 = ClassroomFactory(created_by=user_1)
        class_2 = ClassroomFactory(created_by=user_2)

        self.assertTrue(class_1.can_update(user_1))
        self.assertFalse(class_1.can_update(user_2))

        self.assertFalse(class_2.can_update(user_1))
        self.assertTrue(class_2.can_update(user_2))
예제 #2
0
    def test_superuser_can_update_any_class(self):
        super_user = get_user_model().objects.create_superuser(
            username='******',
            email='*****@*****.**',
            password='******')
        user_1 = UserFactory()
        user_2 = UserFactory()
        class_1 = ClassroomFactory(created_by=user_1)
        class_2 = ClassroomFactory(created_by=user_2)

        self.assertTrue(class_1.can_update(super_user))
        self.assertTrue(class_2.can_update(super_user))
예제 #3
0
    def test_only_the_user_who_created_a_classroom_can_update_it(self):
        user_1 = UserFactory()
        user_2 = UserFactory()
        class_1 = ClassroomFactory(created_by=user_1)
        class_2 = ClassroomFactory(created_by=user_1)
        class_3 = ClassroomFactory(created_by=user_2)

        self.assertEqual(Classroom.objects.count(), 3)
        self.assertTrue(class_1.can_update(user_1))
        self.assertTrue(class_2.can_update(user_1))
        self.assertTrue(class_3.can_update(user_2))

        self.assertFalse(class_1.can_update(user_2))
        self.assertFalse(class_2.can_update(user_2))
        self.assertFalse(class_3.can_update(user_1))