示例#1
0
    def get_type(self, obj):
        """A get method for the AffiliateSerializer class' ``type`` attribute.

        Args:
            obj: The instance of the ContactInfo model class that is being serialized.

        Returns:
            The verbose label associated with the ``type`` of the ContactInfo object.
        """
        return ContactInfo.InfoType(obj.type).label
示例#2
0
    def test_contact_info_type_serializer_method_field(self):
        """Ensure that the contact info `type` serializer method field has the correct value in an API response.
        """
        url = reverse('event-list')

        response = self.client.get(f'{url}/{self.event.pk}/')
        contact = response.data['contacts'][0]

        self.assertEqual(
            ContactInfo.InfoType(self.contact.type).label, contact['type'])