Add tests

This commit is contained in:
Lorenz Padberg 2023-07-12 16:44:03 +02:00
parent 76fcb8b468
commit 6d665193da
1 changed files with 32 additions and 0 deletions

View File

@ -95,6 +95,38 @@ class ProjectQueryTestCase(SkillboxTestCase):
self.assertIsNone(result.errors)
self.assertEqual(len(result.data.get('projects')), 0)
def test_class_with_two_teachers_both_can_see_project(self):
# create class with two teachers
school_class3 = SchoolClassFactory(users=[self.teacher, self.teacher2, self.student1])
self.project1.final = True
self.project1.save()
self.assertEqual(Project.objects.count(), 1)
# teacher can see project
result = self.get_client(self.teacher).execute(self.query)
self.assertIsNone(result.errors)
self.assertEqual(len(result.data.get('projects')), 1)
# teacher2 can see project
result = self.get_client(self.teacher2).execute(self.query)
self.assertIsNone(result.errors)
self.assertEqual(len(result.data.get('projects')), 1)
def test_class_with_two_teachers_direct_final_project_access(self):
# create class with two teachers
school_class3 = SchoolClassFactory(users=[self.teacher, self.teacher2, self.student1])
self.project1.final = True
self.project1.save()
# student can access own project directly
self._test_direct_project_access(self.student1, True)
# teacher of student can access project, as it's final
self._test_direct_project_access(self.teacher, True)
# other teacher can't access project, as it's not final
self._test_direct_project_access(self.teacher2, True)
# non-owner can't access project
self._test_direct_project_access(self.student2, False)
def test_direct_project_access(self):
# student can access own project directly
self._test_direct_project_access(self.student1, True)