summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-31 14:32:35 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-05-31 14:32:35 +0800
commit60a9d754a14dc87dda5a7fb045e48c323189eef6 (patch)
tree1a2fa68820d099de1a79ed5d399b9bfe739dbc92
parentdc13d5eac8f110678c1105ca3e06a58b999298ec (diff)
bugfix: version return body is inconsistent with the designed model
JIRA: FUNCTEST-278 Change-Id: I53fa2eca6476c07ad513e72241d9715431cbdee8 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
-rw-r--r--result_collection_api/resources/handlers.py5
-rw-r--r--result_collection_api/resources/models.py25
-rw-r--r--result_collection_api/tests/unit/test_version.py11
3 files changed, 31 insertions, 10 deletions
diff --git a/result_collection_api/resources/handlers.py b/result_collection_api/resources/handlers.py
index a2c6b8d..0977ef0 100644
--- a/result_collection_api/resources/handlers.py
+++ b/result_collection_api/resources/handlers.py
@@ -223,7 +223,8 @@ class VersionHandler(GenericApiHandler):
@swagger.operation(nickname='list')
def get(self):
"""
- @description: Display a message for the API version
+ @description: list all supported versions
@rtype: L{Versions}
"""
- self.finish_request([{'v1': 'basics'}])
+ versions = [{'version': 'v1.0', 'description': 'basics'}]
+ self.finish_request({'versions': versions})
diff --git a/result_collection_api/resources/models.py b/result_collection_api/resources/models.py
index 3c834fd..7241bb7 100644
--- a/result_collection_api/resources/models.py
+++ b/result_collection_api/resources/models.py
@@ -36,10 +36,21 @@ class CreateResponse(object):
@swagger.model()
class Versions(object):
"""
+ @property versions:
@ptype versions: C{list} of L{Version}
"""
- def __init__(self, versions):
- self.versions = versions
+ def __init__(self):
+ self.versions = list()
+
+ @staticmethod
+ def from_dict(res_dict):
+ if res_dict is None:
+ return None
+
+ res = Versions()
+ for version in res_dict.get('versions'):
+ res.versions.append(Version.from_dict(version))
+ return res
@swagger.model()
@@ -47,3 +58,13 @@ class Version(object):
def __init__(self, version=None, description=None):
self.version = version
self.description = description
+
+ @staticmethod
+ def from_dict(a_dict):
+ if a_dict is None:
+ return None
+
+ ver = Version()
+ ver.version = a_dict.get('version')
+ ver.description = str(a_dict.get('description'))
+ return ver
diff --git a/result_collection_api/tests/unit/test_version.py b/result_collection_api/tests/unit/test_version.py
index a58cd56..8e544e0 100644
--- a/result_collection_api/tests/unit/test_version.py
+++ b/result_collection_api/tests/unit/test_version.py
@@ -1,15 +1,14 @@
-import json
import unittest
from test_base import TestBase
-
+from resources.models import Versions
__author__ = 'serena'
class TestVersionbBase(TestBase):
def setUp(self):
super(TestVersionbBase, self).setUp()
- self.list_res = None
+ self.list_res = Versions
self.basePath = '/versions'
@@ -17,9 +16,9 @@ class TestVersion(TestVersionbBase):
def test_success(self):
code, body = self.get()
self.assertEqual(200, code)
- json_body = json.loads(body)
- self.assertEqual(len(json_body), 1)
- self.assertEqual('basics', json_body[0].get('v1'))
+ self.assertEqual(len(body.versions), 1)
+ self.assertEqual(body.versions[0].version, 'v1.0')
+ self.assertEqual(body.versions[0].description, 'basics')
if __name__ == '__main__':
unittest.main()