diff options
Diffstat (limited to 'utils/test/testapi')
18 files changed, 350 insertions, 335 deletions
diff --git a/utils/test/testapi/deployment/deploy.py b/utils/test/testapi/deployment/deploy.py new file mode 100644 index 000000000..748bd34f8 --- /dev/null +++ b/utils/test/testapi/deployment/deploy.py @@ -0,0 +1,40 @@ +import argparse +import os + +from jinja2 import Environment, FileSystemLoader + +env = Environment(loader=FileSystemLoader('./')) +docker_compose_yml = './docker-compose.yml' +docker_compose_template = './docker-compose.yml.template' + + +def render_docker_compose(port, swagger_url): + vars = { + "expose_port": port, + "swagger_url": swagger_url, + } + template = env.get_template(docker_compose_template) + yml = template.render(vars=vars) + + with open(docker_compose_yml, 'w') as f: + f.write(yml) + f.close() + + +def main(args): + render_docker_compose(args.expose_port, args.swagger_url) + os.system('docker-compose -f {} up -d'.format(docker_compose_yml)) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Backup MongoDBs') + parser.add_argument('-p', '--expose-port', + type=int, + required=False, + default=8000, + help='testapi exposed port') + parser.add_argument('-su', '--swagger-url', + type=str, + required=True, + help='testapi exposed swagger-url') + main(parser.parse_args()) diff --git a/utils/test/testapi/deployment/docker-compose.yml.template b/utils/test/testapi/deployment/docker-compose.yml.template new file mode 100644 index 000000000..5b131f747 --- /dev/null +++ b/utils/test/testapi/deployment/docker-compose.yml.template @@ -0,0 +1,15 @@ +version: '2' +services: + mongo: + image: mongo:3.2.1 + container_name: opnfv-mongo + testapi: + image: opnfv/testapi:latest + container_name: opnfv-testapi + environment: + - mongodb_url=mongodb://mongo:27017/ + - swagger_url={{ vars.swagger_url }} + ports: + - "{{ vars.expose_port }}:8000" + links: + - mongo diff --git a/utils/test/testapi/htmlize/finish.sh b/utils/test/testapi/htmlize/finish.sh new file mode 100644 index 000000000..dc3aa868b --- /dev/null +++ b/utils/test/testapi/htmlize/finish.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +# Stop opnfv-testapi server +proc_number=`ps -ef | grep opnfv-testapi | grep -v grep | wc -l` + +if [ $proc_number -gt 0 ]; then + procs=`ps -ef | grep opnfv-testapi | grep -v grep` + echo "Kill opnfv-testapi server $procs" + ps -ef | grep opnfv-testapi | grep -v grep | awk '{print $2}' | xargs kill -kill &>/dev/null +fi diff --git a/utils/test/testapi/htmlize/htmlize.py b/utils/test/testapi/htmlize/htmlize.py new file mode 100644 index 000000000..68d02febd --- /dev/null +++ b/utils/test/testapi/htmlize/htmlize.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +import argparse +import requests +import json +import os + + +def main(args): + + # Merging two specs + api_response = requests.get(args.api_declaration_url) + api_response = json.loads(api_response.content) + resource_response = requests.get(args.resource_listing_url) + resource_response = json.loads(resource_response.content) + resource_response['models'] = api_response['models'] + resource_response['apis'] = api_response['apis'] + + # Storing the swagger specs + with open('specs.json', 'w') as outfile: + json.dump(resource_response, outfile) + + # Generating html page + cmd = 'java -jar swagger-codegen-cli.jar generate \ + -i specs.json -l html2 -o %s' % (args.output_directory) + os.system(cmd) + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Create \ + Swagger Spec documentation') + parser.add_argument('-ru', '--resource-listing-url', + type=str, + required=False, + default='http://localhost:8000/swagger/spec.json', + help='Resource Listing Spec File') + parser.add_argument('-au', '--api-declaration-url', + type=str, + required=False, + default='http://localhost:8000/swagger/spec', + help='API Declaration Spec File') + parser.add_argument('-o', '--output-directory', + required=True, + default='./', + help='Output Directory where the \ + file should be stored') + main(parser.parse_args()) diff --git a/utils/test/testapi/htmlize/prepare.sh b/utils/test/testapi/htmlize/prepare.sh new file mode 100644 index 000000000..3c265aaa0 --- /dev/null +++ b/utils/test/testapi/htmlize/prepare.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +#Creating virtual environment +virtualenv testapi_venv +source testapi_venv/bin/activate + +# Install Pre-requisites +pip install requests + +# Swgger Codegen Tool +url="http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar" + +#Check for jar file locally and in the repo +if [ ! -f swagger-codegen-cli.jar ]; +then + wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar -O swagger-codegen-cli.jar +fi + +# Start OPNFV Test API Server +cd utils/test/testapi/ +pip install -r requirements.txt +./install.sh +opnfv-testapi -c ../../../testapi_venv/etc/opnfv_testapi/config.ini & + +deactivate diff --git a/utils/test/testapi/htmlize/push-doc-artifact.sh b/utils/test/testapi/htmlize/push-doc-artifact.sh new file mode 100644 index 000000000..383565df1 --- /dev/null +++ b/utils/test/testapi/htmlize/push-doc-artifact.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e +set -o pipefail + +export PATH=$PATH:/usr/local/bin/ + +project=$PROJECT +workspace=$WORKSPACE +artifact_dir="functest/docs" + +set +e +gsutil&>/dev/null +if [ $? != 0 ]; then + echo "Not possible to push results to artifact: gsutil not installed" +else + gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null + if [ $? != 0 ]; then + echo "Not possible to push results to artifact: gsutil not installed." + else + echo "Uploading document to artifact $artifact_dir" + gsutil cp "$workspace"/index.html gs://artifacts.opnfv.org/"$artifact_dir"/testapi.html >/dev/null 2>&1 + echo "Document can be found at http://artifacts.opnfv.org/functest/docs/testapi.html" + fi +fi diff --git a/utils/test/testapi/install.sh b/utils/test/testapi/install.sh index 43229eabb..c55691aed 100755 --- a/utils/test/testapi/install.sh +++ b/utils/test/testapi/install.sh @@ -10,9 +10,17 @@ usage: where: -h|--help show this help text" -if [[ $(whoami) != "root" ]]; then - echo "Error: This script must be run as root!" - exit 1 +# Ref :- https://openstack.nimeyo.com/87286/openstack-packaging-all-definition-data-files-config-setup + +if [ -z "$VIRTUAL_ENV" ]; +then + if [[ $(whoami) != "root" ]]; + then + echo "Error: This script must be run as root!" + exit 1 + fi +else + sed -i -e 's#/etc/opnfv_testapi =#etc/opnfv_testapi =#g' setup.cfg fi cp -fr 3rd_party/static opnfv_testapi/tornado_swagger diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py index 5059f5d77..f1ad15e97 100644 --- a/utils/test/testapi/opnfv_testapi/resources/handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py @@ -227,7 +227,7 @@ class GenericApiHandler(RequestHandler): class VersionHandler(GenericApiHandler): - @swagger.operation(nickname='list') + @swagger.operation(nickname='List all versions') def get(self): """ @description: list all supported versions diff --git a/utils/test/testapi/opnfv_testapi/resources/models.py b/utils/test/testapi/opnfv_testapi/resources/models.py index e79308b53..f518c97a0 100644 --- a/utils/test/testapi/opnfv_testapi/resources/models.py +++ b/utils/test/testapi/opnfv_testapi/resources/models.py @@ -12,60 +12,87 @@ # feng.xiaowei@zte.com.cn add CreateResponse 5-19-2016
# feng.xiaowei@zte.com.cn mv TestCase to testcase_models.py 5-20-2016
# feng.xiaowei@zte.com.cn mv TestResut to result_models.py 5-23-2016
+# feng.xiaowei@zte.com.cn add ModelBase 12-20-2016
##############################################################################
+import copy
+
from opnfv_testapi.tornado_swagger import swagger
-@swagger.model()
-class CreateResponse(object):
- def __init__(self, href=''):
- self.href = href
+class ModelBase(object):
+
+ def _format(self, excludes):
+ new_obj = copy.deepcopy(self)
+ dicts = new_obj.__dict__
+ for k in dicts.keys():
+ if k in excludes:
+ del dicts[k]
+ elif dicts[k]:
+ if hasattr(dicts[k], 'format'):
+ dicts[k] = dicts[k].format()
+ elif isinstance(dicts[k], list):
+ hs = list()
+ [hs.append(h.format() if hasattr(h, 'format') else str(h))
+ for h in dicts[k]]
+ dicts[k] = hs
+ elif not isinstance(dicts[k], (str, int, float, dict)):
+ dicts[k] = str(dicts[k])
+ return dicts
+
+ def format(self):
+ return self._format(['_id'])
+
+ def format_http(self):
+ return self._format([])
@staticmethod
- def from_dict(res_dict):
- if res_dict is None:
+ def attr_parser():
+ return {}
+
+ @classmethod
+ def from_dict(cls, a_dict):
+ if a_dict is None:
return None
- res = CreateResponse()
- res.href = res_dict.get('href')
- return res
+ attr_parser = cls.attr_parser()
+ t = cls()
+ for k, v in a_dict.iteritems():
+ value = v
+ if isinstance(v, dict) and k in attr_parser:
+ value = attr_parser[k].from_dict(v)
+ elif isinstance(v, list) and k in attr_parser:
+ value = []
+ for item in v:
+ value.append(attr_parser[k].from_dict(item))
- def format(self):
- return {'href': self.href}
+ t.__setattr__(k, value)
+
+ return t
@swagger.model()
-class Versions(object):
+class CreateResponse(ModelBase):
+ def __init__(self, href=''):
+ self.href = href
+
+
+@swagger.model()
+class Versions(ModelBase):
"""
@property versions:
@ptype versions: C{list} of L{Version}
"""
+
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
+ def attr_parser():
+ return {'versions': Version}
@swagger.model()
-class Version(object):
+class Version(ModelBase):
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/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py b/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py index 8f44439e7..631d4a91d 100644 --- a/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py @@ -20,7 +20,7 @@ class GenericPodHandler(GenericApiHandler): class PodCLHandler(GenericPodHandler): - @swagger.operation(nickname='list-all') + @swagger.operation(nickname='List all Pods') def get(self): """ @description: list all pods @@ -29,7 +29,7 @@ class PodCLHandler(GenericPodHandler): """ self._list() - @swagger.operation(nickname='create') + @swagger.operation(nickname='Create a Pod') def post(self): """ @description: create a pod @@ -54,7 +54,7 @@ class PodCLHandler(GenericPodHandler): class PodGURHandler(GenericPodHandler): - @swagger.operation(nickname='get-one') + @swagger.operation(nickname='Get a Pod by pod_name') def get(self, pod_name): """ @description: get a single pod by pod_name diff --git a/utils/test/testapi/opnfv_testapi/resources/pod_models.py b/utils/test/testapi/opnfv_testapi/resources/pod_models.py index 7231806f6..26a9e6788 100644 --- a/utils/test/testapi/opnfv_testapi/resources/pod_models.py +++ b/utils/test/testapi/opnfv_testapi/resources/pod_models.py @@ -6,8 +6,10 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import models from opnfv_testapi.tornado_swagger import swagger + # name: name of the POD e.g. zte-1 # mode: metal or virtual # details: any detail @@ -15,58 +17,29 @@ from opnfv_testapi.tornado_swagger import swagger @swagger.model() -class PodCreateRequest(object): +class PodCreateRequest(models.ModelBase): def __init__(self, name, mode='', details='', role=""): self.name = name self.mode = mode self.details = details self.role = role - def format(self): - return { - "name": self.name, - "mode": self.mode, - "details": self.details, - "role": self.role, - } - @swagger.model() -class Pod(PodCreateRequest): +class Pod(models.ModelBase): def __init__(self, name='', mode='', details='', role="", _id='', create_date=''): - super(Pod, self).__init__(name, mode, details, role) + self.name = name + self.mode = mode + self.details = details + self.role = role self._id = _id self.creation_date = create_date - @staticmethod - def from_dict(pod_dict): - if pod_dict is None: - return None - - p = Pod() - p._id = pod_dict.get('_id') - p.creation_date = str(pod_dict.get('creation_date')) - p.name = pod_dict.get('name') - p.mode = pod_dict.get('mode') - p.details = pod_dict.get('details') - p.role = pod_dict.get('role') - return p - - def format(self): - f = super(Pod, self).format() - f['creation_date'] = str(self.creation_date) - return f - - def format_http(self): - f = self.format() - f['_id'] = str(self._id) - return f - @swagger.model() -class Pods(object): +class Pods(models.ModelBase): """ @property pods: @ptype pods: C{list} of L{Pod} @@ -75,11 +48,5 @@ class Pods(object): self.pods = list() @staticmethod - def from_dict(res_dict): - if res_dict is None: - return None - - res = Pods() - for pod in res_dict.get('pods'): - res.pods.append(Pod.from_dict(pod)) - return res + def attr_parser(): + return {'pods': Pod} diff --git a/utils/test/testapi/opnfv_testapi/resources/project_handlers.py b/utils/test/testapi/opnfv_testapi/resources/project_handlers.py index 1e9a97230..9cf698623 100644 --- a/utils/test/testapi/opnfv_testapi/resources/project_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/project_handlers.py @@ -22,7 +22,7 @@ class GenericProjectHandler(GenericApiHandler): class ProjectCLHandler(GenericProjectHandler): - @swagger.operation(nickname="list-all") + @swagger.operation(nickname="List all Projects") def get(self): """ @description: list all projects @@ -31,7 +31,7 @@ class ProjectCLHandler(GenericProjectHandler): """ self._list() - @swagger.operation(nickname="create") + @swagger.operation(nickname="Create a Project") def post(self): """ @description: create a project @@ -56,7 +56,7 @@ class ProjectCLHandler(GenericProjectHandler): class ProjectGURHandler(GenericProjectHandler): - @swagger.operation(nickname='get-one') + @swagger.operation(nickname='Get a Project by project_name') def get(self, project_name): """ @description: get a single project by project_name @@ -66,7 +66,7 @@ class ProjectGURHandler(GenericProjectHandler): """ self._get_one({'name': project_name}) - @swagger.operation(nickname="update") + @swagger.operation(nickname="Update a Project by project_name") def put(self, project_name): """ @description: update a single project by project_name @@ -82,7 +82,7 @@ class ProjectGURHandler(GenericProjectHandler): db_keys = ['name'] self._update(query, db_keys) - @swagger.operation(nickname='delete') + @swagger.operation(nickname='Delete a Project by project_name') def delete(self, project_name): """ @description: delete a project by project_name diff --git a/utils/test/testapi/opnfv_testapi/resources/project_models.py b/utils/test/testapi/opnfv_testapi/resources/project_models.py index f70630cda..f7323c1c4 100644 --- a/utils/test/testapi/opnfv_testapi/resources/project_models.py +++ b/utils/test/testapi/opnfv_testapi/resources/project_models.py @@ -6,37 +6,26 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import models from opnfv_testapi.tornado_swagger import swagger @swagger.model() -class ProjectCreateRequest(object): +class ProjectCreateRequest(models.ModelBase): def __init__(self, name, description=''): self.name = name self.description = description - def format(self): - return { - "name": self.name, - "description": self.description, - } - @swagger.model() -class ProjectUpdateRequest(object): +class ProjectUpdateRequest(models.ModelBase): def __init__(self, name='', description=''): self.name = name self.description = description - def format(self): - return { - "name": self.name, - "description": self.description, - } - @swagger.model() -class Project(object): +class Project(models.ModelBase): def __init__(self, name=None, _id=None, description=None, create_date=None): self._id = _id @@ -44,38 +33,9 @@ class Project(object): self.description = description self.creation_date = create_date - @staticmethod - def from_dict(res_dict): - - if res_dict is None: - return None - - t = Project() - t._id = res_dict.get('_id') - t.creation_date = res_dict.get('creation_date') - t.name = res_dict.get('name') - t.description = res_dict.get('description') - - return t - - def format(self): - return { - "name": self.name, - "description": self.description, - "creation_date": str(self.creation_date) - } - - def format_http(self): - return { - "_id": str(self._id), - "name": self.name, - "description": self.description, - "creation_date": str(self.creation_date), - } - @swagger.model() -class Projects(object): +class Projects(models.ModelBase): """ @property projects: @ptype projects: C{list} of L{Project} @@ -84,11 +44,5 @@ class Projects(object): self.projects = list() @staticmethod - def from_dict(res_dict): - if res_dict is None: - return None - - res = Projects() - for project in res_dict.get('projects'): - res.projects.append(Project.from_dict(project)) - return res + def attr_parser(): + return {'projects': Project} diff --git a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py index 400b84ac1..fe13c09b7 100644 --- a/utils/test/testapi/opnfv_testapi/resources/result_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/result_handlers.py @@ -52,7 +52,7 @@ class GenericResultHandler(GenericApiHandler): class ResultsCLHandler(GenericResultHandler): - @swagger.operation(nickname="list-all") + @swagger.operation(nickname="List all Test Results") def get(self): """ @description: Retrieve result(s) for a test project @@ -127,7 +127,7 @@ class ResultsCLHandler(GenericResultHandler): self._list(self.set_query(), sort=[('start_date', -1)], last=last) - @swagger.operation(nickname="create") + @swagger.operation(nickname="Create a Test Result") def post(self): """ @description: create a test result @@ -169,7 +169,7 @@ class ResultsCLHandler(GenericResultHandler): class ResultsGURHandler(GenericResultHandler): - @swagger.operation(nickname='get-one') + @swagger.operation(nickname='Get a Test Result by result_id') def get(self, result_id): """ @description: get a single result by result_id @@ -181,7 +181,7 @@ class ResultsGURHandler(GenericResultHandler): query["_id"] = ObjectId(result_id) self._get_one(query) - @swagger.operation(nickname="update") + @swagger.operation(nickname="Update a Test Result by result_id") def put(self, result_id): """ @description: update a single result by _id diff --git a/utils/test/testapi/opnfv_testapi/resources/result_models.py b/utils/test/testapi/opnfv_testapi/resources/result_models.py index f73f5c612..50445fc22 100644 --- a/utils/test/testapi/opnfv_testapi/resources/result_models.py +++ b/utils/test/testapi/opnfv_testapi/resources/result_models.py @@ -6,11 +6,12 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import models from opnfv_testapi.tornado_swagger import swagger @swagger.model() -class TIHistory(object): +class TIHistory(models.ModelBase): """ @ptype step: L{float} """ @@ -18,22 +19,9 @@ class TIHistory(object): self.date = date self.step = step - def format(self): - return { - "date": self.date, - "step": self.step - } - - @staticmethod - def from_dict(a_dict): - if a_dict is None: - return None - - return TIHistory(a_dict.get('date'), a_dict.get('step')) - @swagger.model() -class TI(object): +class TI(models.ModelBase): """ @property histories: trust_indicator update histories @ptype histories: C{list} of L{TIHistory} @@ -43,31 +31,13 @@ class TI(object): self.current = current self.histories = list() - def format(self): - hs = [] - for h in self.histories: - hs.append(h.format()) - - return { - "current": self.current, - "histories": hs - } - @staticmethod - def from_dict(a_dict): - t = TI() - if a_dict: - t.current = a_dict.get('current') - if 'histories' in a_dict.keys(): - for history in a_dict.get('histories', None): - t.histories.append(TIHistory.from_dict(history)) - else: - t.histories = [] - return t + def attr_parser(): + return {'histories': TIHistory} @swagger.model() -class ResultCreateRequest(object): +class ResultCreateRequest(models.ModelBase): """ @property trust_indicator: @ptype trust_indicator: L{TI} @@ -98,25 +68,9 @@ class ResultCreateRequest(object): self.criteria = criteria self.trust_indicator = trust_indicator if trust_indicator else TI(0) - def format(self): - return { - "pod_name": self.pod_name, - "project_name": self.project_name, - "case_name": self.case_name, - "installer": self.installer, - "version": self.version, - "start_date": self.start_date, - "stop_date": self.stop_date, - "details": self.details, - "build_tag": self.build_tag, - "scenario": self.scenario, - "criteria": self.criteria, - "trust_indicator": self.trust_indicator.format() - } - @swagger.model() -class ResultUpdateRequest(object): +class ResultUpdateRequest(models.ModelBase): """ @property trust_indicator: @ptype trust_indicator: L{TI} @@ -124,14 +78,9 @@ class ResultUpdateRequest(object): def __init__(self, trust_indicator=None): self.trust_indicator = trust_indicator - def format(self): - return { - "trust_indicator": self.trust_indicator.format(), - } - @swagger.model() -class TestResult(object): +class TestResult(models.ModelBase): """ @property trust_indicator: used for long duration test case @ptype trust_indicator: L{TI} @@ -156,63 +105,12 @@ class TestResult(object): self.trust_indicator = trust_indicator @staticmethod - def from_dict(a_dict): - - if a_dict is None: - return None - - t = TestResult() - t._id = a_dict.get('_id') - t.case_name = a_dict.get('case_name') - t.pod_name = a_dict.get('pod_name') - t.project_name = a_dict.get('project_name') - t.start_date = str(a_dict.get('start_date')) - t.stop_date = str(a_dict.get('stop_date')) - t.details = a_dict.get('details') - t.version = a_dict.get('version') - t.installer = a_dict.get('installer') - t.build_tag = a_dict.get('build_tag') - t.scenario = a_dict.get('scenario') - t.criteria = a_dict.get('criteria') - t.trust_indicator = TI.from_dict(a_dict.get('trust_indicator')) - return t - - def format(self): - return { - "case_name": self.case_name, - "project_name": self.project_name, - "pod_name": self.pod_name, - "start_date": str(self.start_date), - "stop_date": str(self.stop_date), - "version": self.version, - "installer": self.installer, - "details": self.details, - "build_tag": self.build_tag, - "scenario": self.scenario, - "criteria": self.criteria, - "trust_indicator": self.trust_indicator.format() - } - - def format_http(self): - return { - "_id": str(self._id), - "case_name": self.case_name, - "project_name": self.project_name, - "pod_name": self.pod_name, - "start_date": str(self.start_date), - "stop_date": str(self.stop_date), - "version": self.version, - "installer": self.installer, - "details": self.details, - "build_tag": self.build_tag, - "scenario": self.scenario, - "criteria": self.criteria, - "trust_indicator": self.trust_indicator.format() - } + def attr_parser(): + return {'trust_indicator': TI} @swagger.model() -class TestResults(object): +class TestResults(models.ModelBase): """ @property results: @ptype results: C{list} of L{TestResult} @@ -221,11 +119,5 @@ class TestResults(object): self.results = list() @staticmethod - def from_dict(a_dict): - if a_dict is None: - return None - - res = TestResults() - for result in a_dict.get('results'): - res.results.append(TestResult.from_dict(result)) - return res + def attr_parser(): + return {'results': TestResult} diff --git a/utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py b/utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py index 253aa6649..3692b164f 100644 --- a/utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py +++ b/utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py @@ -22,7 +22,7 @@ class GenericTestcaseHandler(GenericApiHandler): class TestcaseCLHandler(GenericTestcaseHandler): - @swagger.operation(nickname="list-all") + @swagger.operation(nickname="List all TestCases by project_name") def get(self, project_name): """ @description: list all testcases of a project by project_name @@ -34,7 +34,7 @@ class TestcaseCLHandler(GenericTestcaseHandler): query['project_name'] = project_name self._list(query) - @swagger.operation(nickname="create") + @swagger.operation(nickname="Create a TestCase by project_name") def post(self, project_name): """ @description: create a testcase of a project by project_name @@ -72,7 +72,7 @@ class TestcaseCLHandler(GenericTestcaseHandler): class TestcaseGURHandler(GenericTestcaseHandler): - @swagger.operation(nickname='get-one') + @swagger.operation(nickname='Get a TestCase by project and case name') def get(self, project_name, case_name): """ @description: get a single testcase @@ -86,7 +86,7 @@ class TestcaseGURHandler(GenericTestcaseHandler): query["name"] = case_name self._get_one(query) - @swagger.operation(nickname="update") + @swagger.operation(nickname="Update a TestCase by project and case name") def put(self, project_name, case_name): """ @description: update a single testcase @@ -104,7 +104,7 @@ class TestcaseGURHandler(GenericTestcaseHandler): db_keys = ['name', 'project_name'] self._update(query, db_keys) - @swagger.operation(nickname='delete') + @swagger.operation(nickname='Delete a TestCase by project and case name') def delete(self, project_name, case_name): """ @description: delete a testcase by project_name and case_name diff --git a/utils/test/testapi/opnfv_testapi/resources/testcase_models.py b/utils/test/testapi/opnfv_testapi/resources/testcase_models.py index c9dce6088..8cc3c6c6a 100644 --- a/utils/test/testapi/opnfv_testapi/resources/testcase_models.py +++ b/utils/test/testapi/opnfv_testapi/resources/testcase_models.py @@ -6,87 +6,80 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import models from opnfv_testapi.tornado_swagger import swagger @swagger.model() -class TestcaseCreateRequest(object): - def __init__(self, name, url=None, description=None): +class TestcaseCreateRequest(models.ModelBase): + def __init__(self, name, url=None, description=None, + tier=None, ci_loop=None, criteria=None, + blocking=None, dependencies=None, run=None, + domains=None, tags=None, version=None): self.name = name self.url = url self.description = description - - def format(self): - return { - "name": self.name, - "description": self.description, - "url": self.url, - } + self.tier = tier + self.ci_loop = ci_loop + self.criteria = criteria + self.blocking = blocking + self.dependencies = dependencies + self.run = run + self.domains = domains + self.tags = tags + self.version = version + self.trust = "Silver" @swagger.model() -class TestcaseUpdateRequest(object): - def __init__(self, name=None, description=None, project_name=None): +class TestcaseUpdateRequest(models.ModelBase): + def __init__(self, name=None, description=None, project_name=None, + tier=None, ci_loop=None, criteria=None, + blocking=None, dependencies=None, run=None, + domains=None, tags=None, version=None, trust=None): self.name = name self.description = description self.project_name = project_name - - def format(self): - return { - "name": self.name, - "description": self.description, - "project_name": self.project_name, - } + self.tier = tier + self.ci_loop = ci_loop + self.criteria = criteria + self.blocking = blocking + self.dependencies = dependencies + self.run = run + self.domains = domains + self.tags = tags + self.version = version + self.trust = trust @swagger.model() -class Testcase(object): - def __init__(self): +class Testcase(models.ModelBase): + def __init__(self, _id=None, name=None, project_name=None, + description=None, url=None, creation_date=None, + tier=None, ci_loop=None, criteria=None, + blocking=None, dependencies=None, run=None, + domains=None, tags=None, version=None, + trust=None): self._id = None self.name = None self.project_name = None self.description = None self.url = None self.creation_date = None - - @staticmethod - def from_dict(a_dict): - - if a_dict is None: - return None - - t = Testcase() - t._id = a_dict.get('_id') - t.project_name = a_dict.get('project_name') - t.creation_date = a_dict.get('creation_date') - t.name = a_dict.get('name') - t.description = a_dict.get('description') - t.url = a_dict.get('url') - - return t - - def format(self): - return { - "name": self.name, - "description": self.description, - "project_name": self.project_name, - "creation_date": str(self.creation_date), - "url": self.url - } - - def format_http(self): - return { - "_id": str(self._id), - "name": self.name, - "project_name": self.project_name, - "description": self.description, - "creation_date": str(self.creation_date), - "url": self.url, - } + self.tier = None + self.ci_loop = None + self.criteria = None + self.blocking = None + self.dependencies = None + self.run = None + self.domains = None + self.tags = None + self.version = None + self.trust = None @swagger.model() -class Testcases(object): +class Testcases(models.ModelBase): """ @property testcases: @ptype testcases: C{list} of L{Testcase} @@ -95,11 +88,5 @@ class Testcases(object): self.testcases = list() @staticmethod - def from_dict(res_dict): - if res_dict is None: - return None - - res = Testcases() - for testcase in res_dict.get('testcases'): - res.testcases.append(Testcase.from_dict(testcase)) - return res + def attr_parser(): + return {'testcases': Testcase} diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py index 8479b35cd..10575a9f5 100644 --- a/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py +++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_result.py @@ -25,12 +25,14 @@ class Details(object): self.timestart = timestart self.duration = duration self.status = status + self.items = [{'item1': 1}, {'item2': 2}] def format(self): return { "timestart": self.timestart, "duration": self.duration, - "status": self.status + "status": self.status, + 'items': [{'item1': 1}, {'item2': 2}] } @staticmethod @@ -43,6 +45,7 @@ class Details(object): t.timestart = a_dict.get('timestart') t.duration = a_dict.get('duration') t.status = a_dict.get('status') + t.items = a_dict.get('items') return t @@ -104,6 +107,7 @@ class TestResultBase(TestBase): self.assertEqual(details_res.duration, details_req.duration) self.assertEqual(details_res.timestart, details_req.timestart) self.assertEqual(details_res.status, details_req.status) + self.assertEqual(details_res.items, details_req.items) self.assertEqual(result.build_tag, req.build_tag) self.assertEqual(result.scenario, req.scenario) self.assertEqual(result.criteria, req.criteria) |