本文整理汇总了Python中models.TestResult.test_result_from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python TestResult.test_result_from_dict方法的具体用法?Python TestResult.test_result_from_dict怎么用?Python TestResult.test_result_from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.TestResult
的用法示例。
在下文中一共展示了TestResult.test_result_from_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import TestResult [as 别名]
# 或者: from models.TestResult import test_result_from_dict [as 别名]
def post(self):
"""
Create a new test result
:return: status of the request
:raise HTTPError
"""
# check for request payload
if self.json_args is None:
raise HTTPError(HTTP_BAD_REQUEST)
# check for missing parameters in the request payload
if self.json_args.get("project_name") is None:
raise HTTPError(HTTP_BAD_REQUEST)
if self.json_args.get("case_name") is None:
raise HTTPError(HTTP_BAD_REQUEST)
# check for pod_name instead of id,
# keeping id for current implementations
if self.json_args.get("pod_name") is None:
raise HTTPError(HTTP_BAD_REQUEST)
# TODO : replace checks with jsonschema
# check for project
mongo_dict = yield self.db.test_projects.find_one({"name": self.json_args.get("project_name")})
if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND, "Could not find project [{}] ".format(self.json_args.get("project_name")))
# check for case
mongo_dict = yield self.db.test_cases.find_one({"name": self.json_args.get("case_name")})
if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND, "Could not find case [{}] ".format(self.json_args.get("case_name")))
# check for pod
mongo_dict = yield self.db.pod.find_one({"name": self.json_args.get("pod_name")})
if mongo_dict is None:
raise HTTPError(HTTP_NOT_FOUND, "Could not find POD [{}] ".format(self.json_args.get("pod_name")))
# convert payload to object
test_result = TestResult.test_result_from_dict(self.json_args)
test_result.creation_date = datetime.now()
future = self.db.test_results.insert(test_result.format(), check_keys=False)
result = yield future
test_result._id = result
self.finish_request(test_result.format_http())
示例2: get
# 需要导入模块: from models import TestResult [as 别名]
# 或者: from models.TestResult import test_result_from_dict [as 别名]
def get(self, result_id=None):
"""
Retrieve dashboard ready result(s) for a test project
Available filters for this request are :
- project : project name
- case : case name
- pod : pod name
- version : platform version (Arno-R1, ...)
- installer (fuel, ...)
- period : x (x last days)
:param result_id: Get a result by ID
:raise HTTPError
GET /dashboard?project=functest&case=vPing&version=Arno-R1 \
&pod=pod_name&period=15
=> get results with optional filters
"""
project_arg = self.get_query_argument("project", None)
case_arg = self.get_query_argument("case", None)
pod_arg = self.get_query_argument("pod", None)
version_arg = self.get_query_argument("version", None)
installer_arg = self.get_query_argument("installer", None)
period_arg = self.get_query_argument("period", None)
# prepare request
get_request = dict()
# /dashboard?project=<>&pod=<>...
if result_id is None:
if project_arg is not None:
get_request["project_name"] = project_arg
if case_arg is not None:
get_request["case_name"] = case_arg
if pod_arg is not None:
get_request["pod_name"] = pod_arg
if version_arg is not None:
get_request["version"] = version_arg
if installer_arg is not None:
get_request["installer"] = installer_arg
if period_arg is not None:
try:
period_arg = int(period_arg)
except:
raise HTTPError(HTTP_BAD_REQUEST)
if period_arg > 0:
period = datetime.now() - timedelta(days=period_arg)
obj = {"$gte": str(period)}
get_request["creation_date"] = obj
else:
get_request["_id"] = result_id
dashboard = []
# on /dashboard retrieve the list of projects and testcases
# ready for dashboard
if project_arg is None:
raise HTTPError(HTTP_NOT_FOUND, "error:Project name missing")
elif check_dashboard_ready_project(project_arg, "./dashboard"):
res = []
if case_arg is None:
raise HTTPError(HTTP_NOT_FOUND, "error:Test case missing for project " + project_arg)
# special case of status for project
if case_arg == "status":
del get_request["case_name"]
# retention time to be agreed
# last five days by default?
# TODO move to DB
period = datetime.now() - timedelta(days=5)
get_request["creation_date"] = {"$gte": period}
# fetching results
cursor = self.db.test_results.find(get_request)
while (yield cursor.fetch_next):
test_result = TestResult.test_result_from_dict(cursor.next_object())
res.append(test_result.format_http())
if check_dashboard_ready_case(project_arg, case_arg):
dashboard = get_dashboard_result(project_arg, case_arg, res)
else:
raise HTTPError(
HTTP_NOT_FOUND,
"error:" + case_arg + " test case not case dashboard ready on project " + project_arg,
)
else:
dashboard.append({"error": "Project not recognized or not dashboard ready"})
dashboard.append({"Dashboard-ready-projects": get_dashboard_cases("./dashboard")})
raise HTTPError(HTTP_NOT_FOUND, "error: no dashboard ready data for this project")
# fetching results
#.........这里部分代码省略.........