예제 #1
0
    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'))
예제 #2
0
    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"))
예제 #3
0
    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'))
예제 #4
0
    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"))