]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_docs.py
1 # # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
4 from . import ControllerTestCase
5 from ..controllers
import RESTController
, ApiController
, Endpoint
, EndpointDoc
, ControllerDoc
6 from ..controllers
.docs
import Docs
9 # Dummy controller and endpoint that can be assigned with @EndpointDoc and @GroupDoc
10 @ControllerDoc("Group description", group
="FooGroup")
11 @ApiController("/doctest/", secure
=False)
12 class DecoratedController(RESTController
):
14 description
="Endpoint description",
17 'parameter': (int, "Description of parameter"),
21 'resp': (str, 'Description of response')
25 @Endpoint(json_response
=False)
26 def decorated_func(self
, parameter
):
30 # To assure functionality of @EndpointDoc, @GroupDoc
31 class DocDecoratorsTest(ControllerTestCase
):
33 def setup_server(cls
):
34 cls
.setup_controllers([DecoratedController
, Docs
], "/test")
36 def test_group_info_attr(self
):
37 test_ctrl
= DecoratedController()
38 self
.assertTrue(hasattr(test_ctrl
, 'doc_info'))
39 self
.assertIn('tag_descr', test_ctrl
.doc_info
)
40 self
.assertIn('tag', test_ctrl
.doc_info
)
42 def test_endpoint_info_attr(self
):
43 test_ctrl
= DecoratedController()
44 test_endpoint
= test_ctrl
.decorated_func
45 self
.assertTrue(hasattr(test_endpoint
, 'doc_info'))
46 self
.assertIn('summary', test_endpoint
.doc_info
)
47 self
.assertIn('tag', test_endpoint
.doc_info
)
48 self
.assertIn('parameters', test_endpoint
.doc_info
)
49 self
.assertIn('response', test_endpoint
.doc_info
)
52 # To assure functionality of Docs.py
53 # pylint: disable=protected-access
54 class DocsTest(ControllerTestCase
):
56 def setup_server(cls
):
57 cls
.setup_controllers([Docs
], "/test")
59 def test_type_to_str(self
):
60 self
.assertEqual(Docs()._type
_to
_str
(str), "string")
62 def test_gen_paths(self
):
63 outcome
= Docs()._gen
_paths
(False, "")['/api/doctest//decorated_func/{parameter}']['get']
64 self
.assertIn('tags', outcome
)
65 self
.assertIn('summary', outcome
)
66 self
.assertIn('parameters', outcome
)
67 self
.assertIn('responses', outcome
)
69 def test_gen_tags(self
):
70 outcome
= Docs()._gen
_tags
(False)[0]
71 self
.assertEqual({'description': 'Group description', 'name': 'FooGroup'}, outcome
)