def test_session_detail_serializer(self): self.assertEqual( { "id": self.session.id, "name": self.session.name, "families": [ FamilySerializer( self.family, context={ "enrolment": EnrolmentSerializer(self.enrolment).data, }, ).data, FamilySerializer( self.other_family, context={ "enrolment": EnrolmentSerializer(self.other_enrolment).data }, ).data, ], "fields": self.session.fields, "classes": [ ClassListSerializer(self.session_class).data, ClassListSerializer(self.other_session_class).data, ], }, SessionDetailSerializer(self.session, context=context).data, )
def test_class_detail_serializer(self): self.assertEqual( { "id": self.class1.id, "name": self.class1.name, "attendance": self.class1.attendance, "families": [ FamilySerializer( self.family1, context={ "request": None, "enrolment": EnrolmentSerializer(self.enrolment1).data, }, ).data, FamilySerializer( self.family2, context={ "request": None, "enrolment": EnrolmentSerializer(self.enrolment2).data, }, ).data, ], "days": self.class1.days, }, ClassDetailSerializer(self.class1, context={"request": None}).data, )
def test_family_serializer_enrolment__specified(self): data = FamilySerializer( self.family, context={ "request": None, "enrolment": EnrolmentSerializer(self.past_enrolment, context=context).data, }, ).data self.assertEqual( data.get("enrolment"), EnrolmentSerializer(self.past_enrolment, context=context).data, )
def test_family_serializer(self): self.assertEqual( { "id": self.family.id, "parent": StudentSerializer(self.family.parent, context=context).data, "email": self.family.email, "phone_number": self.family.home_number, "address": self.family.address, "preferred_comms": self.family.preferred_comms, "num_children": 2, "children": [ StudentSerializer(self.child1, context=context).data, StudentSerializer(self.child2, context=context).data, ], "guests": [StudentSerializer(self.guest, context=context).data], "enrolment": EnrolmentSerializer(self.current_enrolment, context=context).data, }, FamilySerializer(self.family, context=context).data, )
def test_get_family(self): url = reverse("family-detail", args=[self.family.id]) self.client.force_authenticate(self.user) response = self.client.get(url) payload = response.json() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertNotEqual(payload, FamilySerializer(self.family).data) self.assertEqual(payload, FamilyDetailSerializer(self.family).data)
def test_get_families(self): url = reverse("family-list") self.client.force_authenticate(self.user) response = self.client.get(url) payload = response.json() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( payload, [ FamilySerializer(self.family).data, FamilySerializer(self.other_family).data, ], ) self.assertNotEqual( payload, [ FamilyDetailSerializer(self.family).data, FamilyDetailSerializer(self.other_family).data, ], )
def get_families(self, obj): from registration.serializers import FamilySerializer return [ FamilySerializer( enrolment.family, context={ "request": self.context.get("request"), "enrolment": EnrolmentSerializer(enrolment).data, }, ).data for enrolment in obj.enrolments.filter( is_guest=False).order_by("created_at") ]