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 * update teacher * merge from dev * fix child serializers
- Loading branch information
Showing
11 changed files
with
249 additions
and
82 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
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 |
---|---|---|
|
@@ -4,50 +4,41 @@ | |
""" | ||
|
||
from codeforlife.tests import ModelSerializerTestCase | ||
from codeforlife.user.models import Class, Student, User | ||
from codeforlife.user.models import ( | ||
Class, | ||
NonSchoolTeacherUser, | ||
SchoolTeacherUser, | ||
Student, | ||
TeacherUser, | ||
) | ||
|
||
from ...serializers import StudentSerializer | ||
from ...serializers import StudentSerializer, UserSerializer | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class StudentSerializerTestCase(ModelSerializerTestCase[Student]): | ||
class TestStudentSerializer(ModelSerializerTestCase[Student]): | ||
model_serializer_class = StudentSerializer | ||
fixtures = [ | ||
"non_school_teacher", | ||
"school_1", | ||
"school_2", | ||
] | ||
|
||
def test_validate_klass__teacher_not_in_school(self): | ||
""" | ||
Requesting teacher cannot assign a student to a class if they're not in | ||
a school. | ||
""" | ||
|
||
user = User.objects.get(email="[email protected]") | ||
assert user.teacher and not user.teacher.school | ||
|
||
self.assert_validate_field( | ||
name="klass", | ||
value="", | ||
error_code="teacher_not_in_school", | ||
context={"request": self.init_request("POST", user)}, | ||
) | ||
|
||
def test_validate_klass__does_not_exist(self): | ||
""" | ||
Requesting teacher cannot assign a student to a class that doesn't | ||
exist. | ||
""" | ||
|
||
user = User.objects.get(email="[email protected]") | ||
assert user.teacher and user.teacher.school | ||
user = SchoolTeacherUser.objects.get(email="[email protected]") | ||
|
||
self.assert_validate_field( | ||
name="klass", | ||
value="", | ||
error_code="does_not_exist", | ||
context={"request": self.init_request("POST", user)}, | ||
parent=UserSerializer( | ||
context={"request": self.request_factory.post(user=user)} | ||
), | ||
) | ||
|
||
def test_validate_klass__teacher_not_in_same_school(self): | ||
|
@@ -56,8 +47,7 @@ def test_validate_klass__teacher_not_in_same_school(self): | |
the same school. | ||
""" | ||
|
||
user = User.objects.get(email="[email protected]") | ||
assert user.teacher and user.teacher.school | ||
user = SchoolTeacherUser.objects.get(email="[email protected]") | ||
|
||
klass = Class.objects.exclude( | ||
teacher__school=user.teacher.school | ||
|
@@ -68,7 +58,9 @@ def test_validate_klass__teacher_not_in_same_school(self): | |
name="klass", | ||
value=klass.access_code, | ||
error_code="teacher_not_in_same_school", | ||
context={"request": self.init_request("POST", user)}, | ||
parent=UserSerializer( | ||
context={"request": self.request_factory.post(user=user)} | ||
), | ||
) | ||
|
||
def test_validate_klass__teacher_not_admin_or_class_owner(self): | ||
|
@@ -77,10 +69,8 @@ def test_validate_klass__teacher_not_admin_or_class_owner(self): | |
admin or they don't own the class. | ||
""" | ||
|
||
user = User.objects.get(email="[email protected]") | ||
assert ( | ||
user.teacher and user.teacher.school and not user.teacher.is_admin | ||
) | ||
user = SchoolTeacherUser.objects.get(email="[email protected]") | ||
assert not user.teacher.is_admin | ||
|
||
klass = ( | ||
Class.objects.filter(teacher__school=user.teacher.school) | ||
|
@@ -93,5 +83,21 @@ def test_validate_klass__teacher_not_admin_or_class_owner(self): | |
name="klass", | ||
value=klass.access_code, | ||
error_code="teacher_not_admin_or_class_owner", | ||
context={"request": self.init_request("POST", user)}, | ||
parent=UserSerializer( | ||
context={"request": self.request_factory.post(user=user)} | ||
), | ||
) | ||
|
||
def test_validate__not_student(self): | ||
""" | ||
Target user must be a student. | ||
""" | ||
|
||
teacher_user = TeacherUser.objects.first() | ||
assert teacher_user | ||
|
||
self.assert_validate( | ||
attrs={}, | ||
error_code="not_student", | ||
parent=UserSerializer(instance=teacher_user), | ||
) |
Oops, something went wrong.