From ae4937741830611566b174606c227f4f18f18caf Mon Sep 17 00:00:00 2001 From: Anton Studenov Date: Thu, 19 Jan 2017 13:23:01 +0300 Subject: [PATCH] [Test] Add test for simple app based on rally api * Add functional test for simple app based on rally api Change-Id: I9044805507b83639c7f75fe844997359486269c1 --- tests/ci/rally_app.py | 30 ++++++++++++++++++++++++++++++ tests/functional/test_lib_api.py | 30 ++++++++++++++++++++++++++++++ tests/functional/utils.py | 2 ++ 3 files changed, 62 insertions(+) create mode 100644 tests/ci/rally_app.py create mode 100644 tests/functional/test_lib_api.py diff --git a/tests/ci/rally_app.py b/tests/ci/rally_app.py new file mode 100644 index 0000000000..4a412b7117 --- /dev/null +++ b/tests/ci/rally_app.py @@ -0,0 +1,30 @@ +# Copyright 2016: Mirantis Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Simple app based on rally api for testing porpuses""" + +import sys + +from rally import api as rapi + + +def main(): + api = rapi.API(config_args=sys.argv[1:]) + print(len(api.task.list())) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/functional/test_lib_api.py b/tests/functional/test_lib_api.py new file mode 100644 index 0000000000..eae8f15fe7 --- /dev/null +++ b/tests/functional/test_lib_api.py @@ -0,0 +1,30 @@ +# Copyright 2016: Mirantis Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +import subprocess +import unittest + +from tests.functional import utils + + +class LibAPITestCase(unittest.TestCase): + + def test_rally_lib(self): + rally = utils.Rally(force_new_db=True) + cdir = os.path.dirname(os.path.realpath(__file__)) + app = os.path.join(cdir, "../ci/rally_app.py") + subprocess.check_output( + ["python", app, "--config-file", rally.config_filename]) diff --git a/tests/functional/utils.py b/tests/functional/utils.py index 9ac35bfe06..12f3cf253b 100644 --- a/tests/functional/utils.py +++ b/tests/functional/utils.py @@ -86,6 +86,7 @@ class Rally(object): self.tmp_dir = tempfile.mkdtemp() self.env = copy.deepcopy(os.environ) self.env["HOME"] = self.tmp_dir + self.config_filename = None if force_new_db or ("RCI_KEEP_DB" not in os.environ): config_filename = os.path.join(self.tmp_dir, "conf") @@ -98,6 +99,7 @@ class Rally(object): self.args = ["rally", "--config-file", config_filename] subprocess.call(["rally-manage", "--config-file", config_filename, "db", "recreate"], env=self.env) + self.config_filename = config_filename else: self.args = ["rally"] subprocess.call(["rally-manage", "db", "recreate"], env=self.env)