Allow dict's as schema definitions
All negative testing schema's will be moved to dict format. Therefore the framework must support files and dict's. After all test are ported to dict's file support will be deprecated. Change-Id: Idb094f2817e7ed007a0ea47cf8f8602b5aeb6268 Partially-implements: bp api-schema-unification
This commit is contained in:
parent
fc20977052
commit
4f44d72d9c
@ -399,16 +399,21 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
cls.admin_client = os_admin.negative_client
|
cls.admin_client = os_admin.negative_client
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_schema(file):
|
def load_schema(file_or_dict):
|
||||||
"""
|
"""
|
||||||
Loads a schema from a file on a specified location.
|
Loads a schema from a file_or_dict on a specified location.
|
||||||
|
|
||||||
:param file: the file name
|
:param file_or_dict: just a dict or filename
|
||||||
"""
|
"""
|
||||||
|
# NOTE(mkoderer): we will get rid of this function when all test are
|
||||||
|
# ported to dicts
|
||||||
|
if isinstance(file_or_dict, dict):
|
||||||
|
return file_or_dict
|
||||||
|
|
||||||
# NOTE(mkoderer): must be extended for xml support
|
# NOTE(mkoderer): must be extended for xml support
|
||||||
fn = os.path.join(
|
fn = os.path.join(
|
||||||
os.path.abspath(os.path.dirname(os.path.dirname(__file__))),
|
os.path.abspath(os.path.dirname(os.path.dirname(__file__))),
|
||||||
"etc", "schemas", file)
|
"etc", "schemas", file_or_dict)
|
||||||
LOG.debug("Open schema file: %s" % (fn))
|
LOG.debug("Open schema file: %s" % (fn))
|
||||||
return json.load(open(fn))
|
return json.load(open(fn))
|
||||||
|
|
||||||
@ -425,17 +430,21 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
standard_tests, module, loader = args
|
standard_tests, module, loader = args
|
||||||
for test in testtools.iterate_tests(standard_tests):
|
for test in testtools.iterate_tests(standard_tests):
|
||||||
schema_file = getattr(test, '_schema_file', None)
|
schema_file = getattr(test, '_schema_file', None)
|
||||||
|
schema = getattr(test, '_schema', None)
|
||||||
if schema_file is not None:
|
if schema_file is not None:
|
||||||
setattr(test, 'scenarios',
|
setattr(test, 'scenarios',
|
||||||
NegativeAutoTest.generate_scenario(schema_file))
|
NegativeAutoTest.generate_scenario(schema_file))
|
||||||
|
elif schema is not None:
|
||||||
|
setattr(test, 'scenarios',
|
||||||
|
NegativeAutoTest.generate_scenario(schema))
|
||||||
return testscenarios.load_tests_apply_scenarios(*args)
|
return testscenarios.load_tests_apply_scenarios(*args)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_scenario(description_file):
|
def generate_scenario(description):
|
||||||
"""
|
"""
|
||||||
Generates the test scenario list for a given description.
|
Generates the test scenario list for a given description.
|
||||||
|
|
||||||
:param description: A dictionary with the following entries:
|
:param description: A file or dictionary with the following entries:
|
||||||
name (required) name for the api
|
name (required) name for the api
|
||||||
http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
|
http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
|
||||||
url (required) the url to be appended to the catalog url with '%s'
|
url (required) the url to be appended to the catalog url with '%s'
|
||||||
@ -451,7 +460,7 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
the data is used to generate query strings appended to the url,
|
the data is used to generate query strings appended to the url,
|
||||||
otherwise for the body of the http call.
|
otherwise for the body of the http call.
|
||||||
"""
|
"""
|
||||||
description = NegativeAutoTest.load_schema(description_file)
|
description = NegativeAutoTest.load_schema(description)
|
||||||
LOG.debug(description)
|
LOG.debug(description)
|
||||||
generator = importutils.import_class(
|
generator = importutils.import_class(
|
||||||
CONF.negative.test_generator)()
|
CONF.negative.test_generator)()
|
||||||
@ -481,13 +490,14 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
LOG.debug(scenario_list)
|
LOG.debug(scenario_list)
|
||||||
return scenario_list
|
return scenario_list
|
||||||
|
|
||||||
def execute(self, description_file):
|
def execute(self, description):
|
||||||
"""
|
"""
|
||||||
Execute a http call on an api that are expected to
|
Execute a http call on an api that are expected to
|
||||||
result in client errors. First it uses invalid resources that are part
|
result in client errors. First it uses invalid resources that are part
|
||||||
of the url, and then invalid data for queries and http request bodies.
|
of the url, and then invalid data for queries and http request bodies.
|
||||||
|
|
||||||
:param description: A dictionary with the following entries:
|
:param description: A json file or dictionary with the following
|
||||||
|
entries:
|
||||||
name (required) name for the api
|
name (required) name for the api
|
||||||
http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
|
http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
|
||||||
url (required) the url to be appended to the catalog url with '%s'
|
url (required) the url to be appended to the catalog url with '%s'
|
||||||
@ -504,7 +514,7 @@ class NegativeAutoTest(BaseTestCase):
|
|||||||
otherwise for the body of the http call.
|
otherwise for the body of the http call.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
description = NegativeAutoTest.load_schema(description_file)
|
description = NegativeAutoTest.load_schema(description)
|
||||||
LOG.info("Executing %s" % description["name"])
|
LOG.info("Executing %s" % description["name"])
|
||||||
LOG.debug(description)
|
LOG.debug(description)
|
||||||
method = description["http-method"]
|
method = description["http-method"]
|
||||||
@ -594,7 +604,10 @@ def SimpleNegativeAutoTest(klass):
|
|||||||
"""
|
"""
|
||||||
@attr(type=['negative', 'gate'])
|
@attr(type=['negative', 'gate'])
|
||||||
def generic_test(self):
|
def generic_test(self):
|
||||||
|
if hasattr(self, '_schema_file'):
|
||||||
self.execute(self._schema_file)
|
self.execute(self._schema_file)
|
||||||
|
if hasattr(self, '_schema'):
|
||||||
|
self.execute(self._schema)
|
||||||
|
|
||||||
cn = klass.__name__
|
cn = klass.__name__
|
||||||
cn = cn.replace('JSON', '')
|
cn = cn.replace('JSON', '')
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from tempest import config
|
from tempest import config
|
||||||
@ -70,3 +72,13 @@ class TestNegativeAutoTest(base.TestCase):
|
|||||||
self._check_prop_entries(scenarios, "prop_minRam")
|
self._check_prop_entries(scenarios, "prop_minRam")
|
||||||
self._check_prop_entries(scenarios, "prop_minDisk")
|
self._check_prop_entries(scenarios, "prop_minDisk")
|
||||||
self._check_resource_entries(scenarios, "inv_res")
|
self._check_resource_entries(scenarios, "inv_res")
|
||||||
|
|
||||||
|
def test_load_schema(self):
|
||||||
|
json_schema = json.dumps(self.fake_input_desc)
|
||||||
|
with mock.patch('tempest.test.open',
|
||||||
|
mock.mock_open(read_data=json_schema),
|
||||||
|
create=True):
|
||||||
|
return_file = test.NegativeAutoTest.load_schema('filename')
|
||||||
|
self.assertEqual(return_file, self.fake_input_desc)
|
||||||
|
return_dict = test.NegativeAutoTest.load_schema(self.fake_input_desc)
|
||||||
|
self.assertEqual(return_file, return_dict)
|
||||||
|
Loading…
Reference in New Issue
Block a user