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
This commit is contained in:
		
							
								
								
									
										0
									
								
								functionaltests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								functionaltests/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										56
									
								
								functionaltests/base.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								functionaltests/base.py
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
							
								
								
									
										12
									
								
								functionaltests/hello.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								functionaltests/hello.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
Namespaces:
 | 
			
		||||
  Greetings:
 | 
			
		||||
    actions:
 | 
			
		||||
      hello:
 | 
			
		||||
        class: std.echo
 | 
			
		||||
        base-parameters:
 | 
			
		||||
           output: Hello!
 | 
			
		||||
Workflow:
 | 
			
		||||
  tasks:
 | 
			
		||||
    hello:
 | 
			
		||||
      action: Greetings.hello
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										31
									
								
								functionaltests/run_tests.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								functionaltests/run_tests.sh
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
							
								
								
									
										36
									
								
								functionaltests/tests.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								functionaltests/tests.py
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
							
								
								
									
										3
									
								
								tox.ini
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								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}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user