From 90c3cb5bface01224973f10e23dbde4bb014c0b4 Mon Sep 17 00:00:00 2001 From: Flaper Fesp Date: Fri, 30 Aug 2013 17:49:32 +0200 Subject: [PATCH] Use oslo.config for functional tests Instead of defining a Config class for functional tests, this patch integrates it with Marconi's base test suite and replaces the use of ConfigParser with olso.config. The patch doesn't change current behavior and gives the possibility to use external configuration files for both the functional test and Marconi. blueprint refactor-system-tests Change-Id: I60de6e199182881e945a24525c7c4f2d6937256f --- marconi/tests/base.py | 8 ++- marconi/tests/functional/base.py | 9 ++- marconi/tests/functional/config.py | 105 +++++++--------------------- marconi/tests/functional/helpers.py | 26 ++++--- tests/etc/functional-marconi.conf | 56 +++++++++++++++ tests/etc/functional-tests.conf | 32 ++++----- tests/functional/README.rst | 5 +- tests/functional/test_claims.py | 37 ++++++---- tests/functional/test_messages.py | 37 ++++++---- tests/functional/test_queue.py | 89 +++++++++++++++-------- 10 files changed, 226 insertions(+), 178 deletions(-) create mode 100644 tests/etc/functional-marconi.conf diff --git a/marconi/tests/base.py b/marconi/tests/base.py index e181a8159..20d073d33 100644 --- a/marconi/tests/base.py +++ b/marconi/tests/base.py @@ -40,7 +40,8 @@ class TestBase(testtools.TestCase): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) - def conf_path(self, filename): + @classmethod + def conf_path(cls, filename): """Returns the full path to the specified Marconi conf file. :param filename: Name of the conf file to find (e.g., @@ -48,7 +49,8 @@ class TestBase(testtools.TestCase): """ return os.path.join(os.environ["MARCONI_TESTS_CONFIGS_DIR"], filename) - def load_conf(self, filename): + @classmethod + def load_conf(cls, filename): """Loads `filename` configuration file. :param filename: Name of the conf file to find (e.g., @@ -56,7 +58,7 @@ class TestBase(testtools.TestCase): :returns: Project's config object. """ - CFG.load(filename=self.conf_path(filename)) + CFG.load(filename=cls.conf_path(filename)) return CFG def _my_dir(self): diff --git a/marconi/tests/functional/base.py b/marconi/tests/functional/base.py index 11636b990..488370507 100644 --- a/marconi/tests/functional/base.py +++ b/marconi/tests/functional/base.py @@ -12,10 +12,15 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -import testtools + +from marconi import tests as testing +# 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 +from marconi.transport import wsgi # noqa -class FunctionalTestBase(testtools.TestCase): +class FunctionalTestBase(testing.TestBase): 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 7634230cc..1aef85163 100644 --- a/marconi/tests/functional/config.py +++ b/marconi/tests/functional/config.py @@ -13,90 +13,39 @@ # See the License for the specific language governing permissions and # limitations under the License. -import ConfigParser import os -import uuid + +from oslo.config import cfg -class Config(object): - def __init__(self, config_path=None): - if config_path is None: - if os.path.exists('/etc/marconi/functional-tests.conf'): - config_path = '/etc/marconi/functional-tests.conf' - else: - config_path = os.path.expanduser('~/.marconi' - '/functional-tests.conf') - self.parser = ConfigParser.SafeConfigParser() - self.parser.read(config_path) +_AUTH_OPTIONS = [ + cfg.BoolOpt("auth_on", default=False), + cfg.StrOpt("url", default="https://127.0.0.1:5000/v2.0/tokens"), + cfg.StrOpt("username", default=None), + cfg.StrOpt("password", default=None), +] - @property - def auth_enabled(self): - return self.parser.getboolean('auth', 'auth_on') - @property - def username(self): - return self.parser.get('auth', 'username') +_MARCONI_OPTIONS = [ + cfg.StrOpt("url", default="http://127.0.0.1:8888"), + cfg.StrOpt("version", default="v1"), + cfg.StrOpt("config", default="functional-marconi.conf"), +] - @property - def password(self): - return self.parser.get('auth', 'password') - @property - def auth_url(self): - return self.parser.get('auth', 'url') +_HEADERS_OPTIONS = [ + cfg.StrOpt("host", default="example.com"), + cfg.StrOpt("user_agent", default="FunctionalTests"), + cfg.StrOpt("project_id", default="123456"), +] - @property - def base_server(self): - return self.parser.get('marconi_env', 'marconi_url') - @property - def marconi_version(self): - return self.parser.get('marconi_env', 'marconi_version') - - @property - def base_url(self): - return (self.base_server + '/' + self.marconi_version) - - @property - def uuid(self): - return str(uuid.uuid1()) - - @property - def user_agent(self): - return self.parser.get('header_values', 'useragent') - - @property - def host(self): - return self.parser.get('header_values', 'host') - - @property - def project_id(self): - return self.parser.get('header_values', 'project_id') - - @property - def queue_paging_uplimit(self): - return int(self.parser.get('marconi_config', 'queue_paging_uplimit')) - - @property - def message_paging_uplimit(self): - return int(self.parser.get('marconi_config', 'message_paging_uplimit')) - - @property - def message_ttl_max(self): - return int(self.parser.get('marconi_config', 'message_ttl_max')) - - @property - def claim_ttl_max(self): - return int(self.parser.get('marconi_config', 'claim_ttl_max')) - - @property - def claim_grace_max(self): - return int(self.parser.get('marconi_config', 'claim_grace_max')) - - @property - def metadata_size_uplimit(self): - return self.parser.get('marconi_config', 'metadata_size_uplimit') - - @property - def message_size_uplimit(self): - return self.parser.get('marconi_config', 'message_size_uplimit') +def load_config(): + conf = cfg.ConfigOpts() + conf.register_opts(_AUTH_OPTIONS, group="auth") + conf.register_opts(_MARCONI_OPTIONS, group="marconi") + conf.register_opts(_HEADERS_OPTIONS, group="headers") + conf_path = os.path.join(os.environ["MARCONI_TESTS_CONFIGS_DIR"], + "functional-tests.conf") + conf(args=[], default_config_files=[conf_path]) + return conf diff --git a/marconi/tests/functional/helpers.py b/marconi/tests/functional/helpers.py index 742cfc261..2a8101102 100644 --- a/marconi/tests/functional/helpers.py +++ b/marconi/tests/functional/helpers.py @@ -18,25 +18,27 @@ from marconi.tests.functional.util import http import json import random import string +import uuid CFG = config.Config() -def get_keystone_token(): +def get_keystone_token(conf): """Gets Keystone Auth token.""" req_json = { 'auth': { 'passwordCredentials': { - 'username': CFG.username, - 'password': CFG.password + 'username': conf.auth.username, + 'password': conf.auth.password }, }, } header = {"Content-Type": "application/json", "Accept": "application/json"} - url = CFG.auth_url + + url = conf.auth.url response = http.post(url=url, header=header, body=req_json) response_body = json.loads(response.text) @@ -46,18 +48,20 @@ def get_keystone_token(): return auth_token -def create_marconi_headers(): +def create_marconi_headers(conf): """Returns headers to be used for all Marconi requests.""" - auth_token = get_keystone_token() - headers = {"Host": CFG.host, - "User-Agent": CFG.user_agent, + headers = {"Host": conf.headers.host, + "User-Agent": conf.headers.user_agent, "Accept": "application/json", - "X-Project-ID": CFG.project_id, - "X-Auth-Token": auth_token, - "Client-ID": CFG.uuid + "X-Project-ID": conf.headers.project_id, + "Client-ID": str(uuid.uuid1()) } + if conf.auth.auth_on: + auth_token = get_keystone_token(conf) + headers["X-Auth-Token"] = auth_token + return headers diff --git a/tests/etc/functional-marconi.conf b/tests/etc/functional-marconi.conf new file mode 100644 index 000000000..d0eda4972 --- /dev/null +++ b/tests/etc/functional-marconi.conf @@ -0,0 +1,56 @@ +[DEFAULT] +# Show more verbose log output (sets INFO log level output) +;verbose = False + +# Show debugging output in logs (sets DEBUG log level output) +;debug = False + +# Log to this file! +log_file = /var/log/marconi/server.log + +;auth_strategy = + +# ================= Syslog Options ============================ + +# Send logs to syslog (/dev/log) instead of to file specified +# by `log_file` +;use_syslog = False + +# Facility to use. If unset defaults to LOG_USER. +;syslog_log_facility = LOG_LOCAL0 + + +[drivers] +# Transport driver module (e.g., wsgi, zmq) +transport = wsgi +# Storage driver module (e.g., mongodb, sqlite) +storage = sqlite + +[drivers:transport:wsgi] +bind = 127.0.0.1 +port = 8888 + +# Maximum Content-Length allowed for metadata updating and +# message posting. +;metadata_max_length = 65536 +;content_max_length = 262144 + +;[drivers:transport:zmq] +;port = 9999 + +[limits:transport] +# The maximum number of queue records per page when listing queues +;queue_paging_uplimit = 20 +# The maximum number of messages in a message posting, maximum +# number of messages per page when listing or claiming messages, +# and maximum number of messages involved in a bulk operation. +;message_paging_uplimit = 20 +# Expiration limits; the minimal values are all 60 (seconds) +;message_ttl_max = 1209600 +;claim_ttl_max = 43200 +;claim_grace_max = 43200 + +# Maximum compact-JSON (without whitespace) size in bytes allowed +# for each metadata body and each message body +;metadata_size_uplimit = 65536 +;message_size_uplimit = 262144 diff --git a/tests/etc/functional-tests.conf b/tests/etc/functional-tests.conf index 7b4d2ca5b..85a199042 100644 --- a/tests/etc/functional-tests.conf +++ b/tests/etc/functional-tests.conf @@ -1,23 +1,15 @@ [auth] -auth_on = false -url = https://identity.xxx.xxxx.com/v2.0/tokens -username = user -password = secret +# auth_on = False +# url = https://127.0.0.1:5000/v2.0/tokens +# username = None +# password = None -[marconi_env] -marconi_url = http://0.0.0.0:8888 -marconi_version = v1 +[marconi] +# url = http://0.0.0.0:8888 +# version = v1 +# config = functional-marconi.conf -[header_values] -host = marconi.test.com -useragent = systemtests -project_id = 123456 - -[marconi_config] -queue_paging_uplimit = 20 -message_paging_uplimit = 20 -message_ttl_max = 1209600 -claim_ttl_max = 43200 -claim_grace_max = 43200 -metadata_size_uplimit = 65536 -message_size_uplimit = 262144 \ No newline at end of file +[headers] +# host = example.com +# useragent = FunctionalTests +# project_id = 123456 diff --git a/tests/functional/README.rst b/tests/functional/README.rst index f73951399..8680e59b7 100644 --- a/tests/functional/README.rst +++ b/tests/functional/README.rst @@ -29,12 +29,11 @@ Running the Functional Tests #. If leaving keystone auth enabled, update system-tests.conf with a valid set of credentials. -#. Now, to run the sytem tests, simply use the nosetests commands, - from the marconi/tests/functional directory. e.g.: +#. Now, to run the sytem tests, simply use the nosetests commands, e.g.: Run all test suites: :: - nosetests -v + nosetests --tests tests.functional -v Adding New Tests ---------------- diff --git a/tests/functional/test_claims.py b/tests/functional/test_claims.py index 69f2dbedd..b4f5cd6cb 100644 --- a/tests/functional/test_claims.py +++ b/tests/functional/test_claims.py @@ -12,15 +12,16 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -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 import ddt 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 + @ddt.ddt class TestClaims(base.FunctionalTestBase): @@ -28,17 +29,23 @@ class TestClaims(base.FunctionalTestBase): @classmethod def setUpClass(cls): - """Create Queue, Post Messages for Claim Tests.""" - cls.cfg = config.Config() - cls.header = helpers.create_marconi_headers() + 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() - self.queue_url = self.cfg.base_url + '/queues/{}'.format(uuid.uuid1()) + 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}) + http.put(self.queue_url, self.header) self.claim_url = self.queue_url + '/claims' @@ -46,7 +53,7 @@ class TestClaims(base.FunctionalTestBase): #Post Messages url = self.queue_url + '/messages' doc = helpers.get_message_body(messagecount= - self.cfg.message_paging_uplimit) + self.limits.message_paging_uplimit) for i in range(25): http.post(url, self.header, doc) @@ -80,7 +87,7 @@ class TestClaims(base.FunctionalTestBase): result = http.post(url, self.header, doc) location = result.headers['Location'] - url = self.cfg.base_server + location + url = self.cfg.marconi.url + location result = http.get(url, self.header) self.assertEqual(result.status_code, 200) @@ -93,7 +100,7 @@ class TestClaims(base.FunctionalTestBase): Marconi allows a maximum of 20 messages per claim. """ url = self.claim_url + '?limit=' + \ - str(self.cfg.message_paging_uplimit + 1) + str(self.limits.message_paging_uplimit + 1) doc = '{"ttl": 300, "grace": 100}' result = http.post(url, self.header, doc) @@ -111,7 +118,7 @@ class TestClaims(base.FunctionalTestBase): #Patch Claim claim_location = result.headers['Location'] - url = self.cfg.base_server + claim_location + url = self.cfg.marconi.url + claim_location doc_updated = '{"ttl": 300}' result = http.patch(url, self.header, doc_updated) @@ -134,7 +141,7 @@ class TestClaims(base.FunctionalTestBase): href_list = [result.json()[i]['href'] for i in range(len(result.json()))] - url_list = [self.cfg.base_server + href + url_list = [self.cfg.marconi.url + href for href in href_list] #Delete Claimed Messages @@ -153,7 +160,7 @@ class TestClaims(base.FunctionalTestBase): #Extract claim location and construct the claim URL. location = result.headers['Location'] - url = self.cfg.base_server + location + url = self.cfg.marconi.url + location #Release Claim. result = http.delete(url, self.header) @@ -220,7 +227,7 @@ class TestClaims(base.FunctionalTestBase): #Extract claim location and construct the claim URL. location = result.headers['Location'] - url = self.cfg.base_server + location + url = self.cfg.marconi.url + location #Patch Claim. doc = {"ttl": ttl} diff --git a/tests/functional/test_messages.py b/tests/functional/test_messages.py index 71e0a2cc4..c13163697 100644 --- a/tests/functional/test_messages.py +++ b/tests/functional/test_messages.py @@ -12,14 +12,14 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. +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 -import ddt -import uuid - @ddt.ddt class TestMessages(base.FunctionalTestBase): @@ -28,16 +28,23 @@ class TestMessages(base.FunctionalTestBase): @classmethod def setUpClass(cls): - cls.cfg = config.Config() - cls.header = helpers.create_marconi_headers() + 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() - self.queue_url = self.cfg.base_url + '/queues/{}'.format(uuid.uuid1()) + 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}) + http.put(self.queue_url, self.header) self.message_url = self.queue_url + '/messages' @@ -58,7 +65,7 @@ class TestMessages(base.FunctionalTestBase): # GET on posted message href = result.json()['resources'][0] - url = self.cfg.base_server + href + url = self.cfg.marconi.url + href result = http.get(url, self.header) self.assertEqual(result.status_code, 200) @@ -97,7 +104,7 @@ class TestMessages(base.FunctionalTestBase): # GET on posted messages location = result.headers['location'] - url = self.cfg.base_server + location + url = self.cfg.marconi.url + location result = http.get(url, self.header) self.assertEqual(result.status_code, 200) @@ -139,7 +146,7 @@ class TestMessages(base.FunctionalTestBase): self.assertMessageCount(actual_msg_count, expected_msg_count) href = result.json()['links'][0]['href'] - url = self.cfg.base_server + href + url = self.cfg.marconi.url + href self.assertEqual(result.status_code, 204) @@ -154,7 +161,7 @@ class TestMessages(base.FunctionalTestBase): # Delete posted message href = result.json()['resources'][0] - url = self.cfg.base_server + href + url = self.cfg.marconi.url + href result = http.delete(url, self.header) self.assertEqual(result.status_code, 204) @@ -173,7 +180,7 @@ class TestMessages(base.FunctionalTestBase): # Delete posted messages location = result.headers['Location'] - url = self.cfg.base_server + location + url = self.cfg.marconi.url + location result = http.delete(url, self.header) self.assertEqual(result.status_code, 204) @@ -201,7 +208,7 @@ class TestMessages(base.FunctionalTestBase): # Delete posted message location = result.headers['Location'] - url = self.cfg.base_server + location + url = self.cfg.marconi.url + location url += ',nonexisting' result = http.delete(url, self.header) self.assertEqual(result.status_code, 204) @@ -217,7 +224,7 @@ class TestMessages(base.FunctionalTestBase): # Get posted message and a nonexisting message location = result.headers['Location'] - url = self.cfg.base_server + location + url = self.cfg.marconi.url + location url += ',nonexisting' result = http.get(url, self.header) self.assertEqual(result.status_code, 200) @@ -256,7 +263,7 @@ class TestMessages(base.FunctionalTestBase): """ url = self.message_url + '?ids=' \ + ','.join(str(i) for i in - range(self.cfg.message_paging_uplimit + 1)) + range(self.limits.message_paging_uplimit + 1)) result = http.delete(url, self.header) self.assertEqual(result.status_code, 400) @@ -271,7 +278,7 @@ class TestMessages(base.FunctionalTestBase): """ url = self.message_url + '?ids=' \ + ','.join(str(i) for i in - range(self.cfg.message_paging_uplimit + 1)) + range(self.limits.message_paging_uplimit + 1)) result = http.get(url, self.header) self.assertEqual(result.status_code, 400) diff --git a/tests/functional/test_queue.py b/tests/functional/test_queue.py index aaf0b30df..f3e36f6e6 100644 --- a/tests/functional/test_queue.py +++ b/tests/functional/test_queue.py @@ -13,16 +13,16 @@ # implied. # See the License for the specific language governing permissions and # limitations under the License. -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 - import copy import ddt 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 + @ddt.ddt class TestInsertQueue(base.FunctionalTestBase): @@ -31,9 +31,14 @@ class TestInsertQueue(base.FunctionalTestBase): @classmethod def setUpClass(cls): - cls.cfg = config.Config() - cls.header = helpers.create_marconi_headers() + 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_empty = set(['location']) cls.headers_response_with_body = set(['content-location', 'content-type']) @@ -42,7 +47,7 @@ class TestInsertQueue(base.FunctionalTestBase): 'i' * 64) def test_insert_queue(self, queue_name): """Create Queue.""" - self.url = self.cfg.base_url + '/queues/' + queue_name + self.url = self.base_url + '/queues/' + queue_name result = http.put(self.url, self.header) self.assertEqual(result.status_code, 201) @@ -60,7 +65,7 @@ class TestInsertQueue(base.FunctionalTestBase): @ddt.data('汉字漢字', '@$@^qw', 'i' * 65) def test_insert_queue_invalid_name(self, queue_name): """Create Queue.""" - self.url = self.cfg.base_url + '/queues/' + queue_name + self.url = self.base_url + '/queues/' + queue_name result = http.put(self.url, self.header) self.assertEqual(result.status_code, 400) @@ -73,7 +78,14 @@ class TestInsertQueue(base.FunctionalTestBase): def test_insert_queue_invalid_authtoken(self): """Insert Queue with invalid authtoken.""" - self.url = self.cfg.base_url + '/queues/invalidauthtoken' + + # NOTE(flaper87): Currently, tearDown + # depends on this attribute. Needs to + # be fixed. + self.url = self.base_url + '/queues/invalidauthtoken' + + if not self.cfg.auth.auth_on: + self.skipTest("Auth is not on!") header = copy.copy(self.header) header["X-Auth-Token"] = 'invalid' @@ -85,7 +97,7 @@ class TestInsertQueue(base.FunctionalTestBase): def test_insert_queue_header_plaintext(self): """Insert Queue with 'Accept': 'plain/text'.""" - self.url = self.cfg.base_url + '/queues/plaintextheader' + self.url = self.base_url + '/queues/plaintextheader' header = copy.copy(self.header) header["Accept"] = 'plain/text' @@ -96,7 +108,7 @@ class TestInsertQueue(base.FunctionalTestBase): def test_insert_queue_header_asterisk(self): """Insert Queue with 'Accept': '*/*'.""" - self.url = self.cfg.base_url + '/queues/asteriskinheader' + self.url = self.base_url + '/queues/asteriskinheader' header = copy.copy(self.header) header["Accept"] = '*/*' @@ -107,13 +119,13 @@ class TestInsertQueue(base.FunctionalTestBase): def test_insert_queue_with_metadata(self): """Insert queue with a non-empty request body.""" - self.url = self.cfg.base_url + '/queues/hasmetadata' + self.url = self.base_url + '/queues/hasmetadata' doc = '{"queue": "Has Metadata"}' result = http.put(self.url, self.header, doc) self.assertEqual(result.status_code, 201) - self.url = self.cfg.base_url + '/queues/hasmetadata/metadata' + self.url = self.base_url + '/queues/hasmetadata/metadata' result = http.get(self.url, self.header) self.assertEqual(result.status_code, 200) @@ -133,16 +145,20 @@ class TestQueueMetaData(base.FunctionalTestBase): @classmethod def setUpClass(cls): - cls.cfg = config.Config() - cls.header = helpers.create_marconi_headers() + 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.queue_url = self.cfg.base_url + '/queues/{}'.format(uuid.uuid1()) + self.queue_url = self.base_url + '/queues/{}'.format(uuid.uuid1()) http.put(self.queue_url, self.header) self.queue_metadata_url = self.queue_url + '/metadata' @@ -186,23 +202,34 @@ class TestQueueMisc(base.FunctionalTestBase): @classmethod def setUpClass(cls): - cls.cfg = config.Config() - cls.header = helpers.create_marconi_headers() + 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.queue_url = cls.cfg.base_url + '/queues/{}'.format(uuid.uuid1()) - http.put(cls.queue_url, cls.header) + cls.base_url = '%s/%s' % (cls.cfg.marconi.url, + cls.cfg.marconi.version) - url = cls.queue_url + '/metadata' + 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, cls.header, json.dumps(metadata)) + http.put(url, self.header, json.dumps(metadata)) def test_list_queues(self): """List Queues.""" - url = self.cfg.base_url + '/queues' + url = self.base_url + '/queues' result = http.get(url, self.header) self.assertEqual(result.status_code, 200) @@ -216,7 +243,7 @@ class TestQueueMisc(base.FunctionalTestBase): def test_list_queues_detailed(self): """List Queues with detailed = True.""" - url = self.cfg.base_url + '/queues?detailed=True' + url = self.base_url + '/queues?detailed=True' result = http.get(url, self.header) self.assertEqual(result.status_code, 200) @@ -231,7 +258,7 @@ class TestQueueMisc(base.FunctionalTestBase): @ddt.data(0, -1, 30) def test_list_queue_invalid_limit(self, limit): """List Queues with a limit value that is not allowed.""" - url = self.cfg.base_url + '/queues?limit=' + str(limit) + url = self.base_url + '/queues?limit=' + str(limit) result = http.get(url, self.header) self.assertEqual(result.status_code, 400) @@ -240,7 +267,7 @@ class TestQueueMisc(base.FunctionalTestBase): def test_check_health(self): """Test health endpoint.""" - url = self.cfg.base_url + '/health' + url = self.base_url + '/health' result = http.get(url, self.header) self.assertEqual(result.status_code, 204) @@ -249,7 +276,7 @@ class TestQueueMisc(base.FunctionalTestBase): def test_check_queue_exists(self): """Checks if queue exists.""" - url = self.cfg.base_url + '/queues/testqueue' + url = self.base_url + '/queues/testqueue' http.put(url, self.header) result = http.get(url, self.header) @@ -262,7 +289,7 @@ class TestQueueMisc(base.FunctionalTestBase): def test_check_queue_exists_negative(self): """Checks non-existing queue.""" - url = self.cfg.base_url + '/queues/nonexistingqueue' + url = self.base_url + '/queues/nonexistingqueue' result = http.get(url, self.header) self.assertEqual(result.status_code, 404) @@ -274,7 +301,7 @@ class TestQueueMisc(base.FunctionalTestBase): def test_get_queue_malformed_marker(self): """List queues with invalid marker.""" - url = self.cfg.base_url + '/queues?marker=invalid' + url = self.base_url + '/queues?marker=invalid' result = http.get(url, self.header) self.assertEqual(result.status_code, 204) @@ -284,5 +311,5 @@ class TestQueueMisc(base.FunctionalTestBase): @classmethod def tearDownClass(cls): """Delete Queue.""" - url = cls.cfg.base_url + '/queues/testqueue' + url = cls.base_url + '/queues/testqueue' http.delete(url, cls.header)