Add version routes to KDS
Add the first real endpoints to the KDS server starting with the version discovery endpoints. Change-Id: If359a683e1c9614855d7c20e9f8009c2198a05f7
This commit is contained in:
parent
fef233829a
commit
b766aca05e
|
@ -12,9 +12,18 @@
|
|||
|
||||
import pecan
|
||||
|
||||
from kite.api.v1 import controllers
|
||||
|
||||
|
||||
class RootController(object):
|
||||
|
||||
v1 = controllers.Controller()
|
||||
|
||||
@pecan.expose('json')
|
||||
def index(self):
|
||||
return {'hello': 'world'}
|
||||
pecan.response.status = 300
|
||||
return {
|
||||
'versions': [
|
||||
self.v1.version_info(),
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from kite.api.v1.controllers import controller
|
||||
|
||||
Controller = controller.Controller
|
||||
|
||||
__all__ = ['Controller']
|
|
@ -0,0 +1,29 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
|
||||
|
||||
class Controller(object):
|
||||
"""Version 1 API controller root."""
|
||||
|
||||
@staticmethod
|
||||
def version_info():
|
||||
return {'status': 'stable',
|
||||
'id': 'v1.0',
|
||||
'links': [{
|
||||
'href': '%s/v1/' % pecan.request.host_url,
|
||||
'rel': 'self'}]}
|
||||
|
||||
@pecan.expose('json')
|
||||
def index(self):
|
||||
return {'version': self.version_info()}
|
|
@ -15,6 +15,14 @@ from kite.tests.api import base
|
|||
|
||||
class SimpleTest(base.BaseTestCase):
|
||||
|
||||
def test_simple(self):
|
||||
resp = self.get("/")
|
||||
self.assertEqual(resp.json['hello'], 'world')
|
||||
def test_version(self):
|
||||
resp = self.get('/')
|
||||
versions = resp.json['versions']
|
||||
self.assertEqual(resp.status_code, 300)
|
||||
|
||||
host = 'http://localhost' # webtest default
|
||||
|
||||
self.assertEqual(versions[0]['status'], 'stable')
|
||||
self.assertEqual(versions[0]['id'], 'v1.0')
|
||||
self.assertEqual(versions[0]['links'][0]['href'], '%s/v1/' % host)
|
||||
self.assertEqual(versions[0]['links'][0]['rel'], 'self')
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from kite.tests.api import base
|
||||
|
||||
|
||||
def v1_url(*args):
|
||||
return base.urljoin('v1', *args)
|
||||
|
||||
|
||||
class BaseTestCase(base.BaseTestCase):
|
||||
|
||||
def get(self, url, *args, **kwargs):
|
||||
return super(BaseTestCase, self).get(v1_url(url), *args, **kwargs)
|
||||
|
||||
def post(self, url, *args, **kwargs):
|
||||
return super(BaseTestCase, self).post(v1_url(url), *args, **kwargs)
|
||||
|
||||
def put(self, url, *args, **kwargs):
|
||||
return super(BaseTestCase, self).put(v1_url(url), *args, **kwargs)
|
|
@ -0,0 +1,28 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from kite.tests.api.v1 import base
|
||||
|
||||
|
||||
class TestVersion(base.BaseTestCase):
|
||||
|
||||
def test_versions(self):
|
||||
resp = self.get('/')
|
||||
version = resp.json['version']
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
host = 'http://localhost' # webtest default
|
||||
|
||||
self.assertEqual(version['id'], 'v1.0')
|
||||
self.assertEqual(version['status'], 'stable')
|
||||
self.assertEqual(version['links'][0]['href'], '%s/v1/' % host)
|
||||
self.assertEqual(version['links'][0]['rel'], 'self')
|
Loading…
Reference in New Issue