summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
authorgrkoffi <koffirodrigue@gmail.com>2015-09-04 09:21:19 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2015-09-04 09:21:19 +0000
commit46fd62a707f5fc241c6701a9f787fd78c8680182 (patch)
tree1ab91e7160cb5c413837295fc9ad001e7b0ef122 /utils/test
parent034768f50e125bbda5f4d23af3e1795877519f45 (diff)
parentaa6aac09a5a0651b4ef28c1ccc78ca32a1fccf7f (diff)
Merge "Fix minor bugs for result_collection_api"
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/result_collection_api/common/constants.py6
-rw-r--r--utils/test/result_collection_api/resources/handlers.py41
-rw-r--r--utils/test/result_collection_api/resources/models.py8
-rw-r--r--utils/test/result_collection_api/result_collection_api.py10
4 files changed, 36 insertions, 29 deletions
diff --git a/utils/test/result_collection_api/common/constants.py b/utils/test/result_collection_api/common/constants.py
index 485dbf314..21769564c 100644
--- a/utils/test/result_collection_api/common/constants.py
+++ b/utils/test/result_collection_api/common/constants.py
@@ -8,11 +8,11 @@
##############################################################################
-API_LISTENING_PORT = 8000
+API_LISTENING_PORT = 80
-MONGO_URL = "mongodb://192.168.56.102:27017/"
+MONGO_URL = "mongodb://127.0.0.1:27017/"
-APPLICATION_JSON = "application/json"
+DEFAULT_REPRESENTATION = "application/json"
HTTP_BAD_REQUEST = 400
HTTP_FORBIDDEN = 403
HTTP_NOT_FOUND = 404
diff --git a/utils/test/result_collection_api/resources/handlers.py b/utils/test/result_collection_api/resources/handlers.py
index 64f75c287..35aea0c9d 100644
--- a/utils/test/result_collection_api/resources/handlers.py
+++ b/utils/test/result_collection_api/resources/handlers.py
@@ -32,7 +32,7 @@ class GenericApiHandler(RequestHandler):
def prepare(self):
if not (self.request.method == "GET"):
- if not (self.request.headers.get("Content-Type") is None):
+ if self.request.headers.get("Content-Type") is not None:
if self.request.headers["Content-Type"].startswith(
DEFAULT_REPRESENTATION):
try:
@@ -159,7 +159,7 @@ class TestProjectHandler(GenericApiHandler):
# check for name in db
mongo_dict = yield self.db.test_projects.find_one(query)
- if not (mongo_dict is None):
+ if mongo_dict is not None:
raise HTTPError(HTTP_FORBIDDEN,
"{} already exists as a project".format(
self.json_args.get("name")))
@@ -195,7 +195,7 @@ class TestProjectHandler(GenericApiHandler):
if new_name != test_project.name:
mongo_dict = yield self.db.test_projects.find_one(
{"name": new_name})
- if not (mongo_dict is None):
+ if mongo_dict is not None:
raise HTTPError(HTTP_FORBIDDEN,
"{} already exists as a project"
.format(new_name))
@@ -235,9 +235,9 @@ class TestProjectHandler(GenericApiHandler):
print "DELETE request for : {}".format(project_name)
- # check for an existing case to be deleted
- mongo_dict = yield self.db.test_cases.find_one(
- {'project_name': project_name})
+ # check for an existing project to be deleted
+ mongo_dict = yield self.db.test_projects.find_one(
+ {'name': project_name})
test_project = TestProject.testproject_from_dict(mongo_dict)
if test_project is None:
raise HTTPError(HTTP_NOT_FOUND,
@@ -246,7 +246,7 @@ class TestProjectHandler(GenericApiHandler):
# just delete it, or maybe save it elsewhere in a future
res = yield self.db.test_projects.remove(
- {'project_name': project_name})
+ {'name': project_name})
print res
self.finish_request({"message": "success"})
@@ -358,7 +358,7 @@ class TestCasesHandler(GenericApiHandler):
# with the name provided in the json payload
mongo_dict = yield self.db.test_cases.find_one(
{'project_name': new_project_name, 'name': new_name})
- if not (mongo_dict is None):
+ if mongo_dict is not None:
raise HTTPError(HTTP_FORBIDDEN,
"{} already exists as a project"
.format(new_name))
@@ -450,39 +450,38 @@ class TestResultsHandler(GenericApiHandler):
"""
project_arg = self.get_query_argument("project", None)
- case_arg = self.get_query_arguments("case", None)
- pod_arg = self.get_query_arguments("pod", None)
+ case_arg = self.get_query_argument("case", None)
+ pod_arg = self.get_query_argument("pod", None)
# prepare request
get_request = dict()
if result_id is None:
- if not (project_arg is None):
+ if project_arg is not None:
get_request["project_name"] = project_arg
- if not (case_arg is None):
+ if case_arg is not None:
get_request["case_name"] = case_arg
- if not (pod_arg is None):
+ if pod_arg is not None:
get_request["pod_id"] = pod_arg
else:
get_request["_id"] = result_id
res = []
# fetching results
- cursor = self.db.test_cases.find(get_request)
+ cursor = self.db.test_results.find(get_request)
while (yield cursor.fetch_next):
- test_case = TestCase.test_case_from_dict(cursor.next_object)
- res.append(test_case.format_http())
+ test_result = TestResult.test_result_from_dict(cursor.next_object())
+ res.append(test_result.format_http())
# building meta object
meta = dict()
- meta["total"] = res.count()
+ meta["total"] = len(res)
# final response object
answer = dict()
answer["test_results"] = res
answer["meta"] = meta
-
self.finish_request(answer)
@asynchronous
@@ -510,7 +509,7 @@ class TestResultsHandler(GenericApiHandler):
# check for project
mongo_dict = yield self.db.test_projects.find_one(
{"name": self.json_args.get("project_name")})
- if not (mongo_dict is None):
+ if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND,
"Could not find project [{}] "
.format(self.json_args.get("project_name")))
@@ -518,7 +517,7 @@ class TestResultsHandler(GenericApiHandler):
# check for case
mongo_dict = yield self.db.test_cases.find_one(
{"name": self.json_args.get("case_name")})
- if not (mongo_dict is None):
+ if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND,
"Could not find case [{}] "
.format(self.json_args.get("case_name")))
@@ -526,7 +525,7 @@ class TestResultsHandler(GenericApiHandler):
# check for pod
mongo_dict = yield self.db.pod.find_one(
{"_id": self.json_args.get("pod_id")})
- if not (mongo_dict is None):
+ if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND,
"Could not find POD [{}] "
.format(self.json_args.get("pod_id")))
diff --git a/utils/test/result_collection_api/resources/models.py b/utils/test/result_collection_api/resources/models.py
index bb4cb0cf1..82c17fda3 100644
--- a/utils/test/result_collection_api/resources/models.py
+++ b/utils/test/result_collection_api/resources/models.py
@@ -114,7 +114,7 @@ class TestCase:
"description": self.description,
"creation_date": str(self.creation_date),
}
- if not (test_project is None):
+ if test_project is not None:
res["test_project"] = test_project
return res
@@ -128,6 +128,8 @@ class TestResult:
self.case_name = None
self.project_name = None
self.pod_id = None
+ self.installer = None
+ self.platform_version = None
self.description = None
self.creation_date = None
self.details = None
@@ -155,7 +157,7 @@ class TestResult:
"project_name": self.project_name,
"pod_id": self.pod_id,
"description": self.description,
- "creation_date": self.creation_date,
+ "creation_date": str(self.creation_date),
"details": self.details,
}
@@ -166,6 +168,6 @@ class TestResult:
"project_name": self.project_name,
"pod_id": self.pod_id,
"description": self.description,
- "creation_date": self.creation_date,
+ "creation_date": str(self.creation_date),
"details": self.details,
}
diff --git a/utils/test/result_collection_api/result_collection_api.py b/utils/test/result_collection_api/result_collection_api.py
index 71b3267c2..bb26bb25e 100644
--- a/utils/test/result_collection_api/result_collection_api.py
+++ b/utils/test/result_collection_api/result_collection_api.py
@@ -14,13 +14,18 @@ Pre-requisites:
We can launch the API with this file
-TODOS :
+TODOs :
- json args validation with schemes
- count cases for GET on test_projects
- count results for GET on cases
- - add meta object to json response
- provide filtering on requests
- include objects
+ - logging
+ - external configuration file
+ - setup file
+ - results pagination
+ - POST/PUT/DELETE for PODs
+ - POST/PUT/GET/DELETE for installers, platforms (enrich results info)
"""
@@ -66,6 +71,7 @@ def make_app():
# POST /results =>
# Push results with mandatory request payload parameters
# (project, case, and pod_id)
+ (r"/results", TestResultsHandler),
(r"/results([^/]*)", TestResultsHandler),
(r"/results/([^/]*)", TestResultsHandler),
],