From bf0645fdb5efa3527444b47b81e934c564ece6ba Mon Sep 17 00:00:00 2001 From: kgriffs Date: Tue, 17 Jun 2014 19:09:48 -0500 Subject: [PATCH] Update hacking version and fix new violations The newer hacking version is more strict about some things, so I had to update a bunch of files with minor issues that previously fell through the cracks. Change-Id: I169bc6f8533bab28c7d6cf321ea83a8d7945f136 --- marconi/cmd/server.py | 1 + marconi/common/utils.py | 5 ++- marconi/queues/bootstrap.py | 1 - marconi/queues/storage/base.py | 18 +++++----- marconi/queues/storage/errors.py | 14 ++++---- marconi/queues/storage/mongodb/messages.py | 15 ++++---- marconi/queues/storage/mongodb/queues.py | 8 ++--- marconi/queues/storage/mongodb/utils.py | 1 + marconi/queues/storage/pooling.py | 3 +- marconi/queues/storage/sqlalchemy/claims.py | 13 +++---- marconi/queues/storage/sqlalchemy/messages.py | 10 +++--- marconi/queues/storage/sqlalchemy/queues.py | 17 +++++---- marconi/queues/transport/base.py | 2 +- marconi/queues/transport/wsgi/v1_0/homedoc.py | 12 +++---- .../queues/transport/wsgi/v1_0/messages.py | 8 ++--- marconi/queues/transport/wsgi/v1_1/homedoc.py | 12 +++---- .../queues/transport/wsgi/v1_1/messages.py | 8 ++--- marconi/tests/functional/base.py | 11 +++--- marconi/tests/helpers.py | 36 ++++++++++++------- marconi/tests/queues/transport/wsgi/base.py | 7 ++-- .../queues/transport/wsgi/v1/test_claims.py | 2 +- .../queues/transport/wsgi/v1/test_home.py | 3 -- .../queues/transport/wsgi/v1/test_messages.py | 7 ++-- .../queues/transport/wsgi/v1_1/test_claims.py | 4 +-- .../transport/wsgi/v1_1/test_messages.py | 4 +-- test-requirements.txt | 2 +- tests/functional/wsgi/v1/test_claims.py | 20 +++++------ tests/functional/wsgi/v1/test_messages.py | 17 ++++----- tests/functional/wsgi/v1/test_queues.py | 16 +++++---- tests/unit/queues/transport/wsgi/test_v1_0.py | 8 ++--- tests/unit/queues/transport/wsgi/test_v1_1.py | 8 ++--- 31 files changed, 155 insertions(+), 138 deletions(-) diff --git a/marconi/cmd/server.py b/marconi/cmd/server.py index 298feb2f7..153283cb5 100644 --- a/marconi/cmd/server.py +++ b/marconi/cmd/server.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os + from oslo.config import cfg from marconi.common import cli diff --git a/marconi/common/utils.py b/marconi/common/utils.py index 9d11c9fab..6890f2076 100644 --- a/marconi/common/utils.py +++ b/marconi/common/utils.py @@ -22,6 +22,7 @@ import six def fields(d, names, pred=lambda x: True, key_transform=lambda x: x, value_transform=lambda x: x): """Returns the entries in this dictionary with keys appearing in names. + :type d: dict :type names: [a] :param pred: a filter that is applied to the values of the dictionary. @@ -32,8 +33,8 @@ def fields(d, names, pred=lambda x: True, returning it :type value_transform: a -> a :rtype: dict - """ + return dict((key_transform(k), value_transform(v)) for k, v in six.iteritems(d) if k in names and pred(v)) @@ -58,7 +59,9 @@ def dict_to_conf(options): :returns: a list of options compatible with oslo.config :rtype: [oslo.config.cfg.Opt] """ + opts = [] + for k, v in six.iteritems(options): opt_type = _pytype_to_cfgtype[type(v)] opts.append(opt_type(name=k, default=v)) diff --git a/marconi/queues/bootstrap.py b/marconi/queues/bootstrap.py index 71e143cd4..e0e76ef2f 100644 --- a/marconi/queues/bootstrap.py +++ b/marconi/queues/bootstrap.py @@ -23,7 +23,6 @@ from marconi.openstack.common import log from marconi.queues.storage import pipeline from marconi.queues.storage import pooling from marconi.queues.storage import utils as storage_utils -from marconi.queues import transport # NOQA LOG = log.getLogger(__name__) diff --git a/marconi/queues/storage/base.py b/marconi/queues/storage/base.py index 8a5320388..4815bc68e 100644 --- a/marconi/queues/storage/base.py +++ b/marconi/queues/storage/base.py @@ -16,6 +16,7 @@ """Implements the DriverBase abstract class for Marconi storage drivers.""" import abc + import six DEFAULT_QUEUES_PER_PAGE = 10 @@ -480,15 +481,15 @@ class PoolsBase(ControllerBase): @six.add_metaclass(abc.ABCMeta) class CatalogueBase(ControllerBase): - """A controller for managing the catalogue. The catalogue is - responsible for maintaining a mapping between project.queue - entries to their pool. + """A controller for managing the catalogue. + + The catalogue is responsible for maintaining a mapping + between project.queue entries to their pool. """ @abc.abstractmethod def list(self, project): - """Returns a list of queue entries from the catalogue associated with - this project. + """Get a list of queues from the catalogue. :param project: The project to use when filtering through queue entries. @@ -500,8 +501,7 @@ class CatalogueBase(ControllerBase): @abc.abstractmethod def get(self, project, queue): - """Returns the pool identifier for the queue registered under this - project. + """Returns the pool identifier for the given queue. :param project: Namespace to search for the given queue :type project: six.text_type @@ -527,7 +527,7 @@ class CatalogueBase(ControllerBase): @abc.abstractmethod def insert(self, project, queue, pool): - """Creates a new catalogue entry, or updates it if it already existed. + """Creates a new catalogue entry, or updates it if it already exists. :param project: str - Namespace to insert the given queue into :type project: six.text_type @@ -551,7 +551,7 @@ class CatalogueBase(ControllerBase): @abc.abstractmethod def update(self, project, queue, pools=None): - """Updates the pool identifier for this queue + """Updates the pool identifier for this queue. :param project: Namespace to search :type project: six.text_type diff --git a/marconi/queues/storage/errors.py b/marconi/queues/storage/errors.py index 340688361..12a05adeb 100644 --- a/marconi/queues/storage/errors.py +++ b/marconi/queues/storage/errors.py @@ -24,9 +24,7 @@ class ExceptionBase(Exception): class ConnectionError(ExceptionBase): - """Raised when the connection with the back-end - was lost. - """ + """Raised when the connection with the back-end was lost.""" class DoesNotExist(ExceptionBase): @@ -38,9 +36,7 @@ class NotPermitted(ExceptionBase): class Conflict(ExceptionBase): - """Resource could not be created due to a conflict - with an existing resource. - """ + """Resource could not be created due to a conflict.""" class MessageConflict(Conflict): @@ -51,13 +47,15 @@ class MessageConflict(Conflict): def __init__(self, queue, project, message_ids): """Initializes the error with contextual information. + :param queue: name of the queue to which the message was posted :param project: name of the project to which the queue belongs :param message_ids: list of IDs for messages successfully - posted. Note that these must be in the same order as the - list of messages originally submitted to be enqueued. + posted. Note that these must be in the same order as the + list of messages originally submitted to be enqueued. """ + super(MessageConflict, self).__init__(queue=queue, project=project) self._succeeded_ids = message_ids diff --git a/marconi/queues/storage/mongodb/messages.py b/marconi/queues/storage/mongodb/messages.py index eef331a7b..011e57105 100644 --- a/marconi/queues/storage/mongodb/messages.py +++ b/marconi/queues/storage/mongodb/messages.py @@ -148,9 +148,9 @@ class MessageController(storage.Message): for collection in self._collections: self._ensure_indexes(collection) - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Helpers - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def _ensure_indexes(self, collection): """Ensures that all indexes are created.""" @@ -296,9 +296,9 @@ class MessageController(storage.Message): # ensure the most performant one is chosen. return cursor.hint(ACTIVE_INDEX_FIELDS) - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # "Friends" interface - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def _count(self, queue_name, project=None, include_claimed=False): """Return total number of messages in a queue. @@ -358,8 +358,7 @@ class MessageController(storage.Message): collection = self._collection(queue_name, project) msgs = collection.find(query, sort=[('k', 1)], read_preference=preference).hint( - CLAIMED_INDEX_FIELDS - ) + CLAIMED_INDEX_FIELDS) if limit is not None: msgs = msgs.limit(limit) @@ -392,9 +391,9 @@ class MessageController(storage.Message): {'$set': {'c': {'id': None, 'e': now}}}, upsert=False, multi=True) - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Public interface - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def list(self, queue_name, project=None, marker=None, limit=storage.DEFAULT_MESSAGES_PER_PAGE, diff --git a/marconi/queues/storage/mongodb/queues.py b/marconi/queues/storage/mongodb/queues.py index 45960fbf3..0b29e02c4 100644 --- a/marconi/queues/storage/mongodb/queues.py +++ b/marconi/queues/storage/mongodb/queues.py @@ -94,9 +94,9 @@ class QueueController(storage.Queue): # a specific project, for example. Order matters! self._collection.ensure_index([('p_q', 1)], unique=True) - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Helpers - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def _get(self, name, project=None, fields={'m': 1, '_id': 0}): queue = self._collection.find_one(_get_scoped_query(name, project), @@ -190,9 +190,9 @@ class QueueController(storage.Queue): return doc['c']['v'] - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Interface - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def list(self, project=None, marker=None, limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False): diff --git a/marconi/queues/storage/mongodb/utils.py b/marconi/queues/storage/mongodb/utils.py index 96d208ae1..66cf7e098 100644 --- a/marconi/queues/storage/mongodb/utils.py +++ b/marconi/queues/storage/mongodb/utils.py @@ -122,6 +122,7 @@ def to_oid(obj): def oid_ts(oid): """Converts an ObjectId to a UNIX timestamp. + :raises: TypeError if oid isn't an ObjectId """ try: diff --git a/marconi/queues/storage/pooling.py b/marconi/queues/storage/pooling.py index 31bee4f5c..fb3c638f8 100644 --- a/marconi/queues/storage/pooling.py +++ b/marconi/queues/storage/pooling.py @@ -127,8 +127,7 @@ class RoutingController(storage.base.ControllerBase): class QueueController(RoutingController): - """Controller to facilitate special processing for queue operations. - """ + """Controller to facilitate special processing for queue operations.""" _resource_name = 'queue' diff --git a/marconi/queues/storage/sqlalchemy/claims.py b/marconi/queues/storage/sqlalchemy/claims.py index 2141edb1b..517da9af7 100644 --- a/marconi/queues/storage/sqlalchemy/claims.py +++ b/marconi/queues/storage/sqlalchemy/claims.py @@ -35,10 +35,10 @@ class ClaimController(storage.Claim): sa.and_( tables.Messages.c.ttl > utils.get_age(tables.Messages.c.created), - #tables.Messages.c.ttl > - #utils.get_age(tables.Claims.c.created), - tables.Messages.c.cid == cid - )) + # tables.Messages.c.ttl > + # utils.get_age(tables.Claims.c.created), + tables.Messages.c.cid == cid)) + records = trans.execute(sel) for id, body, ttl, created in records: @@ -141,8 +141,9 @@ class ClaimController(storage.Claim): update = tables.Claims.update().where(sa.and_( tables.Claims.c.ttl > age, tables.Claims.c.id == cid, - tables.Claims.c.id == qid)).\ - values(ttl=metadata['ttl']) + tables.Claims.c.id == qid)) + + update = update.values(ttl=metadata['ttl']) res = trans.execute(update) if res.rowcount != 1: diff --git a/marconi/queues/storage/sqlalchemy/messages.py b/marconi/queues/storage/sqlalchemy/messages.py index 50fb00dd2..a5b8c090e 100644 --- a/marconi/queues/storage/sqlalchemy/messages.py +++ b/marconi/queues/storage/sqlalchemy/messages.py @@ -215,11 +215,13 @@ class MessageController(storage.Message): with self.driver.trans() as trans: qid = utils.get_qid(self.driver, queue, project) + # TODO(kgriffs): Need to port this to sqla! Bug #1331228 + # # cleanup all expired messages in this queue - #self.driver.run(''' - # delete from Messages - # where ttl <= julianday() * 86400.0 - created - # and qid = ?''', qid) + # self.driver.run(''' + # delete from Messages + # where ttl <= julianday() * 86400.0 - created + # and qid = ?''', qid) # executemany() sets lastrowid to None, so no matter we manually # generate the IDs or not, we still need to query for it. diff --git a/marconi/queues/storage/sqlalchemy/queues.py b/marconi/queues/storage/sqlalchemy/queues.py index 428d04497..880136725 100644 --- a/marconi/queues/storage/sqlalchemy/queues.py +++ b/marconi/queues/storage/sqlalchemy/queues.py @@ -98,11 +98,12 @@ class QueueController(storage.Queue): if project is None: project = '' - update = tables.Queues.update().\ - where(sa.and_( - tables.Queues.c.project == project, - tables.Queues.c.name == name)).\ - values(metadata=utils.json_encode(metadata)) + update = (tables.Queues.update(). + where(sa.and_( + tables.Queues.c.project == project, + tables.Queues.c.name == name)). + values(metadata=utils.json_encode(metadata))) + res = self.driver.run(update) try: @@ -131,15 +132,13 @@ class QueueController(storage.Queue): tables.Messages.c.qid == qid, tables.Messages.c.cid != (None), tables.Messages.c.ttl > - sfunc.now() - tables.Messages.c.created, - )), + sfunc.now() - tables.Messages.c.created)), sa.sql.select([sa.func.count(tables.Messages.c.id)], sa.and_( tables.Messages.c.qid == qid, tables.Messages.c.cid == (None), tables.Messages.c.ttl > - sfunc.now() - tables.Messages.c.created, - )) + sfunc.now() - tables.Messages.c.created)) ]) claimed, free = self.driver.get(sel) diff --git a/marconi/queues/transport/base.py b/marconi/queues/transport/base.py index ea78e3d4b..3fee030ac 100644 --- a/marconi/queues/transport/base.py +++ b/marconi/queues/transport/base.py @@ -14,9 +14,9 @@ # limitations under the License. import abc -import six from oslo.config import cfg +import six _TRANSPORT_OPTIONS = ( diff --git a/marconi/queues/transport/wsgi/v1_0/homedoc.py b/marconi/queues/transport/wsgi/v1_0/homedoc.py index de251fdaf..013871606 100644 --- a/marconi/queues/transport/wsgi/v1_0/homedoc.py +++ b/marconi/queues/transport/wsgi/v1_0/homedoc.py @@ -18,9 +18,9 @@ import json # NOTE(kgriffs): http://tools.ietf.org/html/draft-nottingham-json-home-03 JSON_HOME = { 'resources': { - #------------------------------------------------------------------ + # ----------------------------------------------------------------- # Queues - #------------------------------------------------------------------ + # ----------------------------------------------------------------- 'rel/queues': { 'href-template': '/v1/queues{?marker,limit,detailed}', 'href-vars': { @@ -72,9 +72,9 @@ JSON_HOME = { }, }, - #------------------------------------------------------------------ + # ----------------------------------------------------------------- # Messages - #------------------------------------------------------------------ + # ----------------------------------------------------------------- 'rel/messages': { 'href-template': ('/v1/queues/{queue_name}/messages' '{?marker,limit,echo,include_claimed}'), @@ -106,9 +106,9 @@ JSON_HOME = { }, }, - #------------------------------------------------------------------ + # ----------------------------------------------------------------- # Claims - #------------------------------------------------------------------ + # ----------------------------------------------------------------- 'rel/claim': { 'href-template': '/v1/queues/{queue_name}/claims{?limit}', 'href-vars': { diff --git a/marconi/queues/transport/wsgi/v1_0/messages.py b/marconi/queues/transport/wsgi/v1_0/messages.py index 7b99c3db1..5f40c8f0d 100644 --- a/marconi/queues/transport/wsgi/v1_0/messages.py +++ b/marconi/queues/transport/wsgi/v1_0/messages.py @@ -38,9 +38,9 @@ class CollectionResource(object): self._validate = validate self.message_controller = message_controller - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Helpers - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def _get_by_id(self, base_path, project_id, queue_name, ids): """Returns one or more messages from the queue by ID.""" @@ -127,9 +127,9 @@ class CollectionResource(object): ] } - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Interface - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def on_post(self, req, resp, project_id, queue_name): LOG.debug(u'Messages collection POST - queue: %(queue)s, ' diff --git a/marconi/queues/transport/wsgi/v1_1/homedoc.py b/marconi/queues/transport/wsgi/v1_1/homedoc.py index 9c5dea5dc..f681fb33a 100644 --- a/marconi/queues/transport/wsgi/v1_1/homedoc.py +++ b/marconi/queues/transport/wsgi/v1_1/homedoc.py @@ -18,9 +18,9 @@ import json # NOTE(kgriffs): http://tools.ietf.org/html/draft-nottingham-json-home-03 JSON_HOME = { 'resources': { - #------------------------------------------------------------------ + # ----------------------------------------------------------------- # Queues - #------------------------------------------------------------------ + # ----------------------------------------------------------------- 'rel/queues': { 'href-template': '/v1.1/queues{?marker,limit,detailed}', 'href-vars': { @@ -72,9 +72,9 @@ JSON_HOME = { }, }, - #------------------------------------------------------------------ + # ----------------------------------------------------------------- # Messages - #------------------------------------------------------------------ + # ----------------------------------------------------------------- 'rel/messages': { 'href-template': ('/v1.1/queues/{queue_name}/messages' '{?marker,limit,echo,include_claimed}'), @@ -106,9 +106,9 @@ JSON_HOME = { }, }, - #------------------------------------------------------------------ + # ----------------------------------------------------------------- # Claims - #------------------------------------------------------------------ + # ----------------------------------------------------------------- 'rel/claim': { 'href-template': '/v1.1/queues/{queue_name}/claims{?limit}', 'href-vars': { diff --git a/marconi/queues/transport/wsgi/v1_1/messages.py b/marconi/queues/transport/wsgi/v1_1/messages.py index e321887e7..853d1749c 100644 --- a/marconi/queues/transport/wsgi/v1_1/messages.py +++ b/marconi/queues/transport/wsgi/v1_1/messages.py @@ -41,9 +41,9 @@ class CollectionResource(object): self.message_controller = message_controller self.queue_controller = queue_controller - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Helpers - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def _get_by_id(self, base_path, project_id, queue_name, ids): """Returns one or more messages from the queue by ID.""" @@ -131,9 +131,9 @@ class CollectionResource(object): ] } - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- # Interface - #----------------------------------------------------------------------- + # ---------------------------------------------------------------------- def on_post(self, req, resp, project_id, queue_name): LOG.debug(u'Messages collection POST - queue: %(queue)s, ' diff --git a/marconi/tests/functional/base.py b/marconi/tests/functional/base.py index 93b02b1fb..2e2e9a2ef 100644 --- a/marconi/tests/functional/base.py +++ b/marconi/tests/functional/base.py @@ -15,9 +15,10 @@ # limitations under the License. import abc -import jsonschema import multiprocessing import os + +import jsonschema import six from marconi.openstack.common import timeutils @@ -113,8 +114,8 @@ class FunctionalTestBase(testing.TestBase): :param expectedCount: limit value passed in the url (OR) default(10). :param actualCount: number of messages returned in the API response. """ - msg = 'More Messages returned than allowed: expected count = {0}' \ - ', actual count = {1}'.format(expectedCount, actualCount) + msg = ('More Messages returned than allowed: expected count = {0}' + ', actual count = {1}'.format(expectedCount, actualCount)) self.assertTrue(actualCount <= expectedCount, msg) def assertSchema(self, response, expectedSchemaName): @@ -188,8 +189,8 @@ class FunctionalTestBase(testing.TestBase): # (needed to pass this test on sqlite driver) delta = int(delta) - msg = 'Invalid Time Delta {0}, Created time {1}, Now {2}' \ - .format(delta, created_time, now) + msg = ('Invalid Time Delta {0}, Created time {1}, Now {2}' + .format(delta, created_time, now)) self.assertTrue(0 <= delta <= 6000, msg) diff --git a/marconi/tests/helpers.py b/marconi/tests/helpers.py index 58d59cfb1..47b51f218 100644 --- a/marconi/tests/helpers.py +++ b/marconi/tests/helpers.py @@ -58,8 +58,10 @@ def expect(*exc_type): @contextlib.contextmanager def partitions(controller, count): - """context_manager: Creates `count` partitions in storage, - and deletes them once this goes out of scope. + """Context manager to create several partitions for testing. + + The partitions are automatically deleted when the context manager + goes out of scope. :param controller: :param count: int - number of partitions to create @@ -78,8 +80,10 @@ def partitions(controller, count): @contextlib.contextmanager def partition(controller, name, weight, hosts): - """context_manager: Creates a single partition that is deleted - once this context manager goes out of scope. + """Context manager to create a single partition for testing. + + The partition is automatically deleted when the context manager + goes out of scope. :param controller: storage handler :param name: str - partition name @@ -94,8 +98,10 @@ def partition(controller, name, weight, hosts): @contextlib.contextmanager def entry(controller, project, queue, partition, host, metadata={}): - """Creates a catalogue entry with the given details, and deletes - it once the context manager goes out of scope. + """Context manager to create a catalogue entry for testing. + + The entry is automatically deleted when the context manager + goes out of scope. :param controller: storage handler :param project: str - namespace for queue @@ -112,8 +118,10 @@ def entry(controller, project, queue, partition, host, metadata={}): @contextlib.contextmanager def entries(controller, count): - """Creates `count` catalogue entries with the given details, and - deletes them once the context manager goes out of scope. + """Context manager to create several catalogue entries for testing. + + The entries are automatically deleted when the context manager + goes out of scope. :param controller: storage handler :param count: int - number of entries to create @@ -134,8 +142,10 @@ def entries(controller, count): @contextlib.contextmanager def pool_entry(controller, project, queue, pool): - """Creates a catalogue entry with the given details, and deletes - it once the context manager goes out of scope. + """Context manager to create a catalogue entry for testing. + + The entry is automatically deleted when the context manager + goes out of scope. :param controller: storage handler :type controller: queues.storage.base:CatalogueBase @@ -155,8 +165,10 @@ def pool_entry(controller, project, queue, pool): @contextlib.contextmanager def pool_entries(controller, count): - """Creates `count` catalogue entries with the given details, and - deletes them once the context manager goes out of scope. + """Context manager to create several catalogue entries for testing. + + The entries are automatically deleted when the context manager + goes out of scope. :param controller: storage handler :type controller: queues.storage.base:CatalogueBase diff --git a/marconi/tests/queues/transport/wsgi/base.py b/marconi/tests/queues/transport/wsgi/base.py index a3c6a7c1b..13a3a7618 100644 --- a/marconi/tests/queues/transport/wsgi/base.py +++ b/marconi/tests/queues/transport/wsgi/base.py @@ -16,11 +16,10 @@ from falcon import testing as ftest from marconi.openstack.common import jsonutils from marconi.queues import bootstrap +from marconi.queues.transport import validation from marconi.queues.transport.wsgi import driver from marconi import tests as testing -from marconi.queues.transport import validation - class TestBase(testing.TestBase): @@ -111,6 +110,7 @@ class TestBaseFaulty(TestBase): class V1Base(TestBase): """Base class for V1 API Tests. + Should contain methods specific to V1 of the API """ pass @@ -118,6 +118,7 @@ class V1Base(TestBase): class V1BaseFaulty(TestBaseFaulty): """Base class for V1 API Faulty Tests. + Should contain methods specific to V1 exception testing """ pass @@ -125,6 +126,7 @@ class V1BaseFaulty(TestBaseFaulty): class V1_1Base(TestBase): """Base class for V1.1 API Tests. + Should contain methods specific to V1.1 of the API """ @@ -147,6 +149,7 @@ class V1_1Base(TestBase): class V1_1BaseFaulty(TestBaseFaulty): """Base class for V1.1 API Faulty Tests. + Should contain methods specific to V1.1 exception testing """ pass diff --git a/marconi/tests/queues/transport/wsgi/v1/test_claims.py b/marconi/tests/queues/transport/wsgi/v1/test_claims.py index 1ffa45dce..4468d694e 100644 --- a/marconi/tests/queues/transport/wsgi/v1/test_claims.py +++ b/marconi/tests/queues/transport/wsgi/v1/test_claims.py @@ -137,7 +137,7 @@ class ClaimsBaseTest(base.V1Base): self.assertEqual(self.srmock.headers_dict['Content-Location'], claim_href) self.assertEqual(claim['ttl'], 100) - ## NOTE(cpp-cabrera): verify that claim age is non-negative + # NOTE(cpp-cabrera): verify that claim age is non-negative self.assertThat(claim['age'], matchers.GreaterThan(-1)) # Try to delete the message without submitting a claim_id diff --git a/marconi/tests/queues/transport/wsgi/v1/test_home.py b/marconi/tests/queues/transport/wsgi/v1/test_home.py index 7dbcb695f..1253e33a8 100644 --- a/marconi/tests/queues/transport/wsgi/v1/test_home.py +++ b/marconi/tests/queues/transport/wsgi/v1/test_home.py @@ -15,10 +15,7 @@ import falcon import six.moves.urllib.parse as urlparse - from marconi.openstack.common import jsonutils - - from marconi.tests.queues.transport.wsgi import base diff --git a/marconi/tests/queues/transport/wsgi/v1/test_messages.py b/marconi/tests/queues/transport/wsgi/v1/test_messages.py index 5f84a2459..ac865ea3a 100644 --- a/marconi/tests/queues/transport/wsgi/v1/test_messages.py +++ b/marconi/tests/queues/transport/wsgi/v1/test_messages.py @@ -234,8 +234,7 @@ class MessagesBaseTest(base.V1Base): @ddt.data(-1, 59, 1209601) def test_unacceptable_ttl(self, ttl): self.simulate_post(self.queue_path + '/messages', - body=jsonutils.dumps([{'ttl': ttl, - 'body': None}]), + body=jsonutils.dumps([{'ttl': ttl, 'body': None}]), headers=self.headers) self.assertEqual(self.srmock.status, falcon.HTTP_400) @@ -428,8 +427,8 @@ class MessagesBaseTest(base.V1Base): self.assertEqual(self.srmock.status, falcon.HTTP_200) def test_no_duplicated_messages_path_in_href(self): - """Fixes bug 1240897 - """ + """Test for bug 1240897.""" + path = self.queue_path + '/messages' self._post_messages(path, repeat=1) diff --git a/marconi/tests/queues/transport/wsgi/v1_1/test_claims.py b/marconi/tests/queues/transport/wsgi/v1_1/test_claims.py index 2a8a050b1..e6062c015 100644 --- a/marconi/tests/queues/transport/wsgi/v1_1/test_claims.py +++ b/marconi/tests/queues/transport/wsgi/v1_1/test_claims.py @@ -19,13 +19,13 @@ import uuid import ddt import falcon -from marconi.tests.queues.transport.wsgi import base import mock from testtools import matchers from marconi.openstack.common import jsonutils from marconi.openstack.common import timeutils from marconi import tests as testing +from marconi.tests.queues.transport.wsgi import base @ddt.ddt @@ -172,7 +172,7 @@ class ClaimsBaseTest(base.V1_1Base): self.assertEqual(self.srmock.headers_dict['Content-Location'], claim_href) self.assertEqual(claim['ttl'], 100) - ## NOTE(cpp-cabrera): verify that claim age is non-negative + # NOTE(cpp-cabrera): verify that claim age is non-negative self.assertThat(claim['age'], matchers.GreaterThan(-1)) # Try to delete the message without submitting a claim_id diff --git a/marconi/tests/queues/transport/wsgi/v1_1/test_messages.py b/marconi/tests/queues/transport/wsgi/v1_1/test_messages.py index 44adbd2ee..2c770ce09 100644 --- a/marconi/tests/queues/transport/wsgi/v1_1/test_messages.py +++ b/marconi/tests/queues/transport/wsgi/v1_1/test_messages.py @@ -444,8 +444,8 @@ class MessagesBaseTest(base.V1_1Base): self.assertEqual(self.srmock.status, falcon.HTTP_200) def test_no_duplicated_messages_path_in_href(self): - """Fixes bug 1240897 - """ + """Test for bug 1240897.""" + path = self.queue_path + '/messages' self._post_messages(path, repeat=1) diff --git a/test-requirements.txt b/test-requirements.txt index 7f1eb5350..f396551d8 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,5 @@ # Metrics and style -hacking>=0.8.0,<0.9 +hacking>=0.9.2,<0.10 # Packaging mock>=1.0 diff --git a/tests/functional/wsgi/v1/test_claims.py b/tests/functional/wsgi/v1/test_claims.py index 139d0c555..28dc7d960 100644 --- a/tests/functional/wsgi/v1/test_claims.py +++ b/tests/functional/wsgi/v1/test_claims.py @@ -41,7 +41,7 @@ class TestClaims(base.FunctionalTestBase): self.claim_url = self.queue_url + '/claims' self.client.set_base_url(self.claim_url) - #Post Messages + # Post Messages url = self.queue_url + '/messages' doc = helpers.create_message_body( messagecount=self.limits.max_messages_per_page) @@ -102,13 +102,13 @@ class TestClaims(base.FunctionalTestBase): def test_claim_patch(self): """Update Claim.""" - #Test Setup - Post Claim + # Test Setup - Post Claim doc = {"ttl": 300, "grace": 400} result = self.client.post(data=doc) self.assertEqual(result.status_code, 201) - #Patch Claim + # Patch Claim claim_location = result.headers['Location'] url = self.cfg.marconi.url + claim_location doc_updated = {"ttl": 300} @@ -116,7 +116,7 @@ class TestClaims(base.FunctionalTestBase): result = self.client.patch(url, data=doc_updated) self.assertEqual(result.status_code, 204) - #verify that the claim TTL is updated + # verify that the claim TTL is updated result = self.client.get(url) new_ttl = result.json()['ttl'] self.assertEqual(new_ttl, 300) @@ -125,13 +125,13 @@ class TestClaims(base.FunctionalTestBase): def test_delete_claimed_message(self): """Delete message belonging to a Claim.""" - #Test Setup - Post claim + # Test Setup - Post claim doc = {"ttl": 60, "grace": 60} result = self.client.post(data=doc) self.assertEqual(result.status_code, 201) - #Delete Claimed Messages + # Delete Claimed Messages for rst in result.json(): href = rst['href'] url = self.cfg.marconi.url + href @@ -147,11 +147,11 @@ class TestClaims(base.FunctionalTestBase): result = self.client.post(data=doc) self.assertEqual(result.status_code, 201) - #Extract claim location and construct the claim URL. + # Extract claim location and construct the claim URL. location = result.headers['Location'] url = self.cfg.marconi.url + location - #Release Claim. + # Release Claim. result = self.client.delete(url) self.assertEqual(result.status_code, 204) @@ -214,11 +214,11 @@ class TestClaims(base.FunctionalTestBase): result = self.client.post(data=doc) self.assertEqual(result.status_code, 201) - #Extract claim location and construct the claim URL. + # Extract claim location and construct the claim URL. location = result.headers['Location'] url = self.cfg.marconi.url + location - #Patch Claim. + # Patch Claim. doc = {"ttl": ttl} result = self.client.patch(url, data=doc) self.assertEqual(result.status_code, 400) diff --git a/tests/functional/wsgi/v1/test_messages.py b/tests/functional/wsgi/v1/test_messages.py index 2b89fa1be..cf3b11682 100644 --- a/tests/functional/wsgi/v1/test_messages.py +++ b/tests/functional/wsgi/v1/test_messages.py @@ -146,8 +146,9 @@ class TestMessages(base.FunctionalTestBase): expected_msg_count = params.get('limit', 10) # Test Setup - doc = helpers.create_message_body(messagecount= - self.limits.max_messages_per_page) + doc = helpers.create_message_body( + messagecount=self.limits.max_messages_per_page) + result = self.client.post(data=doc) self.assertEqual(result.status_code, 201) @@ -300,9 +301,9 @@ class TestMessages(base.FunctionalTestBase): By default, max messages that can be deleted in a single request is 20. """ - url = self.message_url + '?ids=' \ - + ','.join(str(i) for i in - range(self.limits.max_messages_per_page + 1)) + url = (self.message_url + '?ids=' + + ','.join(str(i) for i in + range(self.limits.max_messages_per_page + 1))) result = self.client.delete(url) self.assertEqual(result.status_code, 400) @@ -315,9 +316,9 @@ class TestMessages(base.FunctionalTestBase): By default, max messages that can be fetched in a single request is 20. """ - url = self.message_url + '?ids=' \ - + ','.join(str(i) for i in - range(self.limits.max_messages_per_page + 1)) + url = (self.message_url + '?ids=' + + ','.join(str(i) for i in + range(self.limits.max_messages_per_page + 1))) result = self.client.get(url) self.assertEqual(result.status_code, 400) diff --git a/tests/functional/wsgi/v1/test_queues.py b/tests/functional/wsgi/v1/test_queues.py index 08c0d0c4a..2010147d0 100644 --- a/tests/functional/wsgi/v1/test_queues.py +++ b/tests/functional/wsgi/v1/test_queues.py @@ -264,9 +264,10 @@ class TestQueueMisc(base.FunctionalTestBase): self.base_url = self.cfg.marconi.url self.client.set_base_url(self.base_url) - self.queue_url = self.base_url + '/{0}/queues/{1}' \ - .format(self.cfg.marconi.version, - uuid.uuid1()) + template = self.base_url + '/{0}/queues/{1}' + + self.queue_url = template.format(self.cfg.marconi.version, + uuid.uuid1()) def test_list_queues(self): """List Queues.""" @@ -274,8 +275,9 @@ class TestQueueMisc(base.FunctionalTestBase): self.client.put(self.queue_url) self.addCleanup(self.client.delete, self.queue_url) - result = self.client.get('/{0}/queues' - .format(self.cfg.marconi.version)) + url = '/{0}/queues'.format(self.cfg.marconi.version) + result = self.client.get(url) + self.assertEqual(result.status_code, 200) self.assertSchema(result.json(), 'queue_list') @@ -418,8 +420,8 @@ class TestQueueNonExisting(base.FunctionalTestBase): super(TestQueueNonExisting, self).setUp() self.base_url = '{0}/{1}'.format(self.cfg.marconi.url, self.cfg.marconi.version) - self.queue_url = self.base_url + \ - '/queues/0a5b1b85-4263-11e3-b034-28cfe91478b9' + self.queue_url = (self.base_url + + '/queues/0a5b1b85-4263-11e3-b034-28cfe91478b9') self.client.set_base_url(self.queue_url) self.header = helpers.create_marconi_headers(self.cfg) diff --git a/tests/unit/queues/transport/wsgi/test_v1_0.py b/tests/unit/queues/transport/wsgi/test_v1_0.py index f9b915b40..796699faa 100644 --- a/tests/unit/queues/transport/wsgi/test_v1_0.py +++ b/tests/unit/queues/transport/wsgi/test_v1_0.py @@ -18,9 +18,9 @@ from marconi.tests.queues.transport.wsgi import base from marconi.tests.queues.transport.wsgi import v1 -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- # Identical or just minor variations across versions -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- URL_PREFIX = '/v1' @@ -89,9 +89,9 @@ class TestPoolsSqlalchemy(v1.TestPoolsSqlalchemy): url_prefix = URL_PREFIX -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- # v1.0 only -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- class TestHealth(base.V1Base): diff --git a/tests/unit/queues/transport/wsgi/test_v1_1.py b/tests/unit/queues/transport/wsgi/test_v1_1.py index 8a4ade6a1..35f97f32c 100644 --- a/tests/unit/queues/transport/wsgi/test_v1_1.py +++ b/tests/unit/queues/transport/wsgi/test_v1_1.py @@ -17,9 +17,9 @@ import falcon from marconi.tests.queues.transport.wsgi import base from marconi.tests.queues.transport.wsgi import v1_1 -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- # Identical or just minor variations across versions -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- URL_PREFIX = '/v1.1' @@ -90,9 +90,9 @@ class TestPoolsSqlalchemy(v1_1.TestPoolsSqlalchemy): url_prefix = URL_PREFIX -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- # v1.1 only -#---------------------------------------------------------------------------- +# -------------------------------------------------------------------------- class TestPing(base.V1_1Base):