diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/pybind/mgr/dashboard/tests/test_versioning.py | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/pybind/mgr/dashboard/tests/test_versioning.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/tests/test_versioning.py b/src/pybind/mgr/dashboard/tests/test_versioning.py new file mode 100644 index 000000000..0a77a299e --- /dev/null +++ b/src/pybind/mgr/dashboard/tests/test_versioning.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +import unittest + +from ..controllers._api_router import APIRouter +from ..controllers._rest_controller import RESTController +from ..controllers._version import APIVersion +from ..tests import ControllerTestCase + + +@APIRouter("/vtest", secure=False) +class VTest(RESTController): + RESOURCE_ID = "vid" + + @RESTController.MethodMap(version=APIVersion(0, 1)) + def list(self): + return {'version': ""} + + def get(self): + return {'version': ""} + + @RESTController.Collection('GET', version=APIVersion(1, 0)) + def vmethod(self): + return {'version': '1.0'} + + @RESTController.Collection('GET', version=APIVersion(1, 1)) + def vmethodv1_1(self): + return {'version': '1.1'} + + @RESTController.Collection('GET', version=APIVersion(2, 0)) + def vmethodv2(self): + return {'version': '2.0'} + + +class RESTVersioningTest(ControllerTestCase, unittest.TestCase): + @classmethod + def setup_server(cls): + cls.setup_controllers([VTest], "/test") + + def test_list(self): + for (version, expected_status) in [ + ((0, 1), 200), + ((2, 0), 415) + ]: + with self.subTest(version=version): + self._get('/test/api/vtest', version=APIVersion._make(version)) + self.assertStatus(expected_status) + + def test_v1(self): + for (version, expected_status) in [ + ((1, 0), 200), + ((2, 0), 415) + ]: + with self.subTest(version=version): + self._get('/test/api/vtest/vmethod', + version=APIVersion._make(version)) + self.assertStatus(expected_status) + + def test_v2(self): + for (version, expected_status) in [ + ((2, 0), 200), + ((1, 0), 415) + ]: + with self.subTest(version=version): + self._get('/test/api/vtest/vmethodv2', + version=APIVersion._make(version)) + self.assertStatus(expected_status) + + def test_backward_compatibility(self): + for (version, expected_status) in [ + ((1, 1), 200), + ((1, 0), 200), + ((2, 0), 415) + ]: + with self.subTest(version=version): + self._get('/test/api/vtest/vmethodv1_1', + version=APIVersion._make(version)) + self.assertStatus(expected_status) |