diff --git a/solum/api/controllers/root.py b/solum/api/controllers/root.py index 22a966b8b..e903ef167 100644 --- a/solum/api/controllers/root.py +++ b/solum/api/controllers/root.py @@ -14,20 +14,56 @@ # License for the specific language governing permissions and limitations # under the License. +import pecan from wsme import types as wtypes import wsmeext.pecan as wsme_pecan -from solum import version + +STATUS_KIND = wtypes.Enum(str, 'SUPPORTED', 'CURRENT', 'DEPRECATED') + + +class Link(wtypes.Base): + """A link representation.""" + + href = wtypes.text + "The link url" + + targetName = wtypes.text + "Textual name of the target link" + + @classmethod + def sample(cls): + return cls(href=('http://localhost:9777/v1'), + targetName='v1') class Version(wtypes.Base): """Version representation.""" - version = wtypes.text + id = wtypes.text + "The version identifier" + + status = STATUS_KIND + "The status of the API (SUPPORTED, CURRENT or DEPRECATED)" + + link = Link + "The link to the versioned API" + + @classmethod + def sample(cls): + return cls(id='v1.0', + status='CURRENT', + link=Link(targetName='v1', + href='http://localhost:9777/v1')) class RootController(object): - @wsme_pecan.wsexpose(Version) + @wsme_pecan.wsexpose([Version]) def index(self): - return Version(version=version.version_string()) + host_url = '%s/%s' % (pecan.request.host_url, 'v1') + v1 = Version(id='v1.0', + status='CURRENT', + link=Link(targetName='v1', + href=host_url)) + return [v1] diff --git a/solum/tests/api/test_functional.py b/solum/tests/api/test_functional.py index 09d034ff1..b5a543b0c 100644 --- a/solum/tests/api/test_functional.py +++ b/solum/tests/api/test_functional.py @@ -16,7 +16,6 @@ from solum.openstack.common import jsonutils from solum.tests.api import base -from solum import version class TestRootController(base.FunctionalTest): @@ -25,4 +24,7 @@ class TestRootController(base.FunctionalTest): response = self.app.get('/', headers={'Accept': 'application/json'}) self.assertEqual(response.status_int, 200) data = jsonutils.loads(response.body) - self.assertEqual(data['version'], version.version_string()) + self.assertEqual(data[0]['id'], 'v1.0') + self.assertEqual(data[0]['status'], 'CURRENT') + self.assertEqual(data[0]['link'], {'href': 'http://localhost/v1', + 'targetName': 'v1'})