summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test/testapi')
-rw-r--r--utils/test/testapi/htmlize/finish.sh17
-rw-r--r--utils/test/testapi/htmlize/htmlize.py51
-rw-r--r--utils/test/testapi/htmlize/prepare.sh28
-rw-r--r--utils/test/testapi/htmlize/push-doc-artifact.sh25
-rwxr-xr-xutils/test/testapi/install.sh14
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/handlers.py3
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/models.py8
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/pod_handlers.py6
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/project_handlers.py10
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/result_handlers.py8
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/result_models.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py61
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py87
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py10
-rw-r--r--utils/test/testapi/opnfv_testapi/router/url_mappings.py7
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/test_result.py6
16 files changed, 315 insertions, 28 deletions
diff --git a/utils/test/testapi/htmlize/finish.sh b/utils/test/testapi/htmlize/finish.sh
new file mode 100644
index 000000000..d24ae056c
--- /dev/null
+++ b/utils/test/testapi/htmlize/finish.sh
@@ -0,0 +1,17 @@
+#!/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
+
+deactivate
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..67158f211
--- /dev/null
+++ b/utils/test/testapi/htmlize/prepare.sh
@@ -0,0 +1,28 @@
+#!/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 &
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..9fc5d6be1 100644
--- a/utils/test/testapi/opnfv_testapi/resources/handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py
@@ -43,6 +43,7 @@ class GenericApiHandler(RequestHandler):
self.db_pods = 'pods'
self.db_testcases = 'testcases'
self.db_results = 'results'
+ self.db_scenarios = 'scenarios'
def prepare(self):
if self.request.method != "GET" and self.request.method != "DELETE":
@@ -227,7 +228,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 c85c1d5b1..f518c97a0 100644
--- a/utils/test/testapi/opnfv_testapi/resources/models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/models.py
@@ -24,7 +24,6 @@ class ModelBase(object):
def _format(self, excludes):
new_obj = copy.deepcopy(self)
dicts = new_obj.__dict__
- print self, self.__class__
for k in dicts.keys():
if k in excludes:
del dicts[k]
@@ -32,9 +31,9 @@ class ModelBase(object):
if hasattr(dicts[k], 'format'):
dicts[k] = dicts[k].format()
elif isinstance(dicts[k], list):
- hs = []
- for h in dicts[k]:
- hs.append(h.format())
+ 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])
@@ -71,6 +70,7 @@ class ModelBase(object):
return t
+@swagger.model()
class CreateResponse(ModelBase):
def __init__(self, href=''):
self.href = href
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/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/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 30119020b..50445fc22 100644
--- a/utils/test/testapi/opnfv_testapi/resources/result_models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/result_models.py
@@ -112,7 +112,7 @@ class TestResult(models.ModelBase):
@swagger.model()
class TestResults(models.ModelBase):
"""
- @property rgit esults:
+ @property results:
@ptype results: C{list} of L{TestResult}
"""
def __init__(self):
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
new file mode 100644
index 000000000..75754d8b9
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
@@ -0,0 +1,61 @@
+from opnfv_testapi.resources.handlers import GenericApiHandler
+from opnfv_testapi.resources.scenario_models import Scenario
+from opnfv_testapi.tornado_swagger import swagger
+
+
+class GenericScenarioHandler(GenericApiHandler):
+ def __init__(self, application, request, **kwargs):
+ super(GenericScenarioHandler, self).__init__(application,
+ request,
+ **kwargs)
+ self.table = self.db_scenarios
+ self.table_cls = Scenario
+
+
+class ScenariosCLHandler(GenericScenarioHandler):
+ @swagger.operation(nickname="List scenarios by queries")
+ def get(self):
+ """
+ @description: Retrieve scenario(s).
+ @notes: Retrieve scenario(s)
+ @return 200: all scenarios consist with query,
+ empty list if no scenario is found
+ @rtype: L{Scenarios}
+ """
+ self._list()
+
+ @swagger.operation(nickname="Create a new scenario")
+ def post(self):
+ """
+ @description: create a new scenario by name
+ @param body: scenario to be created
+ @type body: L{string}
+ @rtype: L{CreateResponse}
+ """
+ pass
+
+
+class ScenarioGURHandler(GenericScenarioHandler):
+ @swagger.operation(nickname='Get the scenario by name')
+ def get(self, name):
+ """
+ @description: get a single scenario by name
+ @rtype: L{Scenario}
+ @return 200: scenario exist
+ @raise 404: scenario not exist
+ """
+ pass
+
+ @swagger.operation(nickname="Update the scenario by name")
+ def put(self, name):
+ """
+ @description: update a single scenario by name
+ @param body: fields to be updated
+ @type body: L{string}
+ @in body: body
+ @rtype: L{Scenario}
+ @return 200: update success
+ @raise 404: scenario not exist
+ @raise 403: nothing to update
+ """
+ pass
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
new file mode 100644
index 000000000..0748a3738
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
@@ -0,0 +1,87 @@
+import models
+from opnfv_testapi.tornado_swagger import swagger
+
+
+@swagger.model()
+class ScenarioTI(models.ModelBase):
+ def __init__(self, date=None, status='silver'):
+ self.date = date
+ self.status = status
+
+
+@swagger.model()
+class ScenarioScore(models.ModelBase):
+ def __init__(self, date=None, score=''):
+ self.date = date
+ self.score = score
+
+
+@swagger.model()
+class ScenarioProject(models.ModelBase):
+ """
+ @property customs:
+ @ptype customs: C{list} of L{string}
+ @property scores:
+ @ptype scores: C{list} of L{ScenarioScore}
+ @property trust_indicators:
+ @ptype trust_indicators: C{list} of L{ScenarioTI}
+ """
+ def __init__(self,
+ name='',
+ customs=None,
+ scores=None,
+ trust_indicators=None):
+ self.name = name
+ self.customs = customs
+ self.scores = scores
+ self.trust_indicator = trust_indicators
+
+
+@swagger.model()
+class ScenarioVersion(models.ModelBase):
+ """
+ @property projects:
+ @ptype projects: C{list} of L{ScenarioProject}
+ """
+ def __init__(self, version, projects=None):
+ self.version = version
+ self.projects = projects
+
+
+@swagger.model()
+class ScenarioInstaller(models.ModelBase):
+ """
+ @property versions:
+ @ptype versions: C{list} of L{ScenarioVersion}
+ """
+ def __init__(self, installer=None, owner=None, versions=None):
+ self.installer = installer
+ self.owner = owner
+ self.versions = versions if versions else list()
+
+
+@swagger.model()
+class Scenario(models.ModelBase):
+ """
+ @property installers:
+ @ptype installers: C{list} of L{ScenarioInstaller}
+ """
+ def __init__(self, name='', create_date='', _id='', installers=None):
+ self.name = name
+ self._id = _id
+ self.create_date = create_date
+ self.installers = installers if installers else list()
+
+
+@swagger.model()
+class Scenarios(models.ModelBase):
+ """
+ @property scenarios:
+ @ptype scenarios: C{list} of L{Scenario}
+ """
+ def __init__(self):
+ self.scenarios = list()
+
+ @staticmethod
+ def attr_parser():
+ return {'scenarios': Scenario}
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/router/url_mappings.py b/utils/test/testapi/opnfv_testapi/router/url_mappings.py
index eb648ecbb..0ae3c31c3 100644
--- a/utils/test/testapi/opnfv_testapi/router/url_mappings.py
+++ b/utils/test/testapi/opnfv_testapi/router/url_mappings.py
@@ -14,7 +14,8 @@ from opnfv_testapi.resources.project_handlers import ProjectCLHandler, \
ProjectGURHandler
from opnfv_testapi.resources.result_handlers import ResultsCLHandler, \
ResultsGURHandler
-
+from opnfv_testapi.resources.scenario_handlers import ScenariosCLHandler
+from opnfv_testapi.resources.scenario_handlers import ScenarioGURHandler
mappings = [
# GET /versions => GET API version
@@ -45,4 +46,8 @@ mappings = [
# (project, case, and pod)
(r"/api/v1/results", ResultsCLHandler),
(r"/api/v1/results/([^/]+)", ResultsGURHandler),
+
+ # scenarios
+ (r"/api/v1/scenarios", ScenariosCLHandler),
+ (r"/api/v1/scenarios/([^/]+)", ScenarioGURHandler),
]
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)