From 7740b66adaa4776344c8933d0a1d214c15e44852 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Thu, 25 Jul 2024 07:52:41 +0000 Subject: [PATCH] teachers in school --- codeforlife/tests/model_view_set.py | 3 ++- codeforlife/user/filters/user.py | 4 +++- codeforlife/user/views/user_test.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/codeforlife/tests/model_view_set.py b/codeforlife/tests/model_view_set.py index 1d0c1478..942620c7 100644 --- a/codeforlife/tests/model_view_set.py +++ b/codeforlife/tests/model_view_set.py @@ -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 ), @@ -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" diff --git a/codeforlife/user/filters/user.py b/codeforlife/user/filters/user.py index b8f02490..8def472f 100644 --- a/codeforlife/user/filters/user.py +++ b/codeforlife/user/filters/user.py @@ -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"] diff --git a/codeforlife/user/views/user_test.py b/codeforlife/user/views/user_test.py index 85b9da0e..577946b0 100644 --- a/codeforlife/user/views/user_test.py +++ b/codeforlife/user/views/user_test.py @@ -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()