-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
""" | ||
© Ocado Group | ||
Created on 14/12/2023 at 14:26:20(+00:00). | ||
""" | ||
|
||
from rest_framework.views import APIView | ||
|
||
from ....tests import APITestCase | ||
from ...permissions import InClass | ||
|
||
|
||
class TestInClass(APITestCase): | ||
""" | ||
Naming convention: | ||
test_{class_id}__{user_type} | ||
class_id: The id of a class. Options: | ||
- any_class: Any class. | ||
- in_class: A specific class the user is in. | ||
- not_in_class: A specific class the user is not in. | ||
user_type: The type of user. Options: | ||
- non_class_teacher: A teacher not in a class. | ||
- class_teacher: A teacher in a class. | ||
- student: A student. | ||
- indy: An independent. | ||
""" | ||
|
||
def test_any_class__non_class_teacher(self): | ||
""" | ||
Teacher without a class is not in any class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_any_class__class_teacher(self): | ||
""" | ||
Teacher with a class is in any class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_any_class__student(self): | ||
""" | ||
Student is in any class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_any_class__indy(self): | ||
""" | ||
Independent is not in any class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_not_in_class__non_class_teacher(self): | ||
""" | ||
Teacher without a class is not in a specific class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_not_in_class__class_teacher(self): | ||
""" | ||
Teacher with a class is not in a specific class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_not_in_class__student(self): | ||
""" | ||
Student is not in a specific class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_not_in_class__indy(self): | ||
""" | ||
Independent is not in a specific class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_in_class__class_teacher(self): | ||
""" | ||
Teacher with a class is in a specific class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_in_class__student(self): | ||
""" | ||
Student is in a specific class. | ||
""" | ||
|
||
raise NotImplementedError() # TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
© Ocado Group | ||
Created on 14/12/2023 at 14:26:20(+00:00). | ||
""" | ||
|
||
from rest_framework.views import APIView | ||
|
||
from ....tests import APITestCase | ||
from ...permissions import InSchool | ||
|
||
|
||
class TestInSchool(APITestCase): | ||
""" | ||
Naming convention: | ||
test_{school_id}__{user_type} | ||
school_id: The id of a school. Options: | ||
- any_school: Any school. | ||
- in_school: A specific school the user is in. | ||
- not_in_school: A specific school the user is not in. | ||
user_type: The type of user. Options: | ||
- non_school_teacher: A teacher not in a school. | ||
- school_teacher: A teacher in a school. | ||
- student: A student. | ||
- indy: An independent. | ||
""" | ||
|
||
# TODO: define unit tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
© Ocado Group | ||
Created on 14/12/2023 at 14:26:20(+00:00). | ||
""" | ||
|
||
from rest_framework.views import APIView | ||
|
||
from ....tests import APITestCase | ||
from ...permissions import IsIndependent | ||
|
||
|
||
class TestIsIndependent(APITestCase): | ||
""" | ||
Naming convention: | ||
test_{user_type} | ||
user_type: The type of user. Options: | ||
- teacher: A teacher. | ||
- student: A student. | ||
- indy: An independent. | ||
""" | ||
|
||
def test_teacher(self): | ||
""" | ||
Teacher is not any independent. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_student(self): | ||
""" | ||
Student is not any independent. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_indy(self): | ||
""" | ||
Independent is any independent. | ||
""" | ||
|
||
raise NotImplementedError() # TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
© Ocado Group | ||
Created on 14/12/2023 at 14:26:20(+00:00). | ||
""" | ||
|
||
from rest_framework.views import APIView | ||
|
||
from ....tests import APITestCase | ||
from ...permissions import IsStudent | ||
|
||
|
||
class TestIsStudent(APITestCase): | ||
""" | ||
Naming convention: | ||
test_{user_type}__{student_id} | ||
user_type: The type of user. Options: | ||
- teacher: A teacher. | ||
- student: A student. | ||
- indy: An independent. | ||
student_id: The ID of a student. Options: | ||
- any_student: User is any student. | ||
- not_any_student: User is not any student. | ||
- specific_student: User is a specific student. | ||
- not_specific_student User is not a specific student. | ||
""" | ||
|
||
def test_teacher__not_any_student(self): | ||
""" | ||
Teacher is not any student. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_teacher__not_specific_student(self): | ||
""" | ||
Teacher is not a specific student. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_indy__not_any_student(self): | ||
""" | ||
Independent is not any student. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_indy__not_specific_student(self): | ||
""" | ||
Independent is not a specific student. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_student__any_student(self): | ||
""" | ||
Student is any student. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_student__specific_student(self): | ||
""" | ||
Student is a specific student. | ||
""" | ||
|
||
raise NotImplementedError() # TODO | ||
|
||
def test_student__not_specific_student(self): | ||
""" | ||
Student is not a specific student. | ||
""" | ||
|
||
raise NotImplementedError() # TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
""" | ||
© Ocado Group | ||
Created on 14/12/2023 at 14:26:20(+00:00). | ||
""" | ||
|
||
from rest_framework.test import APIRequestFactory | ||
from rest_framework.views import APIView | ||
|
||
from ....tests import APITestCase | ||
from ...models import User | ||
from ...permissions import IsTeacher | ||
|
||
|
||
class TestIsTeacher(APITestCase): | ||
# TODO: test that students and independents do not get permission. | ||
""" | ||
Naming convention: | ||
test_{teacher_id}__{is_admin} | ||
teacher_id: The id of a teacher. Options: | ||
- id: A specific teacher. | ||
- none: Any teacher. | ||
is_admin: A flag for if the teacher is an admin. Options: | ||
- true: Teacher is an admin. | ||
- false: Teacher is a non-admin. | ||
- none: Teacher is an admin or a non-admin. | ||
""" | ||
|
||
fixtures = [ | ||
"users", | ||
"teachers", | ||
"schools", | ||
"classes", | ||
"students", | ||
] | ||
|
||
def setUp(self): | ||
self.user__1 = User.objects.get(pk=1) | ||
self.user__2 = User.objects.get(pk=2) | ||
|
||
assert self.user__1.teacher and self.user__1.teacher.is_admin | ||
assert self.user__2.teacher and not self.user__2.teacher.is_admin | ||
|
||
self.user__1__teacher = self.user__1.teacher | ||
self.user__2__teacher = self.user__2.teacher | ||
|
||
request_factory = APIRequestFactory() | ||
self.request__1 = request_factory.get("/") | ||
self.request__1.user = self.user__1 | ||
self.request__2 = request_factory.get("/") | ||
self.request__2.user = self.user__2 | ||
|
||
def test_none__none(self): | ||
""" | ||
Is any teacher. | ||
""" | ||
|
||
assert IsTeacher( | ||
teacher_id=None, | ||
is_admin=None, | ||
).has_permission(self.request__1, APIView()) | ||
|
||
def test_none__true(self): | ||
""" | ||
Is any admin teacher. | ||
""" | ||
|
||
assert IsTeacher( | ||
teacher_id=None, | ||
is_admin=True, | ||
).has_permission(self.request__1, APIView()) | ||
|
||
assert not IsTeacher( | ||
teacher_id=None, | ||
is_admin=True, | ||
).has_permission(self.request__2, APIView()) | ||
|
||
def test_none__false(self): | ||
""" | ||
Is any non-admin teacher. | ||
""" | ||
|
||
assert not IsTeacher( | ||
teacher_id=None, | ||
is_admin=False, | ||
).has_permission(self.request__1, APIView()) | ||
|
||
assert IsTeacher( | ||
teacher_id=None, | ||
is_admin=False, | ||
).has_permission(self.request__2, APIView()) | ||
|
||
def test_id__none(self): | ||
""" | ||
Is a specific teacher. | ||
""" | ||
|
||
assert IsTeacher( | ||
teacher_id=self.user__1__teacher.id, | ||
is_admin=None, | ||
).has_permission(self.request__1, APIView()) | ||
|
||
assert not IsTeacher( | ||
teacher_id=self.user__2__teacher.id, | ||
is_admin=None, | ||
).has_permission(self.request__1, APIView()) | ||
|
||
def test_id__true(self): | ||
""" | ||
Is a specific admin teacher. | ||
""" | ||
|
||
assert IsTeacher( | ||
teacher_id=self.user__1__teacher.id, | ||
is_admin=True, | ||
).has_permission(self.request__1, APIView()) | ||
|
||
assert not IsTeacher( | ||
teacher_id=self.user__2__teacher.id, | ||
is_admin=True, | ||
).has_permission(self.request__2, APIView()) | ||
|
||
def test_id__false(self): | ||
""" | ||
Is a specific non-admin teacher. | ||
""" | ||
|
||
assert not IsTeacher( | ||
teacher_id=self.user__1__teacher.id, | ||
is_admin=False, | ||
).has_permission(self.request__1, APIView()) | ||
|
||
assert IsTeacher( | ||
teacher_id=self.user__2__teacher.id, | ||
is_admin=False, | ||
).has_permission(self.request__2, APIView()) |