From cacf8658b5080f5d0b7939b69d16d8a62de83f63 Mon Sep 17 00:00:00 2001 From: Anastasia Kuznetsova Date: Mon, 7 Jul 2014 18:34:44 +0400 Subject: [PATCH] Add integration tests (actions with workbooks) This commit is first in the series of commits implementing appropriate blueprint (please, look at link below). In this commit I added a bunch of integration tests which check work with workbooks(creation, updating, addition of definition and so on) and use only python-mistralclient methods. Targets blueprint: mistral-mistralclient-integration-tests Change-Id: Ieb95929102cc7a27ceb6caf5d63f7417d07d3974 --- functionaltests/__init__.py | 0 functionaltests/base.py | 56 ++++++++++++++++++++++++++++++++++++ functionaltests/hello.yaml | 12 ++++++++ functionaltests/run_tests.sh | 31 ++++++++++++++++++++ functionaltests/tests.py | 36 +++++++++++++++++++++++ tox.ini | 3 +- 6 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 functionaltests/__init__.py create mode 100644 functionaltests/base.py create mode 100644 functionaltests/hello.yaml create mode 100644 functionaltests/run_tests.sh create mode 100644 functionaltests/tests.py diff --git a/functionaltests/__init__.py b/functionaltests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/functionaltests/base.py b/functionaltests/base.py new file mode 100644 index 00000000..9bb7f218 --- /dev/null +++ b/functionaltests/base.py @@ -0,0 +1,56 @@ +import os +import testtools + +from tempest import clients +from tempest.common import rest_client + +from mistralclient.api import client as mclient + + +class ClientAuth(rest_client.RestClient): + def __init__(self, auth_provider): + super(ClientAuth, self).__init__(auth_provider) + + self.mistral_client = mclient.Client( + auth_token=self.auth_provider.get_token()) + + +class MistralBase(testtools.TestCase): + + @classmethod + def setUpClass(cls): + super(MistralBase, cls).setUpClass() + + mgr = clients.Manager() + cls.mistral_client = ClientAuth(mgr.auth_provider).mistral_client + + __location = os.path.realpath(os.path.join(os.getcwd(), + os.path.dirname(__file__))) + + cls.definition = open(os.path.join( + __location, 'hello.yaml'), 'rb').read() + + cls.wb = cls.mistral_client_workbooks.create( + "wb", "Description", ["tags"]) + + @classmethod + def tearDownClass(cls): + super(MistralBase, cls).tearDownClass() + + for wb in cls.mistral_client.workbooks.list(): + cls.mistral_client.workbooks.delete(wb.name) + + def assert_item_in_list(self, items, **props): + def _matches(item, **props): + for prop_name, prop_val in props.iteritems(): + v = item[prop_name] if isinstance(item, dict) \ + else getattr(item, prop_name) + + if v != prop_val: + return False + + return True + + filtered_items = filter(lambda item: _matches(item, **props), items) + + return len(filtered_items) != 0 diff --git a/functionaltests/hello.yaml b/functionaltests/hello.yaml new file mode 100644 index 00000000..f3f27660 --- /dev/null +++ b/functionaltests/hello.yaml @@ -0,0 +1,12 @@ +Namespaces: + Greetings: + actions: + hello: + class: std.echo + base-parameters: + output: Hello! +Workflow: + tasks: + hello: + action: Greetings.hello + diff --git a/functionaltests/run_tests.sh b/functionaltests/run_tests.sh new file mode 100644 index 00000000..fd018ac3 --- /dev/null +++ b/functionaltests/run_tests.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# 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. + +# How many seconds to wait for the API to be responding before giving up +API_RESPONDING_TIMEOUT=20 + +if ! timeout ${API_RESPONDING_TIMEOUT} sh -c "while ! curl -s http://127.0.0.1:8989/v1/ 2>/dev/null | grep -q 'Authentication required' ; do sleep 1; done"; then + echo "Mistral API failed to respond within ${API_RESPONDING_TIMEOUT} seconds" + exit 1 +fi + +echo "Successfully contacted Mistral API" + +# Where tempest code lives +TEMPEST_DIR=${TEMPEST_DIR:-/opt/stack/new/tempest} + +# Add tempest source tree to PYTHONPATH +export PYTHONPATH=$PYTHONPATH:$TEMPEST_DIR + +nosetests -sv tests.py diff --git a/functionaltests/tests.py b/functionaltests/tests.py new file mode 100644 index 00000000..95d5c759 --- /dev/null +++ b/functionaltests/tests.py @@ -0,0 +1,36 @@ +from base import MistralBase + + +class Workbooks(MistralBase): + + def test_get_workbook_list(self): + wbs = self.mistral_client.workbooks.list() + self.assertIsInstance(wbs, list) + + def test_create_workbook(self): + wbs = self.mistral_client.workbooks.list() + self.mistral_client.workbooks.create("new_wb") + wbs_with_new_wb = self.mistral_client.workbooks.list() + + self.assertEqual(len(wbs)+1, len(wbs_with_new_wb)) + self.assertTrue(self.assert_item_in_list( + wbs_with_new_wb, name="new_wb")) + + def test_get_workbook(self): + received_wb = self.mistral_client.workbooks.get("wb") + self.assertEqual(self.wb.name, received_wb.name) + + def test_update_workbook(self): + updated_wb = self.mistral_client.workbooks.update( + "wb", "New Description", ["tags"]) + + self.assertEqual(self.wb.name, updated_wb.name) + self.assertEqual("New Description", updated_wb.description) + self.assertEqual(["tags"], updated_wb.tags) + + def test_upload_get_definition(self): + self.mistral_client.workbooks.upload_definition("wb", self.definition) + received_definition = \ + self.mistral_client.workbooks.get_definition("wb") + + self.assertEqual(self.definition, received_definition) diff --git a/tox.ini b/tox.ini index 1a8f5fed..a8657cc4 100644 --- a/tox.ini +++ b/tox.ini @@ -15,10 +15,11 @@ setenv = NOSE_OPENSTACK_SHOW_ELAPSED=1 NOSE_OPENSTACK_STDOUT=1 NOSE_XUNIT=1 + DISCOVER_DIRECTORY=mistralclient/tests deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt -commands = nosetests +commands = nosetests mistralclient/tests [testenv:pep8] commands = flake8 {posargs}