aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStamatis Katsaounis <mokats@intracom-telecom.com>2018-10-04 12:42:16 +0300
committerStamatis Katsaounis <mokats@intracom-telecom.com>2018-10-04 12:42:16 +0300
commitc05e2986e658d9892c9d65203a1e2a785c68bf27 (patch)
tree329e16bee025b4db9f9f43ad143b1aca776d7bd8
parent19724cbcef2508f97ddcc7fdef7e7bb44288634c (diff)
Revive unit tests and flake8 of webportal
JIRA: DOVETAIL-742 This patch revives unit test and flake8 tests of webportal. In addition, it fixes errors and enables handling of some uris which were forgotten. Change-Id: I8225c7ca08a3c97b6e77f00490defc91046a2dd6 Signed-off-by: Stamatis Katsaounis <mokats@intracom-telecom.com>
-rw-r--r--docker/db/get_db_schema.py8
-rw-r--r--docker/db/init_db.py2
-rw-r--r--opnfv_testapi/common/config.py2
-rw-r--r--opnfv_testapi/common/message.py4
-rw-r--r--opnfv_testapi/resources/handlers.py4
-rw-r--r--opnfv_testapi/resources/models.py4
-rw-r--r--opnfv_testapi/resources/result_handlers.py2
-rw-r--r--opnfv_testapi/resources/scenario_handlers.py2
-rw-r--r--opnfv_testapi/router/url_mappings.py13
-rw-r--r--opnfv_testapi/tests/unit/common/normal.ini1
-rw-r--r--opnfv_testapi/tests/unit/executor.py2
-rw-r--r--opnfv_testapi/tests/unit/fake_pymongo.py2
-rw-r--r--opnfv_testapi/tests/unit/resources/test_result.py2
-rw-r--r--tox.ini1
-rwxr-xr-xutils/generate-testcase-list/generate-testcases-list.py10
15 files changed, 40 insertions, 19 deletions
diff --git a/docker/db/get_db_schema.py b/docker/db/get_db_schema.py
index 1106355..16ed3da 100644
--- a/docker/db/get_db_schema.py
+++ b/docker/db/get_db_schema.py
@@ -18,7 +18,7 @@ def get(url):
try:
ret = requests.get(url)
return ret.json()
- except:
+ except Exception:
return None
@@ -28,7 +28,7 @@ def pod():
pods = get(source)['pods']
with open("pods.json", "w") as f:
f.write(json.dumps(pods, indent=4))
- except:
+ except Exception:
return
@@ -39,7 +39,7 @@ def project():
projects = get(source)['projects']
with open("projects.json", "w") as f:
f.write(json.dumps(projects, indent=4))
- except:
+ except Exception:
return
for p in projects:
@@ -52,7 +52,7 @@ def project():
f.write(json.dumps(cases))
f.write('\n')
f.close()
- except:
+ except Exception:
print("useless data")
diff --git a/docker/db/init_db.py b/docker/db/init_db.py
index 2aac6fc..afed693 100644
--- a/docker/db/init_db.py
+++ b/docker/db/init_db.py
@@ -58,7 +58,7 @@ def cases():
c['project_name'])
print(target)
post(target, c)
- except:
+ except Exception:
print("useless data")
add_case("functest", "tempest_custom")
diff --git a/opnfv_testapi/common/config.py b/opnfv_testapi/common/config.py
index 75dbc35..a6ab338 100644
--- a/opnfv_testapi/common/config.py
+++ b/opnfv_testapi/common/config.py
@@ -49,7 +49,7 @@ class Config(object):
def _parse_value(value):
try:
value = int(value)
- except:
+ except Exception:
if str(value).lower() == 'true':
value = True
elif str(value).lower() == 'false':
diff --git a/opnfv_testapi/common/message.py b/opnfv_testapi/common/message.py
index 61ce03d..e9b3b1c 100644
--- a/opnfv_testapi/common/message.py
+++ b/opnfv_testapi/common/message.py
@@ -14,6 +14,10 @@ def key_error(key):
return "KeyError: '{}'".format(key)
+def no_file_uploaded():
+ return "Please upload a file."
+
+
def no_body():
return 'No Body'
diff --git a/opnfv_testapi/resources/handlers.py b/opnfv_testapi/resources/handlers.py
index 9b156e1..e8c81f3 100644
--- a/opnfv_testapi/resources/handlers.py
+++ b/opnfv_testapi/resources/handlers.py
@@ -55,7 +55,7 @@ class GenericApiHandler(web.RequestHandler):
def get_int(self, key, value):
try:
value = int(value)
- except:
+ except Exception:
raises.BadRequest(message.must_int(key))
return value
@@ -327,5 +327,5 @@ class VersionHandler(GenericApiHandler):
@description: list all supported versions
@rtype: L{Versions}
"""
- versions = [{'version': 'api.cvp.0.7.0', 'description': 'basics'}]
+ versions = [{'version': 'v1.0', 'description': 'basics'}]
self.finish_request({'versions': versions})
diff --git a/opnfv_testapi/resources/models.py b/opnfv_testapi/resources/models.py
index e8fc532..06db995 100644
--- a/opnfv_testapi/resources/models.py
+++ b/opnfv_testapi/resources/models.py
@@ -68,10 +68,10 @@ class ModelBase(object):
elif isinstance(obj, unicode):
try:
obj = self._obj_format(ast.literal_eval(obj))
- except:
+ except Exception:
try:
obj = str(obj)
- except:
+ except Exception:
obj = obj
elif isinstance(obj, list):
hs = list()
diff --git a/opnfv_testapi/resources/result_handlers.py b/opnfv_testapi/resources/result_handlers.py
index b7b5c2b..b8d166c 100644
--- a/opnfv_testapi/resources/result_handlers.py
+++ b/opnfv_testapi/resources/result_handlers.py
@@ -37,7 +37,7 @@ class GenericResultHandler(handlers.GenericApiHandler):
def get_int(self, key, value):
try:
value = int(value)
- except:
+ except Exception:
raises.BadRequest(message.must_int(key))
return value
diff --git a/opnfv_testapi/resources/scenario_handlers.py b/opnfv_testapi/resources/scenario_handlers.py
index 5d420a5..0aa6063 100644
--- a/opnfv_testapi/resources/scenario_handlers.py
+++ b/opnfv_testapi/resources/scenario_handlers.py
@@ -16,7 +16,7 @@ class GenericScenarioHandler(handlers.GenericApiHandler):
self.table_cls = models.Scenario
-class ScenariosCLHandler(GenericScenarioHandler):
+class ScenarioCLHandler(GenericScenarioHandler):
@swagger.operation(nickname="queryScenarios")
def get(self):
"""
diff --git a/opnfv_testapi/router/url_mappings.py b/opnfv_testapi/router/url_mappings.py
index e1d4c18..55f1c0e 100644
--- a/opnfv_testapi/router/url_mappings.py
+++ b/opnfv_testapi/router/url_mappings.py
@@ -11,13 +11,18 @@ from opnfv_testapi.resources import handlers
from opnfv_testapi.resources import result_handlers
from opnfv_testapi.resources import test_handlers
from opnfv_testapi.resources import application_handlers
+from opnfv_testapi.resources import pod_handlers
+from opnfv_testapi.resources import project_handlers
+from opnfv_testapi.resources import scenario_handlers
from opnfv_testapi.resources import sut_handlers
+from opnfv_testapi.resources import testcase_handlers
from opnfv_testapi.ui.auth import sign
from opnfv_testapi.ui.auth import user
mappings = [
(r"/versions", handlers.VersionHandler),
+ (r"/api/v1/results", result_handlers.ResultsCLHandler),
(r"/api/v1/results/upload", result_handlers.ResultsUploadHandler),
(r"/api/v1/results/([^/]+)", result_handlers.ResultsGURHandler),
@@ -34,6 +39,14 @@ mappings = [
(r"/api/v1/suts/hardware/([^/]+)", sut_handlers.HardwareHandler),
+ (r"/api/v1/pods", pod_handlers.PodCLHandler),
+ (r"/api/v1/pods/([^/]+)", pod_handlers.PodGURHandler),
+ (r"/api/v1/scenarios", scenario_handlers.ScenarioCLHandler),
+ (r"/api/v1/scenarios/([^/]+)", scenario_handlers.ScenarioGURHandler),
+ (r"/api/v1/projects", project_handlers.ProjectCLHandler),
+ (r"/api/v1/projects/([^/]+)", project_handlers.ProjectGURHandler),
+ (r"/api/v1/projects/([^/]+)/cases", testcase_handlers.TestcaseCLHandler),
+ (r"/api/v1/projects/([^/]+)/cases/([^/]+)", testcase_handlers.TestcaseGURHandler),
(r'/api/v1/auth/signin', sign.SigninHandler),
(r'/api/v1/auth/signin_return', sign.SigninReturnHandler),
diff --git a/opnfv_testapi/tests/unit/common/normal.ini b/opnfv_testapi/tests/unit/common/normal.ini
index 77cc6c6..6906913 100644
--- a/opnfv_testapi/tests/unit/common/normal.ini
+++ b/opnfv_testapi/tests/unit/common/normal.ini
@@ -12,6 +12,7 @@ port = 8000
# With debug_on set to true, error traces will be shown in HTTP responses
debug = True
authenticate = False
+log_file = /dev/null
[swagger]
base_url = http://localhost:8000
diff --git a/opnfv_testapi/tests/unit/executor.py b/opnfv_testapi/tests/unit/executor.py
index b8f696c..72d9d33 100644
--- a/opnfv_testapi/tests/unit/executor.py
+++ b/opnfv_testapi/tests/unit/executor.py
@@ -18,6 +18,8 @@ def upload(excepted_status, excepted_response):
status, body = self.upload(request)
if excepted_status == httplib.OK:
getattr(self, excepted_response)(body)
+ elif excepted_status == httplib.BAD_REQUEST:
+ self.assertEqual(excepted_response, body.msg)
else:
self.assertIn(excepted_response, body)
return wrap
diff --git a/opnfv_testapi/tests/unit/fake_pymongo.py b/opnfv_testapi/tests/unit/fake_pymongo.py
index 0ca83df..28ea966 100644
--- a/opnfv_testapi/tests/unit/fake_pymongo.py
+++ b/opnfv_testapi/tests/unit/fake_pymongo.py
@@ -207,7 +207,7 @@ class MemDb(object):
def _aggregate(self, *args, **kwargs):
res = self.contents
- print args
+ print(args)
for arg in args[0]:
for k, v in arg.iteritems():
if k == '$match':
diff --git a/opnfv_testapi/tests/unit/resources/test_result.py b/opnfv_testapi/tests/unit/resources/test_result.py
index 1e83ed3..3f87f11 100644
--- a/opnfv_testapi/tests/unit/resources/test_result.py
+++ b/opnfv_testapi/tests/unit/resources/test_result.py
@@ -144,7 +144,7 @@ class TestResultBase(base.TestBase):
class TestResultUpload(TestResultBase):
- @executor.upload(httplib.BAD_REQUEST, message.key_error('file'))
+ @executor.upload(httplib.BAD_REQUEST, message.no_file_uploaded())
def test_filenotfind(self):
return None
diff --git a/tox.ini b/tox.ini
index d300f1a..c9f5a6e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,6 +9,7 @@ skipsdist = True
sitepackages = True
[testenv]
+basepython = python2.7
usedevelop = True
install_command = pip install -U {opts} {packages}
deps =
diff --git a/utils/generate-testcase-list/generate-testcases-list.py b/utils/generate-testcase-list/generate-testcases-list.py
index 5bfaa2f..b7b78cf 100755
--- a/utils/generate-testcase-list/generate-testcases-list.py
+++ b/utils/generate-testcase-list/generate-testcases-list.py
@@ -35,13 +35,13 @@ class TestcaseList:
except IOError:
error = 'Testsuite definition file not found: "{}"'.\
format(self.testsuite)
- print error
+ print(error)
os.sys.exit(-1)
except yaml.scanner.ScannerError:
error = 'Reading test suite definition failed. ' \
'Not a valid yaml file: "{}"'. \
format(self.testsuite)
- print error
+ print(error)
os.sys.exit(-1)
return testsuite_data
@@ -59,7 +59,7 @@ class TestcaseList:
error = 'Reading test case definition failed.' \
'Not a valid yaml file: "{}"'. \
format(file_path)
- print error
+ print(error)
os.sys.exit(-1)
return testcases
@@ -91,8 +91,8 @@ class TestcaseList:
total_per_area += tc['total']
testcase_list[area][name] = tc
- print "Total number of test cases in area {}: {}".format(
- area, total_per_area)
+ print("Total number of test cases in area {}: {}".format(
+ area, total_per_area))
output_file = os.path.join(self.output_dir, 'testcases.json')
with open(output_file, 'w') as file: