def generate_scenario(description_file): """ Generates the test scenario list for a given description. :param description: A dictionary with the following entries: name (required) name for the api http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE url (required) the url to be appended to the catalog url with '%s' for each resource mentioned resources: (optional) A list of resource names such as "server", "flavor", etc. with an element for each '%s' in the url. This method will call self.get_resource for each element when constructing the positive test case template so negative subclasses are expected to return valid resource ids when appropriate. json-schema (optional) A valid json schema that will be used to create invalid data for the api calls. For "GET" and "HEAD", the data is used to generate query strings appended to the url, otherwise for the body of the http call. """ description = NegativeAutoTest.load_schema(description_file) LOG.debug(description) generate_json.validate_negative_test_schema(description) schema = description.get("json-schema", None) resources = description.get("resources", []) scenario_list = [] expected_result = None for resource in resources: if isinstance(resource, dict): expected_result = resource['expected_result'] resource = resource['name'] LOG.debug("Add resource to test %s" % resource) scn_name = "inv_res_%s" % (resource) scenario_list.append((scn_name, { "resource": (resource, str(uuid.uuid4())), "expected_result": expected_result })) if schema is not None: for invalid in generate_json.generate_invalid(schema): scenario_list.append((invalid[0], { "schema": invalid[1], "expected_result": invalid[2] })) LOG.debug(scenario_list) return scenario_list
def generate_scenario(description_file): """ Generates the test scenario list for a given description. :param description: A dictionary with the following entries: name (required) name for the api http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE url (required) the url to be appended to the catalog url with '%s' for each resource mentioned resources: (optional) A list of resource names such as "server", "flavor", etc. with an element for each '%s' in the url. This method will call self.get_resource for each element when constructing the positive test case template so negative subclasses are expected to return valid resource ids when appropriate. json-schema (optional) A valid json schema that will be used to create invalid data for the api calls. For "GET" and "HEAD", the data is used to generate query strings appended to the url, otherwise for the body of the http call. """ description = NegativeAutoTest.load_schema(description_file) LOG.debug(description) generate_json.validate_negative_test_schema(description) schema = description.get("json-schema", None) resources = description.get("resources", []) scenario_list = [] expected_result = None for resource in resources: if isinstance(resource, dict): expected_result = resource['expected_result'] resource = resource['name'] LOG.debug("Add resource to test %s" % resource) scn_name = "inv_res_%s" % (resource) scenario_list.append((scn_name, {"resource": (resource, str(uuid.uuid4())), "expected_result": expected_result })) if schema is not None: for invalid in generate_json.generate_invalid(schema): scenario_list.append((invalid[0], {"schema": invalid[1], "expected_result": invalid[2]})) LOG.debug(scenario_list) return scenario_list
def test_generate_invalid_obj(self): result = gen.generate_invalid(self.fake_input_obj) self._validate_result(result)
def test_generate_invalid_integer(self): result = gen.generate_invalid(self.fake_input_int) self._validate_result(result)
def test_generate_invalid_string(self): result = gen.generate_invalid(self.fake_input_str) self._validate_result(result)