summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/declaration/addtestcase.php40
-rw-r--r--utils/test/declaration/index.php221
-rw-r--r--utils/test/declaration/testcases.php36
-rw-r--r--utils/test/testapi/htmlize/doc-build.sh2
-rw-r--r--utils/test/testapi/htmlize/htmlize.py5
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/handlers.py2
-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/scenario_handlers.py53
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py34
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py10
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py68
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/scenario-c1.json (renamed from utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json)2
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/scenario-c2.json73
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/test_base.py8
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py86
17 files changed, 317 insertions, 347 deletions
diff --git a/utils/test/declaration/addtestcase.php b/utils/test/declaration/addtestcase.php
deleted file mode 100644
index 0e5bed689..000000000
--- a/utils/test/declaration/addtestcase.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-function sendPostData($url, $post){
- $ch = curl_init($url);
- $headers= array('Accept: application/json','Content-Type: application/json');
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
-}
-
-if(isset($_REQUEST['url'])){
- $url=$_REQUEST['url'];
-}
-if(isset($_REQUEST['name'])){
- $name=$_REQUEST['name'];
-}
-if(isset($_REQUEST['desc'])){
- $desc=$_REQUEST['desc'];
-}
-if(isset($_REQUEST['project'])){
-
- $url_send=$_REQUEST['project'];
- $url_send="http://testresults.opnfv.org:80/test/api/v1/projects/".$url_send."/cases";
- $str_data=array('url'=>$url,'name'=>$name,'description'=>$desc);
- $str_data=json_encode($str_data);
- $res=sendPostData($url_send, $str_data);
- echo '<div class="alert alert-success"> <strong>Success!</strong> Added New test Case </div>';
-
-}else{
-
- echo '<div class="alert alert-danger"> <strong>Error!</strong> Failed to Add New test Case </div>';
-
-}
-
-?>
-
diff --git a/utils/test/declaration/index.php b/utils/test/declaration/index.php
deleted file mode 100644
index b2c5d0370..000000000
--- a/utils/test/declaration/index.php
+++ /dev/null
@@ -1,221 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <title>OPNFV DashBoard</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
- <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
-<script>
-$(function() {
-
- $('form#new_testcase').on('submit', function(){
- var selected = $('select#sel_pro2').find("option:selected").val();
- var uri = $('input#uri').val();
- var name = $('input#name').val();
- var desc = $('textarea#desc').val();
- var new_url="http://testresults.opnfv.org:80/test/api/v1/projects/"+selected+"/cases";
- $.post("addtestcase.php", {"project":selected,"url":uri,"name":name,"description":desc}, function(result){
- $("div#result").html(result);
- });
- });
-
-});
-
-$(function() {
-
- $('select#sel1').on('change', function(){
- var selected = $(this).find("option:selected").val();
- var new_url="http://testresults.opnfv.org:80/test/api/v1/projects/"+selected+"/cases";
- //$.post('testcases.php', {project: selected});
- console.log(selected);
- $.post("testcases.php", {project: selected}, function(result){
- $("div#4a").html(result);
- });
-
- });
-
-});
-</script>
-<style>
-body {
- padding : 10px ;
-}
-
-#exTab1 .tab-content {
- color : black;
- padding : 5px 15px;
-}
-
-#exTab2 h3 {
- color : white;
- background-color: #428bca;
- padding : 5px 15px;
-}
-
-/* remove border radius for the tab */
-
-#exTab1 .nav-pills > li > a {
- border-radius: 0;
-}
-
-/* change border radius for the tab , apply corners on top*/
-
-#exTab3 .nav-pills > li > a {
- border-radius: 4px 4px 0 0 ;
-}
-
-#exTab3 .tab-content {
- color : white;
- background-color: #428bca;
- padding : 5px 15px;
-}
-
-</style>
-</head>
-<body>
-
-<div class="container">
- <h1>OPNFV DASHBOARD: </h1></div>
-<div id="exTab1" class="container">
- <ul class="nav nav-pills">
- <li class="active">
- <a href="#1a" data-toggle="tab">PODS</a>
- </li>
- <li><a href="#2a" data-toggle="tab">PROJECTS</a>
- </li>
- <li><a href="#3a" data-toggle="tab">TESTCASES</a>
- </li>
- <li><a href="#5a" data-toggle="tab">ADD TESTCASE</a>
- </li>
- <li><a href="http://testresults.opnfv.org/kibana_dashboards/" >RESULTS</a>
- </li>
- </ul>
- <div class="tab-content clearfix">
- <div class="tab-pane active" id="1a">
- <table class="table table-striped">
- <thead>
- <tr>
- <th>#</th>
- <th>Pod Name</th>
- <th>Creation Date</th>
- <th>Role</th>
- <th>Mode</th>
- </tr>
- </thead>
- <?php
- $url = "http://testresults.opnfv.org:80/test/api/v1/pods";
- $response = file_get_contents($url);
- $data = json_decode($response);
- $pods = $data->pods;
- $i=1;
- foreach ( $pods as $pod ){
-
- $column_str="";
- $column_str="<tr><td>".$i."</td>";
- $column_str=$column_str."<td>".$pod->name."</td>";
- $column_str= $column_str."<td>".$pod->creation_date."</td>";
- $column_str= $column_str."<td>".$pod->role."</td>";
- $column_str= $column_str."<td>".$pod->mode."</td>";
- $column_str= $column_str."</tr>";
- echo $column_str;
- $i=$i+1;
- }
- ?>
- </table>
- </div>
- <div class="tab-pane" id="2a">
- <table class="table table-striped">
- <thead>
- <tr>
- <th>#</th>
- <th>Project</th>
- <th>Creation Date</th>
- </tr>
- </thead>
- <?php
- $url = "http://testresults.opnfv.org:80/test/api/v1/projects";
- $response = file_get_contents($url);
- $data = json_decode($response);
- $projects=$data->projects;
- $i=0;
- foreach ( $projects as $project ){
-
- $column_str="";
- $column_str="<tr><td>".$i."</td>";
- $column_str=$column_str."<td>".$project->name."</td>";
- $column_str= $column_str."<td>".$project->creation_date."</td>";
- $column_str= $column_str."</tr>";
- echo $column_str;
- $i=$i+1;
- }
-?>
- </table>
- </div>
- <div class="tab-pane" id="3a">
-<div class="form-group">
- <label for="sel1">Select list:</label>
- <select class="form-control" id="sel1">
-<?php
- $url = "http://testresults.opnfv.org:80/test/api/v1/projects";
- $response = file_get_contents($url);
- $data = json_decode($response);
- $projects=$data->projects;
- $i=0;
- $firstvalue=$projects[0]->name;
- foreach ( $projects as $project ){
- $column_str="";
- $column_str="<option>".$project->name."</option>";
- echo $column_str;
- }
-
-?>
-</select>
-</div>
- <div class="tab-pane" id="4a">
- <?php
- require "testcases.php";
- ?>
- </div>
- </div>
- <div class="tab-pane" id="5a">
- <form role="form" id="new_testcase">
-<div class="form-group">
- <label for="sel1">Select list:</label>
- <select class="form-control" id="sel_pro2">
-<?php
- $url = "http://testresults.opnfv.org:80/test/api/v1/projects";
- $response = file_get_contents($url);
- $data = json_decode($response);
- $projects=$data->projects;
- $i=0;
- $firstvalue=$projects[0]->name;
- foreach ( $projects as $project ){
- $column_str="";
- $column_str="<option>".$project->name."</option>";
- echo $column_str;
- }
-?>
-</select>
-</div>
-<div class="form-group"> <!-- Name field -->
- <label class="control-label " for="name">TestCase URI</label>
- <input class="form-control" id="uri" name="uri" type="text"/>
- </div>
-<div class="form-group"> <!-- Name field -->
- <label class="control-label " for="name">TestCase Name</label>
- <input class="form-control" id="name" name="name" type="text"/>
- </div>
-<div class="form-group"> <!-- Name field -->
- <label class="control-label " for="name">Description</label>
- <textarea class="form-control" rows="5" id="desc"></textarea>
- </div>
- <button type="submit" class="btn btn-default">Submit</button>
-</form>
- </div>
-<div class="container" id="result"></div>
- </div>
-</div>
-</body>
-</html>
diff --git a/utils/test/declaration/testcases.php b/utils/test/declaration/testcases.php
deleted file mode 100644
index 20645807e..000000000
--- a/utils/test/declaration/testcases.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
- if(isset($_REQUEST['project'])){
- $selected=$_REQUEST['project'];
- }
- else{
- $url = "http://testresults.opnfv.org:80/test/api/v1/projects";
- $response = file_get_contents($url);
- $data = json_decode($response);
- $projects=$data->projects;
- $selected=$projects[0]->name;
- }
- $new_url="http://testresults.opnfv.org:80/test/api/v1/projects/".$selected."/cases";
- $response = file_get_contents($new_url);
- $data = json_decode($response);
- $testcases=$data->testcases;
- $i=0;
- $column_str="";
- $column_str=$column_str."<table class=\"table table-striped\"><tr>";
- $column_str=$column_str."<th>#</th><th>Test Case Name</th>";
- $column_str=$column_str."<th>Creation Date</th>";
- $column_str=$column_str."<th>Description</th></tr>";
- foreach ( $testcases as $testcase ){
- $i=$i+1;
- $column_str=$column_str."<tr>";
- $column_str=$column_str."<td>".$i."</td>";
- $column_str=$column_str."<td>".$testcase->name."</td>";
- $column_str=$column_str."<td>".$testcase->creation_date."</td>";
- $column_str=$column_str."<td>".$testcase->description."</td>";
- $column_str=$column_str."</tr>";
-
- }
- $column_str=$column_str."</table>";
- echo $column_str;
-
-?>
-
diff --git a/utils/test/testapi/htmlize/doc-build.sh b/utils/test/testapi/htmlize/doc-build.sh
index e492c97b5..427b4378b 100644
--- a/utils/test/testapi/htmlize/doc-build.sh
+++ b/utils/test/testapi/htmlize/doc-build.sh
@@ -1,5 +1,7 @@
#!/bin/bash
+set -o errexit
+
# Create virtual environment
source $WORKSPACE/testapi_venv/bin/activate
diff --git a/utils/test/testapi/htmlize/htmlize.py b/utils/test/testapi/htmlize/htmlize.py
index 68d02febd..c07f98ecf 100644
--- a/utils/test/testapi/htmlize/htmlize.py
+++ b/utils/test/testapi/htmlize/htmlize.py
@@ -28,7 +28,10 @@ def main(args):
# 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 os.system(cmd) == 0:
+ exit(0)
+ else:
+ exit(1)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Create \
diff --git a/utils/test/testapi/opnfv_testapi/resources/handlers.py b/utils/test/testapi/opnfv_testapi/resources/handlers.py
index 9fc5d6be1..5f6c3df57 100644
--- a/utils/test/testapi/opnfv_testapi/resources/handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/handlers.py
@@ -228,7 +228,7 @@ class GenericApiHandler(RequestHandler):
class VersionHandler(GenericApiHandler):
- @swagger.operation(nickname='List all versions')
+ @swagger.operation(nickname='listAllVersions')
def get(self):
"""
@description: list all supported versions
diff --git a/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py b/utils/test/testapi/opnfv_testapi/resources/pod_handlers.py
index 631d4a91d..e1bd9d359 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 Pods')
+ @swagger.operation(nickname='listAllPods')
def get(self):
"""
@description: list all pods
@@ -29,7 +29,7 @@ class PodCLHandler(GenericPodHandler):
"""
self._list()
- @swagger.operation(nickname='Create a Pod')
+ @swagger.operation(nickname='createPod')
def post(self):
"""
@description: create a pod
@@ -54,7 +54,7 @@ class PodCLHandler(GenericPodHandler):
class PodGURHandler(GenericPodHandler):
- @swagger.operation(nickname='Get a Pod by pod_name')
+ @swagger.operation(nickname='getPodByName')
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 9cf698623..94c65b722 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 Projects")
+ @swagger.operation(nickname="listAllProjects")
def get(self):
"""
@description: list all projects
@@ -31,7 +31,7 @@ class ProjectCLHandler(GenericProjectHandler):
"""
self._list()
- @swagger.operation(nickname="Create a Project")
+ @swagger.operation(nickname="createProject")
def post(self):
"""
@description: create a project
@@ -56,7 +56,7 @@ class ProjectCLHandler(GenericProjectHandler):
class ProjectGURHandler(GenericProjectHandler):
- @swagger.operation(nickname='Get a Project by project_name')
+ @swagger.operation(nickname='getProjectByName')
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 a Project by project_name")
+ @swagger.operation(nickname="updateProjectByName")
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 a Project by project_name')
+ @swagger.operation(nickname='deleteProjectByName')
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 fe13c09b7..2a1ed56ee 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 Test Results")
+ @swagger.operation(nickname="queryTestResults")
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 a Test Result")
+ @swagger.operation(nickname="createTestResult")
def post(self):
"""
@description: create a test result
@@ -169,7 +169,7 @@ class ResultsCLHandler(GenericResultHandler):
class ResultsGURHandler(GenericResultHandler):
- @swagger.operation(nickname='Get a Test Result by result_id')
+ @swagger.operation(nickname='getTestResultById')
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 a Test Result by result_id")
+ @swagger.operation(nickname="updateTestResultById")
def put(self, result_id):
"""
@description: update a single result by _id
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
index 7bf3d5d53..a9b89eb89 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
@@ -14,18 +14,56 @@ class GenericScenarioHandler(GenericApiHandler):
class ScenariosCLHandler(GenericScenarioHandler):
- @swagger.operation(nickname="List scenarios by queries")
+ @swagger.operation(nickname="queryScenarios")
def get(self):
"""
@description: Retrieve scenario(s).
@notes: Retrieve scenario(s)
- @return 200: all scenarios consist with query,
+ Available filters for this request are :
+ - name : scenario name
+
+ GET /scenarios?name=scenario_1
+ @param name: scenario name
+ @type name: L{string}
+ @in name: query
+ @required name: False
+ @param installer: installer type
+ @type installer: L{string}
+ @in installer: query
+ @required installer: False
+ @param version: version
+ @type version: L{string}
+ @in version: query
+ @required version: False
+ @param project: project name
+ @type project: L{string}
+ @in project: query
+ @required project: False
+ @return 200: all scenarios satisfy queries,
empty list if no scenario is found
@rtype: L{Scenarios}
"""
- self._list()
- @swagger.operation(nickname="Create a new scenario")
+ def _set_query():
+ query = dict()
+ elem_query = dict()
+ for k in self.request.query_arguments.keys():
+ v = self.get_query_argument(k)
+ if k == 'installer':
+ elem_query["installer"] = v
+ elif k == 'version':
+ elem_query["versions.version"] = v
+ elif k == 'project':
+ elem_query["versions.projects.project"] = v
+ else:
+ query[k] = v
+ if elem_query:
+ query['installers'] = {'$elemMatch': elem_query}
+ return query
+
+ self._list(_set_query())
+
+ @swagger.operation(nickname="createScenario")
def post(self):
"""
@description: create a new scenario by name
@@ -50,7 +88,7 @@ class ScenariosCLHandler(GenericScenarioHandler):
class ScenarioGURHandler(GenericScenarioHandler):
- @swagger.operation(nickname='Get the scenario by name')
+ @swagger.operation(nickname='getScenarioByName')
def get(self, name):
"""
@description: get a single scenario by name
@@ -58,14 +96,15 @@ class ScenarioGURHandler(GenericScenarioHandler):
@return 200: scenario exist
@raise 404: scenario not exist
"""
+ self._get_one({'name': name})
pass
- @swagger.operation(nickname="Update the scenario by name")
+ @swagger.operation(nickname="updateScenarioByName")
def put(self, name):
"""
@description: update a single scenario by name
@param body: fields to be updated
- @type body: L{string}
+ @type body: L{ScenarioCreateRequest}
@in body: body
@rtype: L{Scenario}
@return 200: update success
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
index b4bb3634b..f89a12428 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
@@ -11,7 +11,7 @@ class ScenarioTI(models.ModelBase):
@swagger.model()
class ScenarioScore(models.ModelBase):
- def __init__(self, date=None, score=''):
+ def __init__(self, date=None, score='0'):
self.date = date
self.score = score
@@ -27,14 +27,19 @@ class ScenarioProject(models.ModelBase):
@ptype trust_indicators: C{list} of L{ScenarioTI}
"""
def __init__(self,
- name='',
+ project='',
customs=None,
scores=None,
trust_indicators=None):
- self.name = name
+ self.project = project
self.customs = customs
self.scores = scores
- self.trust_indicator = trust_indicators
+ self.trust_indicators = trust_indicators
+
+ @staticmethod
+ def attr_parser():
+ return {'scores': ScenarioScore,
+ 'trust_indicators': ScenarioTI}
@swagger.model()
@@ -43,10 +48,14 @@ class ScenarioVersion(models.ModelBase):
@property projects:
@ptype projects: C{list} of L{ScenarioProject}
"""
- def __init__(self, version, projects=None):
+ def __init__(self, version=None, projects=None):
self.version = version
self.projects = projects
+ @staticmethod
+ def attr_parser():
+ return {'projects': ScenarioProject}
+
@swagger.model()
class ScenarioInstaller(models.ModelBase):
@@ -54,11 +63,14 @@ class ScenarioInstaller(models.ModelBase):
@property versions:
@ptype versions: C{list} of L{ScenarioVersion}
"""
- def __init__(self, installer=None, owner=None, versions=None):
+ def __init__(self, installer=None, versions=None):
self.installer = installer
- self.owner = owner
self.versions = versions if versions else list()
+ @staticmethod
+ def attr_parser():
+ return {'versions': ScenarioVersion}
+
@swagger.model()
class ScenarioCreateRequest(models.ModelBase):
@@ -70,6 +82,10 @@ class ScenarioCreateRequest(models.ModelBase):
self.name = name
self.installers = installers if installers else list()
+ @staticmethod
+ def attr_parser():
+ return {'installers': ScenarioInstaller}
+
@swagger.model()
class Scenario(models.ModelBase):
@@ -83,6 +99,10 @@ class Scenario(models.ModelBase):
self.creation_date = create_date
self.installers = installers if installers else list()
+ @staticmethod
+ def attr_parser():
+ return {'installers': ScenarioInstaller}
+
@swagger.model()
class Scenarios(models.ModelBase):
diff --git a/utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py b/utils/test/testapi/opnfv_testapi/resources/testcase_handlers.py
index 3692b164f..100a4fd91 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 TestCases by project_name")
+ @swagger.operation(nickname="listAllTestCases")
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 a TestCase by project_name")
+ @swagger.operation(nickname="createTestCase")
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 a TestCase by project and case name')
+ @swagger.operation(nickname='getTestCaseByName')
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 a TestCase by project and case name")
+ @swagger.operation(nickname="updateTestCaseByName")
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 a TestCase by project and case name')
+ @swagger.operation(nickname='deleteTestCaseByName')
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/tests/unit/fake_pymongo.py b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
index d86d8eadf..3c4fd01a3 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/fake_pymongo.py
@@ -55,7 +55,8 @@ class MemCursor(object):
class MemDb(object):
- def __init__(self):
+ def __init__(self, name):
+ self.name = name
self.contents = []
pass
@@ -109,8 +110,59 @@ class MemDb(object):
return True
return False
- @staticmethod
- def _in(content, *args):
+ def _in(self, content, *args):
+ if self.name == 'scenarios':
+ return self._in_scenarios(content, *args)
+ else:
+ return self._in_others(content, *args)
+
+ def _in_scenarios_installer(self, installer, content):
+ hit = False
+ for s_installer in content['installers']:
+ if installer == s_installer['installer']:
+ hit = True
+
+ return hit
+
+ def _in_scenarios_version(self, version, content):
+ hit = False
+ for s_installer in content['installers']:
+ for s_version in s_installer['versions']:
+ if version == s_version['version']:
+ hit = True
+ return hit
+
+ def _in_scenarios_project(self, project, content):
+ hit = False
+ for s_installer in content['installers']:
+ for s_version in s_installer['versions']:
+ for s_project in s_version['projects']:
+ if project == s_project['project']:
+ hit = True
+
+ return hit
+
+ def _in_scenarios(self, content, *args):
+ for arg in args:
+ for k, v in arg.iteritems():
+ if k == 'installers':
+ for inner in v.values():
+ for i_k, i_v in inner.iteritems():
+ if i_k == 'installer':
+ return self._in_scenarios_installer(i_v,
+ content)
+ elif i_k == 'versions.version':
+ return self._in_scenarios_version(i_v,
+ content)
+ elif i_k == 'versions.projects.project':
+ return self._in_scenarios_project(i_v,
+ content)
+ elif content.get(k, None) != v:
+ return False
+
+ return True
+
+ def _in_others(self, content, *args):
for arg in args:
for k, v in arg.iteritems():
if k == 'start_date':
@@ -185,8 +237,8 @@ def __getattr__(name):
return globals()[name]
-pods = MemDb()
-projects = MemDb()
-testcases = MemDb()
-results = MemDb()
-scenarios = MemDb()
+pods = MemDb('pods')
+projects = MemDb('projects')
+testcases = MemDb('testcases')
+results = MemDb('results')
+scenarios = MemDb('scenarios')
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json b/utils/test/testapi/opnfv_testapi/tests/unit/scenario-c1.json
index eba8b6c0a..187802215 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/scenario-create.json
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/scenario-c1.json
@@ -35,4 +35,4 @@
]
}
]
-} \ No newline at end of file
+}
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/scenario-c2.json b/utils/test/testapi/opnfv_testapi/tests/unit/scenario-c2.json
new file mode 100644
index 000000000..b6a3b83ab
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/scenario-c2.json
@@ -0,0 +1,73 @@
+{
+ "name": "odl_2-nofeature-ha",
+ "installers":
+ [
+ {
+ "installer": "fuel",
+ "versions":
+ [
+ {
+ "owner": "Lucky",
+ "version": "colorado",
+ "projects":
+ [
+ {
+ "project": "functest",
+ "customs": [ "healthcheck", "vping_ssh"],
+ "scores": [],
+ "trust_indicators": [
+ {
+ "date": "2017-01-18 22:46:44",
+ "status": "silver"
+ }
+
+ ]
+ },
+ {
+ "project": "yardstick",
+ "customs": ["suite-a"],
+ "scores": [
+ {
+ "date": "2017-01-08 22:46:44",
+ "score": "0"
+ }
+ ],
+ "trust_indicators": [
+ {
+ "date": "2017-01-18 22:46:44",
+ "status": "gold"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "owner": "Luke",
+ "version": "colorado",
+ "projects":
+ [
+ {
+ "project": "functest",
+ "customs": [ "healthcheck", "vping_ssh"],
+ "scores":
+ [
+ {
+ "date": "2017-01-09 22:46:44",
+ "score": "11/14"
+ }
+
+ ],
+ "trust_indicators": []
+ },
+ {
+ "project": "yardstick",
+ "customs": [],
+ "scores": [],
+ "trust_indicators": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
index 9343ab2fb..fc780e44c 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_base.py
@@ -47,11 +47,11 @@ class TestBase(AsyncHTTPTestCase):
return self.create_help(self.basePath, req, *args)
def create_help(self, uri, req, *args):
- if req and not isinstance(req, str):
- req = json.dumps(req.format())
+ if req and not isinstance(req, str) and hasattr(req, 'format'):
+ req = req.format()
res = self.fetch(self._update_uri(uri, *args),
method='POST',
- body=req if req else json.dumps(None),
+ body=json.dumps(req),
headers=self.headers)
return self._get_return(res, self.create_res)
@@ -97,7 +97,7 @@ class TestBase(AsyncHTTPTestCase):
return uri.count('%s')
def _get_query_uri(self, query):
- return self.basePath + '?' + query
+ return self.basePath + '?' + query if query else self.basePath
def _get_uri(self, *args):
return self._update_uri(self.basePath, *args)
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py b/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py
index 8e827813c..ff5979524 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/test_scenario.py
@@ -4,15 +4,20 @@ import os
from opnfv_testapi.common.constants import HTTP_BAD_REQUEST
from opnfv_testapi.common.constants import HTTP_FORBIDDEN
from opnfv_testapi.common.constants import HTTP_OK
+from opnfv_testapi.resources.scenario_models import Scenario
from opnfv_testapi.resources.scenario_models import ScenarioCreateRequest
+from opnfv_testapi.resources.scenario_models import Scenarios
from test_testcase import TestBase
class TestScenarioBase(TestBase):
def setUp(self):
super(TestScenarioBase, self).setUp()
+ self.get_res = Scenario
+ self.list_res = Scenarios
self.basePath = '/api/v1/scenarios'
- self.load_request('scenario-create.json')
+ self.req_d = self._load_request('scenario-c1.json')
+ self.req_2 = self._load_request('scenario-c2.json')
def tearDown(self):
pass
@@ -20,10 +25,26 @@ class TestScenarioBase(TestBase):
def assert_body(self, project, req=None):
pass
- def load_request(self, f_req):
- with open(os.path.join(os.path.dirname(__file__), f_req), 'r') as f:
- self.req_d = json.dumps(json.load(f))
+ @staticmethod
+ def _load_request(f_req):
+ abs_file = os.path.join(os.path.dirname(__file__), f_req)
+ with open(abs_file, 'r') as f:
+ loader = json.load(f)
f.close()
+ return loader
+
+ def create_return_name(self, req):
+ _, res = self.create(req)
+ return res.href.split('/')[-1]
+
+ def assert_res(self, code, scenario, req=None):
+ self.assertEqual(code, HTTP_OK)
+ if req is None:
+ req = self.req_d
+ scenario_dict = scenario.format_http()
+ self.assertIsNotNone(scenario_dict['_id'])
+ self.assertIsNotNone(scenario_dict['creation_date'])
+ self.assertDictContainsSubset(req, scenario_dict)
class TestScenarioCreate(TestScenarioBase):
@@ -53,3 +74,60 @@ class TestScenarioCreate(TestScenarioBase):
(code, body) = self.create_d()
self.assertEqual(code, HTTP_FORBIDDEN)
self.assertIn('already exists', body)
+
+
+class TestScenarioGet(TestScenarioBase):
+ def setUp(self):
+ super(TestScenarioGet, self).setUp()
+ self.scenario_1 = self.create_return_name(self.req_d)
+ self.scenario_2 = self.create_return_name(self.req_2)
+
+ def test_getByName(self):
+ code, body = self.get(self.scenario_1)
+ self.assert_res(code, body, req=self.req_d)
+
+ def test_getAll(self):
+ self._query_and_assert(query=None, reqs=[self.req_d, self.req_2])
+
+ def test_queryName(self):
+ query = self._set_query('name=nosdn-nofeature-ha')
+ self._query_and_assert(query, reqs=[self.req_d])
+
+ def test_queryInstaller(self):
+ query = self._set_query('installer=apex')
+ self._query_and_assert(query, reqs=[self.req_d])
+
+ def test_queryVersion(self):
+ query = self._set_query('version=master')
+ self._query_and_assert(query, reqs=[self.req_d])
+
+ def test_queryProject(self):
+ query = self._set_query('project=functest')
+ self._query_and_assert(query, reqs=[self.req_d, self.req_2])
+
+ def test_queryCombination(self):
+ query = self._set_query('name=nosdn-nofeature-ha',
+ 'installer=apex',
+ 'version=master',
+ 'project=functest')
+
+ self._query_and_assert(query, reqs=[self.req_d])
+
+ @staticmethod
+ def _set_query(*args):
+ uri = ''
+ for arg in args:
+ uri += arg + '&'
+ return uri[0: -1]
+
+ def _query_and_assert(self, query, found=True, reqs=None):
+ code, body = self.query(query)
+ if not found:
+ self.assertEqual(code, HTTP_OK)
+ self.assertEqual(0, len(body.scenarios))
+ else:
+ self.assertEqual(len(reqs), len(body.scenarios))
+ for req in reqs:
+ for scenario in body.scenarios:
+ if req['name'] == scenario.name:
+ self.assert_res(code, scenario, req)