diff --git a/functional-test-requirements.txt b/functional-test-requirements.txt deleted file mode 100644 index 5fb09db30..000000000 --- a/functional-test-requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -requests -ddt \ No newline at end of file diff --git a/marconi/tests/functional/base.py b/marconi/tests/functional/base.py index 488370507..9c7c08171 100644 --- a/marconi/tests/functional/base.py +++ b/marconi/tests/functional/base.py @@ -14,6 +14,8 @@ # limitations under the License. from marconi import tests as testing +from marconi.tests.functional import config +from marconi.tests.functional import helpers # NOTE(flaper87): This is necessary to register, # wsgi configs and won't be permanent. It'll be # refactored as part of the work for this blueprint @@ -22,6 +24,25 @@ from marconi.transport import wsgi # noqa class FunctionalTestBase(testing.TestBase): + def setUp(self): + super(FunctionalTestBase, self).setUp() + + # NOTE(flaper87): Config can't be a class + # attribute because it may be necessary to + # modify it at runtime which will affect + # other instances running instances. + self.cfg = config.load_config() + + if not self.cfg.run_tests: + self.skipTest("Functional tests disabled") + + self.mconf = self.load_conf(self.cfg.marconi.config).conf + self.limits = self.mconf['limits:transport'] + + self.header = helpers.create_marconi_headers(self.cfg) + self.headers_response_with_body = set(['location', + 'content-type']) + def assertIsSubset(self, required_values, actual_values): """Checks if a list is subset of another. diff --git a/marconi/tests/functional/config.py b/marconi/tests/functional/config.py index 1aef85163..b77e8879e 100644 --- a/marconi/tests/functional/config.py +++ b/marconi/tests/functional/config.py @@ -17,6 +17,9 @@ import os from oslo.config import cfg +_DEFAULT = [ + cfg.BoolOpt("run_tests", default=False), +] _AUTH_OPTIONS = [ cfg.BoolOpt("auth_on", default=False), @@ -42,6 +45,7 @@ _HEADERS_OPTIONS = [ def load_config(): conf = cfg.ConfigOpts() + conf.register_opts(_DEFAULT) conf.register_opts(_AUTH_OPTIONS, group="auth") conf.register_opts(_MARCONI_OPTIONS, group="marconi") conf.register_opts(_HEADERS_OPTIONS, group="headers") diff --git a/marconi/tests/functional/helpers.py b/marconi/tests/functional/helpers.py index 2a8101102..c4ca68794 100644 --- a/marconi/tests/functional/helpers.py +++ b/marconi/tests/functional/helpers.py @@ -12,8 +12,7 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -from marconi.tests.functional.util import config -from marconi.tests.functional.util import http +from marconi.tests.functional import http import json import random @@ -21,9 +20,6 @@ import string import uuid -CFG = config.Config() - - def get_keystone_token(conf): """Gets Keystone Auth token.""" req_json = { diff --git a/setup.cfg b/setup.cfg index adaa7b451..7b6f01924 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,6 @@ marconi.common.cache.backends = [nosetests] where=tests verbosity=2 -exclude=functional/* with-doctest = true diff --git a/test-requirements.txt b/test-requirements.txt index 5a897d630..132fbc384 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -10,6 +10,9 @@ python-subunit testrepository testtools +# Functional Tests +requests + # Test runner nose nose-exclude diff --git a/tests/etc/functional-tests.conf b/tests/etc/functional-tests.conf index 85a199042..3c80b8cd3 100644 --- a/tests/etc/functional-tests.conf +++ b/tests/etc/functional-tests.conf @@ -1,3 +1,6 @@ +[DEFAULT] +# run_tests = False + [auth] # auth_on = False # url = https://127.0.0.1:5000/v2.0/tokens diff --git a/tests/functional/README.rst b/tests/functional/README.rst index 8680e59b7..e73fa0e24 100644 --- a/tests/functional/README.rst +++ b/tests/functional/README.rst @@ -6,15 +6,37 @@ words, the API calls attempt to simulate an actual user. Unlike unit tests, the functional tests do not use mockendpoints. -Running the Functional Tests ------------------------- +Running functional tests (With Tox) +----------------------------------- + +#. Setup a Marconi server. Refer to the Marconi `README`_ on + how to run Marconi locally, or simply use an existing server. + +#. Change `$MARCONI_TESTS_CONFIGS_DIR/functional-tests.conf` and + set `run_tests` to True. + +#. Run tests. :: + + $ tox + +#. Filter tests. :: + + $ tox -- --tests tests.functional.test_messages + +#. Run tests for specific environments. :: + + $ tox -epy27,pep8 + +Running the Functional Tests (Without Tox) +------------------------------------------ #. Setup a Marconi server. Refer to the Marconi `README`_ on how to run Marconi locally, or simply use an existing server. #. Install functional tests dependencies. :: - pip install -r functional-test-requirements.txt + pip install -r requirements.txt + pip install -r test-requirements.txt #. cd to the marconi/tests/functional directory diff --git a/tests/functional/test_claims.py b/tests/functional/test_claims.py index b4f5cd6cb..d5e7d94f7 100644 --- a/tests/functional/test_claims.py +++ b/tests/functional/test_claims.py @@ -18,7 +18,6 @@ import json import uuid from marconi.tests.functional import base -from marconi.tests.functional import config from marconi.tests.functional import helpers from marconi.tests.functional import http @@ -27,16 +26,6 @@ from marconi.tests.functional import http class TestClaims(base.FunctionalTestBase): """Tests for Claims.""" - @classmethod - def setUpClass(cls): - cls.cfg = config.load_config() - cls.mconf = cls.load_conf(cls.cfg.marconi.config).conf - cls.limits = cls.mconf['limits:transport'] - - cls.header = helpers.create_marconi_headers(cls.cfg) - cls.headers_response_with_body = set(['location', - 'content-type']) - def setUp(self): super(TestClaims, self).setUp() diff --git a/tests/functional/test_messages.py b/tests/functional/test_messages.py index c13163697..c309761be 100644 --- a/tests/functional/test_messages.py +++ b/tests/functional/test_messages.py @@ -16,26 +16,14 @@ import ddt import uuid from marconi.tests.functional import base # noqa -from marconi.tests.functional import config from marconi.tests.functional import helpers from marconi.tests.functional import http @ddt.ddt class TestMessages(base.FunctionalTestBase): - """Tests for Messages.""" - @classmethod - def setUpClass(cls): - cls.cfg = config.load_config() - cls.mconf = cls.load_conf(cls.cfg.marconi.config).conf - cls.limits = cls.mconf['limits:transport'] - - cls.header = helpers.create_marconi_headers(cls.cfg) - cls.headers_response_with_body = set(['location', - 'content-type']) - def setUp(self): super(TestMessages, self).setUp() diff --git a/tests/functional/test_queue.py b/tests/functional/test_queue.py index f3e36f6e6..01c51099d 100644 --- a/tests/functional/test_queue.py +++ b/tests/functional/test_queue.py @@ -19,8 +19,6 @@ import json import uuid from marconi.tests.functional import base # noqa -from marconi.tests.functional import config -from marconi.tests.functional import helpers from marconi.tests.functional import http @@ -29,19 +27,12 @@ class TestInsertQueue(base.FunctionalTestBase): """Tests for Insert queue.""" - @classmethod - def setUpClass(cls): - cls.cfg = config.load_config() - cls.mconf = cls.load_conf(cls.cfg.marconi.config).conf - cls.limits = cls.mconf['limits:transport'] + def setUp(self): + super(TestInsertQueue, self).setUp() + self.base_url = '%s/%s' % (self.cfg.marconi.url, + self.cfg.marconi.version) - cls.base_url = '%s/%s' % (cls.cfg.marconi.url, - cls.cfg.marconi.version) - - cls.header = helpers.create_marconi_headers(cls.cfg) - cls.headers_response_empty = set(['location']) - cls.headers_response_with_body = set(['content-location', - 'content-type']) + self.headers_response_empty = set(['location']) @ddt.data('qtestqueue', 'TESTqueue', 'hyphen-name', '_undersore', 'i' * 64) @@ -143,21 +134,12 @@ class TestQueueMetaData(base.FunctionalTestBase): """Tests for queue metadata.""" - @classmethod - def setUpClass(cls): - cls.cfg = config.load_config() - cls.mconf = cls.load_conf(cls.cfg.marconi.config).conf - cls.limits = cls.mconf['limits:transport'] - - cls.base_url = '%s/%s' % (cls.cfg.marconi.url, - cls.cfg.marconi.version) - cls.header = helpers.create_marconi_headers(cls.cfg) - cls.headers_response_with_body = set(['location', - 'content-type']) - def setUp(self): super(TestQueueMetaData, self).setUp() + self.base_url = '%s/%s' % (self.cfg.marconi.url, + self.cfg.marconi.version) + self.queue_url = self.base_url + '/queues/{}'.format(uuid.uuid1()) http.put(self.queue_url, self.header) @@ -200,32 +182,11 @@ class TestQueueMetaData(base.FunctionalTestBase): @ddt.ddt class TestQueueMisc(base.FunctionalTestBase): - @classmethod - def setUpClass(cls): - cls.cfg = config.load_config() - cls.mconf = cls.load_conf(cls.cfg.marconi.config).conf - cls.limits = cls.mconf['limits:transport'] - - cls.header = helpers.create_marconi_headers(cls.cfg) - cls.headers_response_empty = set(['location']) - cls.headers_response_with_body = set(['content-location', - 'content-type']) - - cls.base_url = '%s/%s' % (cls.cfg.marconi.url, - cls.cfg.marconi.version) - def setUp(self): super(TestQueueMisc, self).setUp() - self.queue = uuid.uuid1() - self.queue_url = ("%(url)s/%(version)s/queues/%(queue)s" % - {'url': self.cfg.marconi.url, - 'version': self.cfg.marconi.version, - 'queue': self.queue}) - - url = self.queue_url + '/metadata' - metadata = {"queue_metadata": "TEST METADATA"} - http.put(url, self.header, json.dumps(metadata)) + self.base_url = '%s/%s' % (self.cfg.marconi.url, + self.cfg.marconi.version) def test_list_queues(self): """List Queues."""