예제 #1
0
 def test__openapi_redoc(self, mock_render_template):
     mock_self = Mock()
     DocBlueprintMixin._openapi_redoc(mock_self)
     mock_render_template.assert_called_once_with(
         'redoc.html',
         title=mock_self._app.name,
         redoc_url=mock_self._redoc_url)
예제 #2
0
 def test__openapi_swagger_ui(self, mock_render_template):
     mock_self = Mock()
     DocBlueprintMixin._openapi_swagger_ui(mock_self)
     mock_render_template.assert_called_once_with(
         'swagger_ui.html', title=mock_self._app.name, swagger_ui_url=mock_self._swagger_ui_url,
         swagger_ui_supported_submit_methods=mock_self._swagger_ui_supported_submit_methods
     )
예제 #3
0
 def test__openapi_json(self, mock_current_app, mock_dumps):
     mock_self = Mock()
     DocBlueprintMixin._openapi_json(mock_self)
     mock_current_app.response_class.assert_called_once_with(
         mock_dumps.return_value, mimetype="application/json")
     mock_dumps.assert_called_once_with(mock_self.spec.to_dict.return_value,
                                        indent=2)
예제 #4
0
    def test__register_doc_blueprint__no_openapi_url_prefix(self):
        mock_self = Mock()
        mock_self._app.config = {'OPENAPI_URL_PREFIX': None}
        DocBlueprintMixin._register_doc_blueprint(mock_self)

        mock_self._register_redoc_rule.assert_not_called()
        mock_self._register_swagger_ui_rule.assert_not_called()
        mock_self._app.register_blueprint.assert_not_called()
예제 #5
0
    def test__register_redoc_rule__no_redoc_path(self):
        mock_self = Mock()
        mock_self._app.config = {'OPENAPI_REDOC_PATH': None}
        mock_blueprint = Mock()

        DocBlueprintMixin._register_redoc_rule(mock_self, mock_blueprint)
        assert isinstance(mock_self._redoc_url, Mock)
        mock_blueprint.add_url_rule.assert_not_called()
예제 #6
0
    def test_register_swagger_ui_rule__no_path(self):
        mock_self = Mock()
        mock_self._app.config = {'OPENAPI_SWAGGER_UI_PATH': None}
        mock_blueprint = Mock()

        DocBlueprintMixin._register_swagger_ui_rule(mock_self, mock_blueprint)
        assert isinstance(mock_self._swagger_ui_rule, Mock)
        assert isinstance(mock_self._swagger_ui_supported_submit_methods, Mock)
        mock_blueprint.add_url_rule.assert_not_called()
예제 #7
0
    def test_register_swagger_ui_rule(self, swagger_ui_url, swagger_ui_version, expected_result_url):
        mock_self = Mock()
        mock_self.decorators_for_autodoc = [self.some_dec]
        mock_self._app.config = {'OPENAPI_SWAGGER_UI_PATH': '/swagger_ui',
                                 'OPENAPI_SWAGGER_UI_URL': swagger_ui_url,
                                 'OPENAPI_SWAGGER_UI_VERSION': swagger_ui_version}
        mock_blueprint = Mock()

        DocBlueprintMixin._register_swagger_ui_rule(mock_self, mock_blueprint)
        mock_self._swagger_ui_url = expected_result_url
        mock_self._swagger_ui_supported_submit_methods = ["get", "put", "post", "delete",
                                                          "options", "head", "patch", "trace"]
        mock_blueprint.add_url_rule.assert_called_once_with('/swagger_ui', endpoint='openapi_swagger_ui',
                                                            view_func=self.some_dec(mock_self._openapi_swagger_ui))
예제 #8
0
    def test__register_redoc_rule(self, redoc_url, redoc_version, expected_redoc_url):
        redoc_path = '/api/redoc'
        mock_self = Mock()
        mock_self._app.config = {'OPENAPI_REDOC_PATH': redoc_path,
                                 'OPENAPI_REDOC_URL': redoc_url}
        if redoc_version:
            mock_self._app.config['OPENAPI_REDOC_VERSION'] = redoc_version

        mock_self.decorators_for_autodoc = [self.some_dec]
        mock_blueprint = Mock()

        DocBlueprintMixin._register_redoc_rule(mock_self, mock_blueprint)

        assert mock_self._redoc_url == expected_redoc_url
        mock_blueprint.add_url_rule.assert_called_once_with(redoc_path, endpoint='openapi_redoc',
                                                            view_func=self.some_dec(mock_self._openapi_redoc))
예제 #9
0
    def test__register_doc_blueprint(self, mock_add_url_rule):
        url = '/api/swagger'
        mock_self = Mock()
        mock_self._app.config = {'OPENAPI_URL_PREFIX': url}
        mock_self.decorators_for_autodoc = [self.some_dec]
        DocBlueprintMixin._register_doc_blueprint(mock_self)

        blueprint = mock_self._register_redoc_rule.call_args[0][0]
        assert blueprint.template_folder == './templates'
        assert blueprint.url_prefix == url
        mock_add_url_rule.assert_called_once_with(blueprint, '/openapi.json', endpoint='openapi_json',
                                                  view_func=self.some_dec(mock_self._openapi_json))

        mock_self._register_redoc_rule.assert_called_once_with(blueprint)
        mock_self._register_swagger_ui_rule.assert_called_once_with(blueprint)
        mock_self._app.register_blueprint.assert_called_once_with(blueprint)