def test_should_serialize_with_default_serializer(self): field = SchemaField(of_type=self.test_schema_cls) serialized_dict = field.serialize( request_factory.get_request(), self.test_entity_cls('John', 'Smith')) assert_that(serialized_dict['name'], equal_to('John'))
def test_should_serialize_with_overridden_serializer(self): test_schema_cls = self.test_schema_cls request = request_factory.get_request(context_params={"crud_action": CrudActions.UPDATE_DETAIL}) class TestSerializer(DefaultEntitySerializer): def serialize_entity(self, request, entity): return {"name": entity.surname} field = SchemaField(of_type=self.test_schema_cls, serializer_cls=TestSerializer) response_dict = field.serialize(request, self.test_entity_cls("John", "Smith")) assert_that(response_dict["name"], equal_to("Smith"))
def test_should_serialize_with_overridden_serializer(self): test_schema_cls = self.test_schema_cls request = request_factory.get_request( context_params={'crud_action': CrudActions.UPDATE_DETAIL}) class TestSerializer(DefaultEntitySerializer): def serialize_entity(self, request, entity): return {'name': entity.surname} field = SchemaField(of_type=self.test_schema_cls, serializer_cls=TestSerializer) response_dict = field.serialize(request, self.test_entity_cls('John', 'Smith')) assert_that(response_dict['name'], equal_to('Smith'))
def test_should_serialize_with_default_serializer(self): field = SchemaField(of_type=self.test_schema_cls) serialized_dict = field.serialize(request_factory.get_request(), self.test_entity_cls("John", "Smith")) assert_that(serialized_dict["name"], equal_to("John"))