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
|
||||
|
||||
@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
|
||||
fn = os.path.join(
|
||||
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))
|
||||
return json.load(open(fn))
|
||||
|
||||
@ -425,17 +430,21 @@ class NegativeAutoTest(BaseTestCase):
|
||||
standard_tests, module, loader = args
|
||||
for test in testtools.iterate_tests(standard_tests):
|
||||
schema_file = getattr(test, '_schema_file', None)
|
||||
schema = getattr(test, '_schema', None)
|
||||
if schema_file is not None:
|
||||
setattr(test, 'scenarios',
|
||||
NegativeAutoTest.generate_scenario(schema_file))
|
||||
elif schema is not None:
|
||||
setattr(test, 'scenarios',
|
||||
NegativeAutoTest.generate_scenario(schema))
|
||||
return testscenarios.load_tests_apply_scenarios(*args)
|
||||
|
||||
@staticmethod
|
||||
def generate_scenario(description_file):
|
||||
def generate_scenario(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
|
||||
http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
|
||||
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,
|
||||
otherwise for the body of the http call.
|
||||
"""
|
||||
description = NegativeAutoTest.load_schema(description_file)
|
||||
description = NegativeAutoTest.load_schema(description)
|
||||
LOG.debug(description)
|
||||
generator = importutils.import_class(
|
||||
CONF.negative.test_generator)()
|
||||
@ -481,13 +490,14 @@ class NegativeAutoTest(BaseTestCase):
|
||||
LOG.debug(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
|
||||
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.
|
||||
|
||||
: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
|
||||
http-method (required) one of HEAD,GET,PUT,POST,PATCH,DELETE
|
||||
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.
|
||||
|
||||
"""
|
||||
description = NegativeAutoTest.load_schema(description_file)
|
||||
description = NegativeAutoTest.load_schema(description)
|
||||
LOG.info("Executing %s" % description["name"])
|
||||
LOG.debug(description)
|
||||
method = description["http-method"]
|
||||
@ -594,7 +604,10 @@ def SimpleNegativeAutoTest(klass):
|
||||
"""
|
||||
@attr(type=['negative', 'gate'])
|
||||
def generic_test(self):
|
||||
if hasattr(self, '_schema_file'):
|
||||
self.execute(self._schema_file)
|
||||
if hasattr(self, '_schema'):
|
||||
self.execute(self._schema)
|
||||
|
||||
cn = klass.__name__
|
||||
cn = cn.replace('JSON', '')
|
||||
|
@ -13,6 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import mock
|
||||
|
||||
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_minDisk")
|
||||
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