From aebabe8b6e3b59a19f02fe3251a2053eb7947698 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Sun, 16 Apr 2017 00:46:02 +0800 Subject: [PATCH] [API] Abandon usage of classmethods & staticmethods in API Based on raas, api can not vist DB directily, so we need port all classmethods and static methods to objects' methods. Change-Id: I087e9abb1d2b2dbe46f2c4f0bace6273e9234e23 --- tests/unit/doc/test_task_samples.py | 17 ++++++++++------- tests/unit/rally_jobs/test_jobs.py | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/unit/doc/test_task_samples.py b/tests/unit/doc/test_task_samples.py index 83488b31..08339a5a 100644 --- a/tests/unit/doc/test_task_samples.py +++ b/tests/unit/doc/test_task_samples.py @@ -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)) diff --git a/tests/unit/rally_jobs/test_jobs.py b/tests/unit/rally_jobs/test_jobs.py index c176db58..e8b96e8f 100644 --- a/tests/unit/rally_jobs/test_jobs.py +++ b/tests/unit/rally_jobs/test_jobs.py @@ -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(),