Negative tests: Add result check for resources
This add an result check if a invalid resource is given. Introducing a new dict that can be enhanced later for other cases. Change-Id: Ief3e51fafb9437a8e6b9a71aad79459716bac3d4 Partially-implements: bp negative-tests
This commit is contained in:
parent
924081bcb1
commit
424c84fd6e
@ -2,5 +2,7 @@
|
|||||||
"name": "get-flavor-details",
|
"name": "get-flavor-details",
|
||||||
"http-method": "GET",
|
"http-method": "GET",
|
||||||
"url": "flavors/%s",
|
"url": "flavors/%s",
|
||||||
"resources": ["flavor"]
|
"resources": [
|
||||||
|
{"name": "flavor", "expected_result": 404}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
"name": "get-console-output",
|
"name": "get-console-output",
|
||||||
"http-method": "POST",
|
"http-method": "POST",
|
||||||
"url": "servers/%s/action",
|
"url": "servers/%s/action",
|
||||||
"resources": ["server"],
|
"resources": [
|
||||||
|
{"name":"server", "expected_result": 404}
|
||||||
|
],
|
||||||
"json-schema": {
|
"json-schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -203,36 +203,62 @@ def gen_inv_prop_obj(schema):
|
|||||||
return invalids
|
return invalids
|
||||||
|
|
||||||
|
|
||||||
type_map_valid = {"string": generate_valid_string,
|
type_map_valid = {
|
||||||
"integer": generate_valid_integer,
|
"string": generate_valid_string,
|
||||||
"object": generate_valid_object}
|
"integer": generate_valid_integer,
|
||||||
|
"object": generate_valid_object
|
||||||
|
}
|
||||||
|
|
||||||
type_map_invalid = {"string": [gen_int,
|
type_map_invalid = {
|
||||||
gen_none,
|
"string": [
|
||||||
gen_str_min_length,
|
gen_int,
|
||||||
gen_str_max_length],
|
gen_none,
|
||||||
"integer": [gen_string,
|
gen_str_min_length,
|
||||||
gen_none,
|
gen_str_max_length],
|
||||||
gen_int_min,
|
"integer": [
|
||||||
gen_int_max],
|
gen_string,
|
||||||
"object": [gen_obj_remove_attr,
|
gen_none,
|
||||||
gen_obj_add_attr,
|
gen_int_min,
|
||||||
gen_inv_prop_obj]}
|
gen_int_max],
|
||||||
|
"object": [
|
||||||
|
gen_obj_remove_attr,
|
||||||
|
gen_obj_add_attr,
|
||||||
|
gen_inv_prop_obj]
|
||||||
|
}
|
||||||
|
|
||||||
schema = {"type": "object",
|
schema = {
|
||||||
"properties":
|
"type": "object",
|
||||||
{"name": {"type": "string"},
|
"properties": {
|
||||||
"http-method": {"enum": ["GET", "PUT", "HEAD",
|
"name": {"type": "string"},
|
||||||
"POST", "PATCH", "DELETE", 'COPY']},
|
"http-method": {
|
||||||
"url": {"type": "string"},
|
"enum": ["GET", "PUT", "HEAD",
|
||||||
"json-schema": jsonschema._utils.load_schema("draft4"),
|
"POST", "PATCH", "DELETE", 'COPY']
|
||||||
"resources": {"type": "array", "items": {"type": "string"}},
|
},
|
||||||
"results": {"type": "object",
|
"url": {"type": "string"},
|
||||||
"properties": {}}
|
"json-schema": jsonschema._utils.load_schema("draft4"),
|
||||||
},
|
"resources": {
|
||||||
"required": ["name", "http-method", "url"],
|
"type": "array",
|
||||||
"additionalProperties": False,
|
"items": {
|
||||||
}
|
"oneOf": [
|
||||||
|
{"type": "string"},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": {"type": "string"},
|
||||||
|
"expected_result": {"type": "integer"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"results": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["name", "http-method", "url"],
|
||||||
|
"additionalProperties": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def validate_negative_test_schema(nts):
|
def validate_negative_test_schema(nts):
|
||||||
|
@ -405,11 +405,16 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
schema = description.get("json-schema", None)
|
schema = description.get("json-schema", None)
|
||||||
resources = description.get("resources", [])
|
resources = description.get("resources", [])
|
||||||
scenario_list = []
|
scenario_list = []
|
||||||
|
expected_result = None
|
||||||
for resource in resources:
|
for resource in resources:
|
||||||
|
if isinstance(resource, dict):
|
||||||
|
expected_result = resource['expected_result']
|
||||||
|
resource = resource['name']
|
||||||
LOG.debug("Add resource to test %s" % resource)
|
LOG.debug("Add resource to test %s" % resource)
|
||||||
scn_name = "inv_res_%s" % (resource)
|
scn_name = "inv_res_%s" % (resource)
|
||||||
scenario_list.append((scn_name, {"resource": (resource,
|
scenario_list.append((scn_name, {"resource": (resource,
|
||||||
str(uuid.uuid4()))
|
str(uuid.uuid4())),
|
||||||
|
"expected_result": expected_result
|
||||||
}))
|
}))
|
||||||
if schema is not None:
|
if schema is not None:
|
||||||
for invalid in generate_json.generate_invalid(schema):
|
for invalid in generate_json.generate_invalid(schema):
|
||||||
@ -460,16 +465,12 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
if schema:
|
if schema:
|
||||||
valid = generate_json.generate_valid(schema)
|
valid = generate_json.generate_valid(schema)
|
||||||
new_url, body = self._http_arguments(valid, url, method)
|
new_url, body = self._http_arguments(valid, url, method)
|
||||||
resp, resp_body = self.client.send_request(method, new_url,
|
elif hasattr(self, "schema"):
|
||||||
resources, body=body)
|
|
||||||
self._check_negative_response(resp.status, resp_body)
|
|
||||||
return
|
|
||||||
|
|
||||||
if hasattr(self, "schema"):
|
|
||||||
new_url, body = self._http_arguments(self.schema, url, method)
|
new_url, body = self._http_arguments(self.schema, url, method)
|
||||||
resp, resp_body = self.client.send_request(method, new_url,
|
|
||||||
resources, body=body)
|
resp, resp_body = self.client.send_request(method, new_url,
|
||||||
self._check_negative_response(resp.status, resp_body)
|
resources, body=body)
|
||||||
|
self._check_negative_response(resp.status, resp_body)
|
||||||
|
|
||||||
def _http_arguments(self, json_dict, url, method):
|
def _http_arguments(self, json_dict, url, method):
|
||||||
LOG.debug("dict: %s url: %s method: %s" % (json_dict, url, method))
|
LOG.debug("dict: %s url: %s method: %s" % (json_dict, url, method))
|
||||||
@ -510,6 +511,8 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
:param name: The name of the kind of resource such as "flavor", "role",
|
:param name: The name of the kind of resource such as "flavor", "role",
|
||||||
etc.
|
etc.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(name, dict):
|
||||||
|
name = name['name']
|
||||||
if hasattr(self, "resource") and self.resource[0] == name:
|
if hasattr(self, "resource") and self.resource[0] == name:
|
||||||
LOG.debug("Return invalid resource (%s) value: %s" %
|
LOG.debug("Return invalid resource (%s) value: %s" %
|
||||||
(self.resource[0], self.resource[1]))
|
(self.resource[0], self.resource[1]))
|
||||||
|
Loading…
Reference in New Issue
Block a user