Exemplo n.º 1
0
 def test_enrolment_serializer__no_classes(self):
     self.enrolment.preferred_class = None
     self.enrolment.enrolled_class = None
     self.assertIsNone(
         EnrolmentSerializer(self.enrolment).data["preferred_class"])
     self.assertIsNone(
         EnrolmentSerializer(self.enrolment).data["enrolled_class"])
Exemplo n.º 2
0
 def test_enrolment_serializer_update__cannot_update_family(self):
     other_last_name = "Schmidt"
     other_family = create_test_family(last_name=other_last_name)
     data = dict(self.update_request)
     data["family"] = other_family.id
     serializer = EnrolmentSerializer(self.enrolment, data=data)
     self.assertFalse(serializer.is_valid())
 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,
     )
Exemplo n.º 5
0
 def test_enrolment_serializer_validate__invalid_update_students(
     self,
     mock_validate_class_in_session,
     validate_student_ids_in_family,
 ):
     serializer = EnrolmentSerializer(self.enrolment,
                                      data=self.update_request)
     self.assertFalse(serializer.is_valid())
     validate_student_ids_in_family.assert_called_once_with(
         [self.family.parent.id],
         self.family,
     )
     mock_validate_class_in_session.assert_not_called()
 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,
     )
Exemplo n.º 7
0
 def test_enrolment_serializer__validate_create(
     self,
     mock_validate_class_in_session,
     validate_student_ids_in_family,
 ):
     serializer = EnrolmentSerializer(None, data=self.update_request)
     self.assertTrue(serializer.is_valid())
     validate_student_ids_in_family.assert_called_once_with(
         [self.family.parent.id],
         self.family,
     )
     self.assertEqual(mock_validate_class_in_session.call_count, 2)
     mock_validate_class_in_session.assert_has_calls([
         call(self.class2, self.session),
         call(self.class1, self.session),
     ])
 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,
     )
Exemplo n.º 9
0
    def get_enrolment(self, obj):
        enrolment = self.context.get("enrolment")
        if enrolment is not None:
            return enrolment

        if obj.current_enrolment is not None:
            return EnrolmentSerializer(obj.current_enrolment).data

        return None
Exemplo n.º 10
0
class FamilySearchSerializer(serializers.HyperlinkedModelSerializer):
    parent = StudentListSerializer()
    children = StudentListSerializer(many=True)
    guests = StudentListSerializer(many=True)
    enrolments = EnrolmentSerializer(many=True)

    class Meta:
        model = Family
        fields = [
            "id",
            "email",
            "phone_number",
            "parent",
            "children",
            "guests",
            "enrolments",
        ]
Exemplo n.º 11
0
 def test_enrolment_serializer(self):
     self.assertEqual(
         {
             "id":
             self.enrolment.id,
             "family":
             self.family.id,
             "session":
             SessionListSerializer(self.session).data,
             "preferred_class":
             ClassListSerializer(self.class1).data,
             "enrolled_class":
             ClassListSerializer(self.class2).data,
             "status":
             self.enrolment.status,
             "students": [],
             "created_at":
             self.enrolment.created_at.replace(
                 tzinfo=timezone.utc).astimezone(tz=None).isoformat(),
             "is_guest":
             False,
         },
         EnrolmentSerializer(self.enrolment).data,
     )
Exemplo n.º 12
0
 def test_enrolment_serializer_validate__cannot_update_session(self):
     data = dict(self.update_request)
     data["session"] = self.other_session.id
     serializer = EnrolmentSerializer(self.enrolment, data=data)
     self.assertFalse(serializer.is_valid())
Exemplo n.º 13
0
 def get_enrolments(self, obj):
     enrolments = obj.enrolments.order_by("session__created_at")
     return EnrolmentSerializer(enrolments, many=True).data