diff --git a/README.rst b/README.rst index 9b6c30392..a5f35e6ff 100644 --- a/README.rst +++ b/README.rst @@ -77,4 +77,13 @@ To run the examples find them in mistral-extra repository (https://github.com/st Tests ----- -Information about automated tests for Mistral can be found here: https://wiki.openstack.org/wiki/Mistral/Testing +There is an ability to run part of functional tests in non-openstack mode locally. To do this: + + # set *auth_enable=false* in the mistral.conf and restart Mistral + # execute: + + bash run_functional_tests.sh + +To run tests for only one version need to specify it: bash run_functional_tests.sh v1 + +More information about automated tests for Mistral can be found here: https://wiki.openstack.org/wiki/Mistral/Testing diff --git a/mistral/tests/functional/base.py b/mistral/tests/functional/base.py index 4b06e640e..97056754f 100644 --- a/mistral/tests/functional/base.py +++ b/mistral/tests/functional/base.py @@ -14,8 +14,11 @@ # under the License. import json +import mock +import os import time +from tempest import auth from tempest import clients from tempest.common import rest_client from tempest import config @@ -266,6 +269,24 @@ class MistralClientV2(MistralClientBase): return resp, json.loads(body) +class AuthProv(auth.KeystoneV2AuthProvider): + + def __init__(self): + self.alt_part = None + + def auth_request(self, method, url, *args, **kwargs): + req_url, headers, body = super(AuthProv, self).auth_request( + method, url, *args, **kwargs) + return 'http://localhost:8989/{0}/{1}'.format( + os.environ['VERSION'], url), headers, body + + def get_auth(self): + return 'mock_str', 'mock_str' + + def base_url(self, *args, **kwargs): + return '' + + class TestCase(tempest.test.BaseTestCase): @classmethod @@ -275,7 +296,12 @@ class TestCase(tempest.test.BaseTestCase): """ super(TestCase, cls).setUpClass() - cls.mgr = clients.Manager() + if 'WITHOUT_AUTH' in os.environ: + cls.mgr = mock.MagicMock() + cls.mgr.auth_provider = AuthProv() + else: + cls.mgr = clients.Manager() + if cls._version == 1: cls.client = MistralClientV1(cls.mgr.auth_provider) if cls._version == 2: diff --git a/requirements.txt b/requirements.txt index afcc4b842..79829ee4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,3 +26,4 @@ SQLAlchemy>=0.7.8,!=0.9.5,<=0.9.99 stevedore>=0.14 yaql==0.2.1 # This is not in global requirements jsonschema>=2.0.0,<3.0.0 +mock>=1.0 diff --git a/run_functional_tests.sh b/run_functional_tests.sh new file mode 100755 index 000000000..5c5886a3d --- /dev/null +++ b/run_functional_tests.sh @@ -0,0 +1,47 @@ +#! /usr/bin/env bash + +ARG=$1 + +function pre_hook() { + export WITHOUT_AUTH="True" + IS_TEMPEST=$(pip freeze | grep tempest) + if [ -z "$IS_TEMPEST" ] + then echo "$(tput setaf 4)No such module 'tempest' in the system. Before running this script please install 'tempest' module using : pip install git+http://github.com/openstack/tempest.git$(tput sgr 0)" + exit 1 + fi +} + +function run_tests_by_version() { + echo "$(tput setaf 4)Running integration API and workflow execution tests for v$1$(tput sgr 0)" + export VERSION="v$1" + nosetests -v mistral/tests/functional/api/v$1/ + unset VERSION +} + +function run_tests() { + if [ -z "$ARG" ] + then + run_tests_by_version 1 + run_tests_by_version 2 + elif [ "$ARG" == "v1" ] + then + run_tests_by_version 1 + elif [ "$ARG" == "v2" ] + then + run_tests_by_version 2 + fi +} + +function post_hook () { + unset LOCAL_RUN +} + +#----------main-part---------- + +echo "$(tput setaf 4)Preparation for tests running...$(tput sgr 0)" +pre_hook +echo "$(tput setaf 4)Running tests...$(tput sgr 0)" +run_tests + +post_hook + diff --git a/test-requirements.txt b/test-requirements.txt index d4519ae56..4db8eab5a 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -10,7 +10,6 @@ sphinxcontrib-pecanwsme>=0.8 sphinxcontrib-httpdomain docutils==0.9.1 fixtures>=0.3.14 -mock>=1.0 nose testrepository>=0.0.18 testtools>=0.9.34