def test_response_spec_not_found(self, spy_get_response_spec, spy_marshal_schema_object, mock_request, view_response, expect_exernal_renderer_exception):
        mock_request.response.status_code = 400
        system = {'request': mock_request}
        renderer = self.renderer_factory(info=self.info)

        rendered_value = None
        expected_rendered_value = None
        if expect_exernal_renderer_exception:
            with pytest.raises(Exception):
                # Expect exception because datetime.date object cannot be serialized by JSON pyramid renderer
                rendered_value = renderer(view_response, system)
        else:
            rendered_value = renderer(view_response, system)
            expected_rendered_value = json.dumps(view_response)

        spy_get_response_spec.assert_called_once_with(
            op=mock_request.operation,
            status_code=mock_request.response.status_code,
        )
        assert not spy_marshal_schema_object.called
        assert rendered_value == expected_rendered_value
示例#2
0
    def test_rendering_operation_not_found(self, mock_get_response_spec, mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(renderer_factory=self.external_renderer_factory)
        self.mock_request.operation = None

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        assert not mock_get_response_spec.called
        assert not mock_marshal_schema_object.called
        self.external_renderer_factory.return_value.assert_called_once_with(
            self.value_to_render,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value
示例#3
0
    def test_rendering_operation_not_found(self, mock_get_response_spec, mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(renderer_factory=self.external_renderer_factory)
        self.mock_request.operation = None

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        assert not mock_get_response_spec.called
        assert not mock_marshal_schema_object.called
        self.external_renderer_factory.return_value.assert_called_once_with(
            self.value_to_render,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value
示例#4
0
    def test_no_errors(self, spy_get_response_spec, spy_marshal_schema_object, swagger_spec, mock_request, view_response, expected_rendered_value):
        system = {'request': mock_request}
        renderer = self.renderer_factory(info=self.info)
        rendered_value = renderer(view_response, system)

        spy_get_response_spec.assert_called_once_with(
            op=mock_request.operation,
            status_code=mock_request.response.status_code,
        )
        spy_marshal_schema_object.assert_called_once_with(
            schema_object_spec=self.swagger_spec_dict['paths']['/endpoint']['get']['responses']['200']['schema'],
            swagger_spec=swagger_spec,
            value=view_response,
        )

        assert rendered_value == expected_rendered_value
示例#5
0
    def test_marshaling_raise_exception(self, spy_get_response_spec, spy_marshal_schema_object, swagger_spec, mock_request):
        system = {'request': mock_request}
        value_to_renderer = {'date': datetime.date.today().isoformat()}

        renderer = self.renderer_factory(info=self.info)
        rendered_value = renderer(value_to_renderer, system)

        spy_get_response_spec.assert_called_once_with(
            op=mock_request.operation,
            status_code=mock_request.response.status_code,
        )
        spy_marshal_schema_object.assert_called_once_with(
            schema_object_spec=self.swagger_spec_dict['paths']['/endpoint']['get']['responses']['200']['schema'],
            swagger_spec=swagger_spec,
            value=value_to_renderer,
        )
        assert rendered_value == json.dumps(value_to_renderer)
示例#6
0
    def test_rendering_response_without_schema(self, mock_get_response_spec, mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(renderer_factory=self.external_renderer_factory)
        mock_get_response_spec.return_value = {'200': {'description': ''}}

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        mock_get_response_spec.assert_called_once_with(
            op=self.mock_request.operation,
            status_code=self.mock_request.response.status_code,
        )
        assert not mock_marshal_schema_object.called
        self.external_renderer_factory.return_value.assert_called_once_with(
            self.value_to_render,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value
示例#7
0
    def test_rendering_response_spec_not_found(self, mock_get_response_spec, mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(renderer_factory=self.external_renderer_factory)
        mock_get_response_spec.side_effect = MatchingResponseNotFound

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        mock_get_response_spec.assert_called_once_with(
            op=self.mock_request.operation,
            status_code=self.mock_request.response.status_code,
        )
        assert not mock_marshal_schema_object.called
        self.external_renderer_factory.return_value.assert_called_once_with(
            self.value_to_render,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value
示例#8
0
    def test_rendering_response_spec_not_found(self, mock_get_response_spec, mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(renderer_factory=self.external_renderer_factory)
        mock_get_response_spec.side_effect = MatchingResponseNotFound

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        mock_get_response_spec.assert_called_once_with(
            op=self.mock_request.operation,
            status_code=self.mock_request.response.status_code,
        )
        assert not mock_marshal_schema_object.called
        self.external_renderer_factory.return_value.assert_called_once_with(
            self.value_to_render,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value
    def test_rendering_response_without_schema(self, mock_get_response_spec,
                                               mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(
            renderer_factory=self.external_renderer_factory)
        mock_get_response_spec.return_value = {'200': {'description': ''}}

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        mock_get_response_spec.assert_called_once_with(
            op=self.mock_request.operation,
            status_code=self.mock_request.response.status_code,
        )
        assert not mock_marshal_schema_object.called
        self.external_renderer_factory.return_value.assert_called_once_with(
            self.value_to_render,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value
示例#10
0
    def test_successiful_rendering_flow(self, mock_get_response_spec, mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(renderer_factory=self.external_renderer_factory)

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        mock_get_response_spec.assert_called_once_with(
            op=self.mock_request.operation,
            status_code=self.mock_request.response.status_code,
        )
        mock_marshal_schema_object.assert_called_once_with(
            schema_object_spec=mock_get_response_spec.return_value.__getitem__.return_value,
            swagger_spec=self.mock_spec,
            value=self.value_to_render,
        )
        self.external_renderer_factory.return_value.assert_called_once_with(
            mock_marshal_schema_object.return_value,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value
示例#11
0
    def test_successiful_rendering_flow(self, mock_get_response_spec, mock_marshal_schema_object):
        renderer_factory = PyramidSwaggerRendererFactory(renderer_factory=self.external_renderer_factory)

        renderer = renderer_factory(info=self.info)
        rendered_value = renderer(self.value_to_render, self.mock_system)

        self.external_renderer_factory.assert_called_once_with(self.info)
        mock_get_response_spec.assert_called_once_with(
            op=self.mock_request.operation,
            status_code=self.mock_request.response.status_code,
        )
        mock_marshal_schema_object.assert_called_once_with(
            schema_object_spec=mock_get_response_spec.return_value.__getitem__.return_value,
            swagger_spec=self.mock_spec,
            value=self.value_to_render,
        )
        self.external_renderer_factory.return_value.assert_called_once_with(
            mock_marshal_schema_object.return_value,
            self.mock_system,
        )
        assert rendered_value == self.external_renderer_factory.return_value.return_value