Skip to content

Commit

Permalink
teachers in school
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jul 25, 2024
1 parent 4dcbd9f commit 7740b66
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion codeforlife/tests/model_view_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def retrieve(

def list(
self,
models: t.Iterable[AnyModel],
models: t.Collection[AnyModel],
status_code_assertion: APIClient.StatusCodeAssertion = (
status.HTTP_200_OK
),
Expand Down Expand Up @@ -234,6 +234,7 @@ def list(

def _make_assertions(response_json: JsonDict):
json_models = t.cast(t.List[JsonDict], response_json["data"])
assert len(models) == len(json_models)
for model, json_model in zip(models, json_models):
self._test_case.assert_serialized_model_equals_json_model(
model, json_model, action="list", request_method="get"
Expand Down
4 changes: 3 additions & 1 deletion codeforlife/user/filters/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class UserFilterSet(filters.FilterSet):
"exact",
)

teachers_in_school = filters.NumberFilter("new_teacher__school")

class Meta:
model = User
fields = ["students_in_class"]
fields = ["students_in_class", "teachers_in_school"]
12 changes: 12 additions & 0 deletions codeforlife/user/views/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ def test_list__students_in_class(self):
filters={"students_in_class": klass.access_code},
)

def test_list__teachers_in_school(self):
"""Can successfully list teacher-users in a school."""
user = self.admin_school_teacher_user
school_teacher_users = user.teacher.school_teacher_users.all()
assert school_teacher_users.exists()

self.client.login_as(user)
self.client.list(
models=school_teacher_users,
filters={"teachers_in_school": user.teacher.school.id},
)

def test_retrieve(self):
"""Can successfully retrieve users."""
user = AdminSchoolTeacherUser.objects.first()
Expand Down

0 comments on commit 7740b66

Please sign in to comment.