]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_docs.py
bump version to 15.2.4-pve1
[ceph.git] / ceph / src / pybind / mgr / dashboard / tests / test_docs.py
1 # # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 from . import ControllerTestCase
5 from ..controllers import RESTController, ApiController, Endpoint, EndpointDoc, ControllerDoc
6 from ..controllers.docs import Docs
7
8
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):
13 @EndpointDoc(
14 description="Endpoint description",
15 group="BarGroup",
16 parameters={
17 'parameter': (int, "Description of parameter"),
18 },
19 responses={
20 200: {
21 'resp': (str, 'Description of response')
22 },
23 },
24 )
25 @Endpoint(json_response=False)
26 def decorated_func(self, parameter):
27 pass
28
29
30 # To assure functionality of @EndpointDoc, @GroupDoc
31 class DocDecoratorsTest(ControllerTestCase):
32 @classmethod
33 def setup_server(cls):
34 cls.setup_controllers([DecoratedController, Docs], "/test")
35
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)
41
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)
50
51
52 # To assure functionality of Docs.py
53 # pylint: disable=protected-access
54 class DocsTest(ControllerTestCase):
55 @classmethod
56 def setup_server(cls):
57 cls.setup_controllers([Docs], "/test")
58
59 def test_type_to_str(self):
60 self.assertEqual(Docs()._type_to_str(str), "string")
61
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)
68
69 def test_gen_tags(self):
70 outcome = Docs()._gen_tags(False)[0]
71 self.assertEqual({'description': 'Group description', 'name': 'FooGroup'}, outcome)