generated from ocadotechnology/codeforlife-template-backend
-
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.
* create school * remove is_unique_email action * merge from development * fix unit tests * Merge branch 'development' into create_class * everything but the serializer * fix: create class * Merge branch 'development' into create_class * fix feedback * use py package v0.12.8 * feedback
- Loading branch information
Showing
11 changed files
with
369 additions
and
20 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,123 @@ | ||
""" | ||
© Ocado Group | ||
Created on 05/02/2024 at 15:31:59(+00:00). | ||
""" | ||
|
||
from codeforlife.tests import ModelSerializerTestCase | ||
from codeforlife.user.models import Class, SchoolTeacherUser, Teacher | ||
|
||
from ...serializers import ClassSerializer | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class ClassSerializerTestCase(ModelSerializerTestCase[Class]): | ||
model_serializer_class = ClassSerializer | ||
fixtures = ["school_1"] | ||
|
||
def setUp(self): | ||
self.school_teacher_user = SchoolTeacherUser.objects.get( | ||
email="[email protected]" | ||
) | ||
self.class_1 = Class.objects.get(name="Class 1 @ School 1") | ||
|
||
def test_validate_teacher__does_not_exist(self): | ||
""" | ||
Teacher must exist. | ||
""" | ||
|
||
self.assert_validate_field( | ||
name="teacher", | ||
value=-1, | ||
error_code="does_not_exist", | ||
) | ||
|
||
def test_validate_teacher__not_in_school(self): | ||
""" | ||
Teacher must be in school. | ||
""" | ||
|
||
teacher = Teacher.objects.exclude( | ||
school=self.school_teacher_user.teacher.school | ||
).first() | ||
assert teacher | ||
|
||
self.assert_validate_field( | ||
name="teacher", | ||
value=teacher.id, | ||
error_code="not_in_school", | ||
context={ | ||
"request": self.init_request("POST", self.school_teacher_user) | ||
}, | ||
) | ||
|
||
def test_validate_teacher__not_admin(self): | ||
""" | ||
Teacher cannot assign another teacher if they're not an admin. | ||
""" | ||
|
||
assert not self.school_teacher_user.teacher.is_admin | ||
|
||
teacher = ( | ||
Teacher.objects.filter( | ||
school=self.school_teacher_user.teacher.school | ||
) | ||
.exclude(pk=self.school_teacher_user.teacher.pk) | ||
.first() | ||
) | ||
assert teacher | ||
|
||
self.assert_validate_field( | ||
name="teacher", | ||
value=teacher.id, | ||
error_code="not_admin", | ||
context={ | ||
"request": self.init_request("POST", self.school_teacher_user) | ||
}, | ||
) | ||
|
||
def test_validate_name__name_not_unique(self): | ||
""" | ||
Class names must be unique per school. | ||
""" | ||
|
||
self.assert_validate_field( | ||
name="name", | ||
value=self.class_1.name, | ||
error_code="name_not_unique", | ||
context={ | ||
"request": self.init_request("POST", self.school_teacher_user) | ||
}, | ||
) | ||
|
||
def test_create__teacher(self): | ||
""" | ||
Can successfully create with setting the teacher field. | ||
""" | ||
|
||
self.assert_create( | ||
{ | ||
"name": "ExampleClass", | ||
"teacher": { | ||
"id": self.school_teacher_user.teacher.id, | ||
}, | ||
"classmates_data_viewable": False, | ||
} | ||
) | ||
|
||
def test_create__no_teacher(self): | ||
""" | ||
Can successfully create without setting the teacher field. | ||
""" | ||
|
||
self.assert_create( | ||
{ | ||
"name": "ExampleClass", | ||
"classmates_data_viewable": False, | ||
}, | ||
new_data={ | ||
"teacher": self.school_teacher_user.teacher.id, | ||
}, | ||
context={ | ||
"request": self.init_request("POST", self.school_teacher_user), | ||
}, | ||
) |
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
Oops, something went wrong.