Merge "[API] Abandon usage of classmethods & staticmethods in API"

This commit is contained in:
Jenkins 2017-04-25 10:46:02 +00:00 committed by Gerrit Code Review
commit fca3f4d0d9
2 changed files with 12 additions and 8 deletions

View File

@ -39,6 +39,8 @@ class TaskSampleTestCase(test.TestCase):
super(TaskSampleTestCase, self).setUp()
if os.environ.get("TOX_ENV_NAME") == "cover":
self.skipTest("There is no need to check samples in coverage job.")
with mock.patch("rally.api.API.check_db_revision"):
self.rapi = api.API()
def test_schema_is_valid(self):
scenarios = set()
@ -54,8 +56,8 @@ class TaskSampleTestCase(test.TestCase):
with open(full_path) as task_file:
try:
task_config = yaml.safe_load(api._Task.render_template
(task_file.read()))
task_config = yaml.safe_load(
self.rapi.task.render_template(task_file.read()))
eng = engine.TaskEngine(task_config,
mock.MagicMock(), mock.Mock())
eng.validate(only_syntax=True)
@ -81,7 +83,8 @@ class TaskSampleTestCase(test.TestCase):
full_path = os.path.join(dirname, filename)
with open(full_path) as task_file:
try:
json.loads(api._Task.render_template(task_file.read()))
json.loads(self.rapi.task.render_template(
task_file.read()))
except Exception:
print(traceback.format_exc())
self.fail("Invalid JSON file: %s" % full_path)
@ -121,11 +124,11 @@ class TaskSampleTestCase(test.TestCase):
if os.path.exists(yaml_path) and os.path.exists(json_path):
with open(json_path) as json_file:
json_config = yaml.safe_load(api._Task.render_template
(json_file.read()))
json_config = yaml.safe_load(
self.rapi.task.render_template(json_file.read()))
with open(yaml_path) as yaml_file:
yaml_config = yaml.safe_load(api._Task.render_template
(yaml_file.read()))
yaml_config = yaml.safe_load(
self.rapi.task.render_template(yaml_file.read()))
self.assertEqual(json_config, yaml_config,
"Sample task configs are not equal:"
"\n%s\n%s" % (yaml_path, json_path))

View File

@ -56,7 +56,8 @@ class RallyJobsTestCase(test.TestCase):
"args file %s must be dict in yaml or json "
"presenatation" % args_file)
task = api._Task.render_template(task_file.read(), **args)
task_inst = api._Task(api.API(skip_db_check=True))
task = task_inst.render_template(task_file.read(), **args)
task = yaml.safe_load(task)
eng = engine.TaskEngine(task, mock.MagicMock(),