def test_event_type_serializer_method_field(self): """Ensure that the event `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}/') self.assertEqual( Event.EventType(self.event.type).label, response.data['type'])
def get_type(self, obj): """A get method for the EventSerializer class' ``type`` attribute. Args: obj: The Event object that is being serialized. Returns: The verbose label associated with the ``type`` of the Event object. """ return Event.EventType(obj.type).label
def test_event_created(self, event_created): """Ensure that the `event_created` task is run with the correct arguments when a new Event object is created and saved. """ event = Event(type=Event.EventType.WORKSHOP, topics=['AI/ML'], start=timezone.now(), end=timezone.now() + timedelta(days=2)) event.save() self.assertTrue(event_created.called) self.assertEqual( Event.EventType(event.type).label, event_created.call_args[0][0]) self.assertEqual(event.start, event_created.call_args[0][1])