Merge "Consolidate constants to a module"

This commit is contained in:
Jenkins 2016-09-14 04:04:43 +00:00 committed by Gerrit Code Review
commit 0b0a95d967
18 changed files with 332 additions and 203 deletions

View File

@ -17,6 +17,7 @@ from zaqar.api.v2 import request as schema_validator
from zaqar.common.api import request
from zaqar.common.api import response
from zaqar.common import consts
from zaqar.common import errors
from zaqar.common import urls
@ -28,12 +29,12 @@ class Handler(object):
"""
_actions_mapping = {
'message_list': 'GET',
'message_get': 'GET',
'message_get_many': 'GET',
'message_post': 'POST',
'message_delete': 'DELETE',
'message_delete_many': 'DELETE'
consts.MESSAGE_LIST: 'GET',
consts.MESSAGE_GET: 'GET',
consts.MESSAGE_GET_MANY: 'GET',
consts.MESSAGE_POST: 'POST',
consts.MESSAGE_DELETE: 'DELETE',
consts.MESSAGE_DELETE_MANY: 'DELETE'
}
def __init__(self, storage, control, validate, defaults):
@ -54,7 +55,7 @@ class Handler(object):
def process_request(self, req, protocol):
# FIXME(vkmc): Control API version
if req._action == 'subscription_create':
if req._action == consts.SUBSCRIPTION_CREATE:
subscriber = req._body.get('subscriber')
if not subscriber:
# Default to the connected websocket as subscriber

View File

@ -14,6 +14,7 @@
# limitations under the License.
from zaqar.common.api import api
from zaqar.common import consts
class RequestSchema(api.Api):
@ -78,9 +79,9 @@ class RequestSchema(api.Api):
},
# Queues
'queue_list': {
consts.QUEUE_LIST: {
'properties': {
'action': {'enum': ['queue_list']},
'action': {'enum': [consts.QUEUE_LIST]},
'headers': {
'type': 'object',
'properties': headers,
@ -98,9 +99,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers']
},
'queue_create': {
consts.QUEUE_CREATE: {
'properties': {
'action': {'enum': ['queue_create']},
'action': {'enum': [consts.QUEUE_CREATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -116,9 +117,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'queue_delete': {
consts.QUEUE_DELETE: {
'properties': {
'action': {'enum': ['queue_delete']},
'action': {'enum': [consts.QUEUE_DELETE]},
'headers': {
'type': 'object',
'properties': headers,
@ -135,9 +136,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'queue_get': {
consts.QUEUE_GET: {
'properties': {
'action': {'enum': ['queue_get']},
'action': {'enum': [consts.QUEUE_GET]},
'headers': {
'type': 'object',
'properties': headers,
@ -154,9 +155,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'queue_get_stats': {
consts.QUEUE_GET_STATS: {
'properties': {
'action': {'enum': ['queue_get_stats']},
'action': {'enum': [consts.QUEUE_GET_STATS]},
'headers': {
'type': 'object',
'properties': headers,
@ -175,9 +176,9 @@ class RequestSchema(api.Api):
},
# Messages
'message_list': {
consts.MESSAGE_LIST: {
'properties': {
'action': {'enum': ['message_list']},
'action': {'enum': [consts.MESSAGE_LIST]},
'headers': {
'type': 'object',
'properties': headers,
@ -198,9 +199,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'message_get': {
consts.MESSAGE_GET: {
'properties': {
'action': {'enum': ['message_get']},
'action': {'enum': [consts.MESSAGE_GET]},
'headers': {
'type': 'object',
'properties': headers,
@ -218,9 +219,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'message_get_many': {
consts.MESSAGE_GET_MANY: {
'properties': {
'action': {'enum': ['message_get_many']},
'action': {'enum': [consts.MESSAGE_GET_MANY]},
'headers': {
'type': 'object',
'properties': headers,
@ -238,9 +239,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'message_post': {
consts.MESSAGE_POST: {
'properties': {
'action': {'enum': ['message_post']},
'action': {'enum': [consts.MESSAGE_POST]},
'headers': {
'type': 'object',
'properties': headers,
@ -258,9 +259,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'message_delete': {
consts.MESSAGE_DELETE: {
'properties': {
'action': {'enum': ['message_delete']},
'action': {'enum': [consts.MESSAGE_DELETE]},
'headers': {
'type': 'object',
'properties': headers,
@ -279,9 +280,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'message_delete_many': {
consts.MESSAGE_DELETE_MANY: {
'properties': {
'action': {'enum': ['message_delete_many']},
'action': {'enum': [consts.MESSAGE_DELETE_MANY]},
'headers': {
'type': 'object',
'properties': headers,
@ -301,9 +302,9 @@ class RequestSchema(api.Api):
},
# Claims
'claim_create': {
consts.CLAIM_CREATE: {
'properties': {
'action': {'enum': ['claim_create']},
'action': {'enum': [consts.CLAIM_CREATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -323,9 +324,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'claim_get': {
consts.CLAIM_GET: {
'properties': {
'action': {'enum': ['claim_get']},
'action': {'enum': [consts.CLAIM_GET]},
'headers': {
'type': 'object',
'properties': headers,
@ -343,9 +344,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'claim_update': {
consts.CLAIM_UPDATE: {
'properties': {
'action': {'enum': ['claim_update']},
'action': {'enum': [consts.CLAIM_UPDATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -364,9 +365,9 @@ class RequestSchema(api.Api):
'required': ['action', 'headers', 'body']
},
'claim_delete': {
consts.CLAIM_DELETE: {
'properties': {
'action': {'enum': ['claim_delete']},
'action': {'enum': [consts.CLAIM_DELETE]},
'headers': {
'type': 'object',
'properties': headers,

View File

@ -14,6 +14,7 @@
# limitations under the License.
from zaqar.common.api import api
from zaqar.common import consts
class ResponseSchema(api.Api):
@ -59,7 +60,7 @@ class ResponseSchema(api.Api):
}
self.schema = {
'queue_list': {
consts.QUEUE_LIST: {
'type': 'object',
'properties': {
'links': {
@ -110,7 +111,7 @@ class ResponseSchema(api.Api):
'required': ['links', 'queues'],
'additionalProperties': False,
},
'queue_stats': {
consts.QUEUE_GET_STATS: {
'type': 'object',
'properties': {
'messages': {
@ -144,7 +145,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'pool_list': {
consts.POOL_LIST: {
'type': 'object',
'properties': {
'links': {
@ -198,7 +199,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'message_list': {
consts.MESSAGE_LIST: {
'type': 'object',
'properties': {
'links': {
@ -227,14 +228,14 @@ class ResponseSchema(api.Api):
}
}
},
'message_get_many': {
consts.MESSAGE_GET_MANY: {
"type": "array",
"items": message,
"minItems": 1,
"maxItems": self.limits.max_messages_per_page
},
'claim_create': {
consts.CLAIM_CREATE: {
"type": "array",
"items": {
"type": "object",
@ -257,7 +258,7 @@ class ResponseSchema(api.Api):
"maxItems": self.limits.max_messages_per_page
},
'claim_get': {
consts.CLAIM_GET: {
'type': 'object',
'properties': {
'age': age,

View File

@ -14,6 +14,7 @@
# limitations under the License.
from zaqar.api.v1 import request as v1
from zaqar.common import consts
class RequestSchema(v1.RequestSchema):
@ -24,9 +25,9 @@ class RequestSchema(v1.RequestSchema):
schema.update({
# Pools
'pool_list': {
consts.POOL_LIST: {
'properties': {
'action': {'enum': ['pool_list']},
'action': {'enum': [consts.POOL_LIST]},
'headers': {
'type': 'object',
'properties': headers,
@ -46,9 +47,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'pool_create': {
consts.POOL_CREATE: {
'properties': {
'action': {'enum': ['pool_create']},
'action': {'enum': [consts.POOL_CREATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -69,9 +70,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'pool_update': {
consts.POOL_UPDATE: {
'properties': {
'action': {'enum': ['pool_update']},
'action': {'enum': [consts.POOL_UPDATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -92,9 +93,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'pool_get': {
consts.POOL_GET: {
'properties': {
'action': {'enum': ['pool_get']},
'action': {'enum': [consts.POOL_GET]},
'headers': {
'type': 'object',
'properties': headers,
@ -113,9 +114,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'pool_delete': {
consts.POOL_DELETE: {
'properties': {
'action': {'enum': ['pool_delete']},
'action': {'enum': [consts.POOL_DELETE]},
'headers': {
'type': 'object',
'properties': headers,
@ -134,9 +135,9 @@ class RequestSchema(v1.RequestSchema):
},
# Flavors
'flavor_list': {
consts.FLAVOR_LIST: {
'properties': {
'action': {'enum': ['flavor_list']},
'action': {'enum': [consts.FLAVOR_LIST]},
'headers': {
'type': 'object',
'properties': headers,
@ -156,9 +157,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'flavor_create': {
consts.FLAVOR_CREATE: {
'properties': {
'action': {'enum': ['flavor_create']},
'action': {'enum': [consts.FLAVOR_CREATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -178,9 +179,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'flavor_update': {
consts.FLAVOR_UPDATE: {
'properties': {
'action': {'enum': ['flavor_update']},
'action': {'enum': [consts.FLAVOR_UPDATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -200,9 +201,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'flavor_get': {
consts.FLAVOR_GET: {
'properties': {
'action': {'enum': ['flavor_get']},
'action': {'enum': [consts.FLAVOR_GET]},
'headers': {
'type': 'object',
'properties': headers,
@ -221,9 +222,9 @@ class RequestSchema(v1.RequestSchema):
'admin': True,
},
'flavor_delete': {
consts.FLAVOR_DELETE: {
'properties': {
'action': {'enum': ['flavor_delete']},
'action': {'enum': [consts.FLAVOR_DELETE]},
'headers': {
'type': 'object',
'properties': headers,

View File

@ -14,6 +14,7 @@
# limitations under the License.
from zaqar.common.api import api
from zaqar.common import consts
class ResponseSchema(api.Api):
@ -84,7 +85,7 @@ class ResponseSchema(api.Api):
}
self.schema = {
'message_get_many': {
consts.MESSAGE_GET_MANY: {
'type': 'object',
'properties': {
'messages': {
@ -98,7 +99,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False,
},
'queue_list': {
consts.QUEUE_LIST: {
'type': 'object',
'properties': {
'links': {
@ -151,7 +152,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False,
},
'queue_stats': {
consts.QUEUE_GET_STATS: {
'type': 'object',
'properties': {
'messages': {
@ -185,7 +186,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'pool_list': {
consts.POOL_LIST: {
'type': 'object',
'properties': {
'links': {
@ -242,7 +243,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'message_list': {
consts.MESSAGE_LIST: {
'type': 'object',
'properties': {
'links': {
@ -271,7 +272,7 @@ class ResponseSchema(api.Api):
}
}
},
'pool_detail': {
consts.POOL_GET_DETAIL: {
'type': 'object',
'properties': {
'name': {
@ -301,7 +302,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'claim_create': {
consts.CLAIM_CREATE: {
'type': 'object',
'properties': {
'messages': {
@ -334,7 +335,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'claim_get': {
consts.CLAIM_GET: {
'type': 'object',
'properties': {
'age': age,
@ -378,7 +379,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'flavor_list': {
consts.FLAVOR_LIST: {
'type': 'object',
'properties': {
'links': {

View File

@ -14,6 +14,7 @@
# limitations under the License.
from zaqar.api.v1_1 import request as v1_1
from zaqar.common import consts
class RequestSchema(v1_1.RequestSchema):
@ -24,9 +25,9 @@ class RequestSchema(v1_1.RequestSchema):
schema.update({
# Subscriptions
'subscription_list': {
consts.SUBSCRIPTION_LIST: {
'properties': {
'action': {'enum': ['subscription_list']},
'action': {'enum': [consts.SUBSCRIPTION_LIST]},
'headers': {
'type': 'object',
'properties': headers,
@ -43,9 +44,9 @@ class RequestSchema(v1_1.RequestSchema):
'required': ['action', 'headers', 'body']
},
'subscription_create': {
consts.SUBSCRIPTION_CREATE: {
'properties': {
'action': {'enum': ['subscription_create']},
'action': {'enum': [consts.SUBSCRIPTION_CREATE]},
'headers': {
'type': 'object',
'properties': headers,
@ -64,9 +65,9 @@ class RequestSchema(v1_1.RequestSchema):
'required': ['action', 'headers', 'body']
},
'subscription_delete': {
consts.SUBSCRIPTION_DELETE: {
'properties': {
'action': {'enum': ['subscription_delete']},
'action': {'enum': [consts.SUBSCRIPTION_DELETE]},
'headers': {
'type': 'object',
'properties': headers,
@ -84,9 +85,9 @@ class RequestSchema(v1_1.RequestSchema):
'required': ['action', 'headers', 'body']
},
'subscription_get': {
consts.SUBSCRIPTION_GET: {
'properties': {
'action': {'enum': ['subscription_get']},
'action': {'enum': [consts.SUBSCRIPTION_GET]},
'headers': {
'type': 'object',
'properties': headers,

View File

@ -14,6 +14,7 @@
# limitations under the License.
from zaqar.common.api import api
from zaqar.common import consts
class ResponseSchema(api.Api):
@ -84,7 +85,7 @@ class ResponseSchema(api.Api):
}
self.schema = {
'message_get_many': {
consts.MESSAGE_GET_MANY: {
'type': 'object',
'properties': {
'messages': {
@ -98,7 +99,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False,
},
'queue_list': {
consts.QUEUE_LIST: {
'type': 'object',
'properties': {
'links': {
@ -151,7 +152,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False,
},
'queue_stats': {
consts.QUEUE_GET_STATS: {
'type': 'object',
'properties': {
'messages': {
@ -185,7 +186,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'pool_list': {
consts.POOL_LIST: {
'type': 'object',
'properties': {
'links': {
@ -242,7 +243,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'message_list': {
consts.MESSAGE_LIST: {
'type': 'object',
'properties': {
'links': {
@ -271,7 +272,7 @@ class ResponseSchema(api.Api):
}
}
},
'pool_detail': {
consts.POOL_GET_DETAIL: {
'type': 'object',
'properties': {
'name': {
@ -301,7 +302,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'claim_create': {
consts.CLAIM_CREATE: {
'type': 'object',
'properties': {
'messages': {
@ -334,7 +335,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'claim_get': {
consts.CLAIM_GET: {
'type': 'object',
'properties': {
'age': age,
@ -378,7 +379,7 @@ class ResponseSchema(api.Api):
'additionalProperties': False
},
'flavor_list': {
consts.FLAVOR_LIST: {
'type': 'object',
'properties': {
'links': {

View File

@ -19,6 +19,7 @@ from stevedore import driver
from zaqar.api import handler
from zaqar.common import cache as oslo_cache
from zaqar.common import configs
from zaqar.common import consts
from zaqar.common import decorators
from zaqar.common import errors
from zaqar.storage import pipeline
@ -90,8 +91,7 @@ class Bootstrap(object):
transport_name = self.driver_conf.transport
LOG.debug(u'Loading transport driver: %s', transport_name)
# FIXME(vkmc): Find a better way to init args
if transport_name == 'websocket':
if transport_name == consts.TRANSPORT_WEBSOCKET:
args = [self.conf, self.api, self.cache]
else:
args = [

115
zaqar/common/consts.py Normal file
View File

@ -0,0 +1,115 @@
# 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.
TRANSPORT_DRIVERS = (
TRANSPORT_WSGI, TRANSPORT_WEBSOCKET,
) = (
'wsgi', 'websocket',
)
MESSAGE_STORE = (
MSG_STORE_MONGODB,
) = (
'mongodb',
)
MANAGEMENT_STORE = (
MGMT_STORE_MONGODB,
) = (
'mongodb',
)
SUBSCRIPTION_OPS = (
SUBSCRIPTION_CREATE,
SUBSCRIPTION_LIST,
SUBSCRIPTION_GET,
SUBSCRIPTION_DELETE,
) = (
'subscription_create',
'subscription_list',
'subscription_get',
'subscription_delete',
)
MESSAGE_OPS = (
MESSAGE_POST,
MESSAGE_LIST,
MESSAGE_GET,
MESSAGE_GET_MANY,
MESSAGE_DELETE,
MESSAGE_DELETE_MANY,
) = (
'message_post',
'message_list',
'message_get',
'message_get_many',
'message_delete',
'message_delete_many',
)
QUEUE_OPS = (
QUEUE_CREATE,
QUEUE_LIST,
QUEUE_GET,
QUEUE_DELETE,
QUEUE_GET_STATS,
) = (
'queue_create',
'queue_list',
'queue_get',
'queue_delete',
'queue_get_stats',
)
CLAIM_OPS = (
CLAIM_CREATE,
CLAIM_GET,
CLAIM_UPDATE,
CLAIM_DELETE,
) = (
'claim_create',
'claim_get',
'claim_update',
'claim_delete',
)
POOL_OPS = (
POOL_CREATE,
POOL_LIST,
POOL_GET,
POOL_GET_DETAIL,
POOL_UPDATE,
POOL_DELETE,
) = (
'pool_create',
'pool_list',
'pool_get',
'pool_get_detail',
'pool_update',
'pool_delete',
)
FLAVOR_OPS = (
FLAVOR_CREATE,
FLAVOR_LIST,
FLAVOR_GET,
FLAVOR_UPDATE,
FLAVOR_DELETE,
) = (
'flavor_create',
'flavor_list',
'flavor_get',
'flavor_update',
'flavor_delete',
)

View File

@ -20,6 +20,7 @@ import uuid
import ddt
from zaqar.common import consts
from zaqar.tests.functional import base
from zaqar.tests.functional import helpers
@ -126,7 +127,7 @@ class TestMessages(base.V1_1FunctionalTestBase):
self.assertEqual(200, result.status_code)
# Verify that the response json schema matches the expected schema
self.assertSchema(result.json(), 'message_get_many')
self.assertSchema(result.json(), consts.MESSAGE_GET_MANY)
self.skipTest('Bug #1273335 - Get set of messages returns wrong hrefs '
'(happens randomly)')

View File

@ -84,7 +84,7 @@ class TestPools(base.V1_1FunctionalTestBase):
# Test existence
result = self.client.get('/'+pool_name+'?detailed=true')
self.assertEqual(200, result.status_code)
self.assertSchema(result.json(), 'pool_detail')
self.assertSchema(result.json(), 'pool_get_detail')
@ddt.data(
{

View File

@ -16,16 +16,17 @@
from zaqar.common.api import request
from zaqar.common import consts
from zaqar.tests import base
class TestRequest(base.TestBase):
def test_request(self):
action = 'message_post'
action = consts.MESSAGE_POST
data = 'body'
env = {'foo': 'bar'}
req = request.Request(action=action, body=data, env=env)
self.assertEqual({'foo': 'bar'}, req._env)
self.assertEqual('body', req._body)
self.assertEqual('message_post', req._action)
self.assertEqual(consts.MESSAGE_POST, req._action)

View File

@ -20,6 +20,7 @@ import ddt
from keystonemiddleware import auth_token
import mock
from zaqar.common import consts
from zaqar.common import urls
from zaqar.tests.unit.transport.websocket import base
from zaqar.tests.unit.transport.websocket import utils as test_utils
@ -68,7 +69,7 @@ class AuthTest(base.V2Base):
self.assertEqual('200 OK', responses[0])
# Check that the env is available to future requests
req = json.dumps({'action': 'message_list',
req = json.dumps({'action': consts.MESSAGE_LIST,
'body': {'queue_name': 'myqueue'},
'headers': self.headers})
process_request = mock.patch.object(self.protocol._handler,
@ -89,7 +90,7 @@ class AuthTest(base.V2Base):
msg_mock = msg_mock.start()
self.protocol.onMessage(req, False)
req = test_utils.create_request("queue_list", {}, self.headers)
req = test_utils.create_request(consts.QUEUE_LIST, {}, self.headers)
self.protocol.onMessage(req, False)
self.assertEqual(1, msg_mock.call_count)
@ -198,7 +199,7 @@ class AuthTest(base.V2Base):
'URL-Methods': ['GET'],
'URL-Paths': ['/v2/queues/myqueue/messages']
})
req = json.dumps({'action': 'message_list',
req = json.dumps({'action': consts.MESSAGE_LIST,
'body': {'queue_name': 'myqueue'},
'headers': headers})
self.protocol.onMessage(req, False)
@ -222,7 +223,7 @@ class AuthTest(base.V2Base):
'URL-Methods': ['GET'],
'URL-Paths': ['/v2/queues/otherqueue/messages']
})
req = json.dumps({'action': 'message_list',
req = json.dumps({'action': consts.MESSAGE_LIST,
'body': {'queue_name': 'otherqueue'},
'headers': headers})
self.protocol.onMessage(req, False)
@ -246,7 +247,7 @@ class AuthTest(base.V2Base):
'URL-Methods': ['GET'],
'URL-Paths': ['/v2/queues/myqueue/messages']
})
req = json.dumps({'action': 'message_delete',
req = json.dumps({'action': consts.MESSAGE_DELETE,
'body': {'queue_name': 'myqueue',
'message_id': '123'},
'headers': headers})

View File

@ -19,6 +19,7 @@ import ddt
import mock
from oslo_utils import timeutils
from zaqar.common import consts
from zaqar.tests.unit.transport.websocket import base
from zaqar.tests.unit.transport.websocket import utils as test_utils
@ -39,7 +40,7 @@ class ClaimsBaseTest(base.V1_1Base):
'X-Project-ID': self.project_id
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "skittle"}
req = test_utils.create_request(action, body, self.headers)
@ -48,7 +49,7 @@ class ClaimsBaseTest(base.V1_1Base):
resp = json.loads(msg_mock.call_args[0][0])
self.assertEqual(201, resp['headers']['status'])
action = "message_post"
action = consts.MESSAGE_POST
body = {"queue_name": "skittle",
"messages": [
{'body': 239, 'ttl': 300},
@ -74,7 +75,7 @@ class ClaimsBaseTest(base.V1_1Base):
def tearDown(self):
super(ClaimsBaseTest, self).tearDown()
action = 'queue_delete'
action = consts.QUEUE_DELETE
body = {'queue_name': 'skittle'}
send_mock = mock.Mock()
@ -88,7 +89,7 @@ class ClaimsBaseTest(base.V1_1Base):
@ddt.data('[', '[]', '.', '"fail"')
def test_bad_claim(self, doc):
action = "claim_create"
action = consts.CLAIM_CREATE
body = doc
send_mock = mock.Mock()
@ -99,7 +100,7 @@ class ClaimsBaseTest(base.V1_1Base):
resp = json.loads(send_mock.call_args[0][0])
self.assertEqual(400, resp['headers']['status'])
action = "claim_update"
action = consts.CLAIM_UPDATE
body = doc
req = test_utils.create_request(action, body, self.headers)
@ -108,7 +109,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(400, resp['headers']['status'])
def test_exceeded_claim(self):
action = "claim_create"
action = consts.CLAIM_CREATE
body = {"queue_name": "skittle",
"ttl": 100,
"grace": 60,
@ -125,7 +126,7 @@ class ClaimsBaseTest(base.V1_1Base):
@ddt.data((-1, -1), (59, 60), (60, 59), (60, 43201), (43201, 60))
def test_unacceptable_ttl_or_grace(self, ttl_grace):
ttl, grace = ttl_grace
action = "claim_create"
action = consts.CLAIM_CREATE
body = {"queue_name": "skittle",
"ttl": ttl,
"grace": grace}
@ -142,7 +143,7 @@ class ClaimsBaseTest(base.V1_1Base):
def test_unacceptable_new_ttl(self, ttl):
claim = self._get_a_claim()
action = "claim_update"
action = consts.CLAIM_UPDATE
body = {"queue_name": "skittle",
"claim_id": claim['body']['claim_id'],
"ttl": ttl}
@ -156,7 +157,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(400, resp['headers']['status'])
def test_default_ttl_and_grace(self):
action = "claim_create"
action = consts.CLAIM_CREATE
body = {"queue_name": "skittle"}
send_mock = mock.Mock()
@ -167,7 +168,7 @@ class ClaimsBaseTest(base.V1_1Base):
resp = json.loads(send_mock.call_args[0][0])
self.assertEqual(201, resp['headers']['status'])
action = "claim_get"
action = consts.CLAIM_GET
body = {"queue_name": "skittle",
"claim_id": resp['body']['claim_id']}
@ -180,7 +181,7 @@ class ClaimsBaseTest(base.V1_1Base):
def test_lifecycle(self):
# First, claim some messages
action = "claim_create"
action = consts.CLAIM_CREATE
body = {"queue_name": "skittle",
"ttl": 100,
"grace": 60}
@ -206,7 +207,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(204, resp['headers']['status'])
# Listing messages, by default, won't include claimed, will echo
action = "message_list"
action = consts.MESSAGE_LIST
body = {"queue_name": "skittle",
"echo": True}
@ -271,7 +272,7 @@ class ClaimsBaseTest(base.V1_1Base):
message_id_2 = resp['body']['messages'][1]['id']
# Try to delete the message without submitting a claim_id
action = "message_delete"
action = consts.MESSAGE_DELETE
body = {"queue_name": "skittle",
"message_id": message_id_1}
@ -296,7 +297,7 @@ class ClaimsBaseTest(base.V1_1Base):
'X-Project-ID': 'someproject'
}
action = "message_get"
action = consts.MESSAGE_GET
body = {"queue_name": "skittle",
"message_id": message_id_2}
req = test_utils.create_request(action, body, headers)
@ -305,7 +306,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(404, resp['headers']['status'])
# Get the message
action = "message_get"
action = consts.MESSAGE_GET
body = {"queue_name": "skittle",
"message_id": message_id_2}
req = test_utils.create_request(action, body, self.headers)
@ -315,7 +316,7 @@ class ClaimsBaseTest(base.V1_1Base):
# Update the claim
creation = timeutils.utcnow()
action = "claim_update"
action = consts.CLAIM_UPDATE
body = {"queue_name": "skittle",
"ttl": 60,
"grace": 60,
@ -326,7 +327,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(204, resp['headers']['status'])
# Get the claimed messages (again)
action = "claim_get"
action = consts.CLAIM_GET
body = {"queue_name": "skittle",
"claim_id": claim_id}
req = test_utils.create_request(action, body, self.headers)
@ -342,7 +343,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertTrue(estimated_age > resp['body']['age'])
# Delete the claim
action = "claim_delete"
action = consts.CLAIM_DELETE
body = {"queue_name": "skittle",
"claim_id": claim_id}
req = test_utils.create_request(action, body, self.headers)
@ -351,7 +352,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(204, resp['headers']['status'])
# Try to delete a message with an invalid claim ID
action = "message_delete"
action = consts.MESSAGE_DELETE
body = {"queue_name": "skittle",
"message_id": message_id_3,
"claim_id": claim_id}
@ -362,7 +363,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(400, resp['headers']['status'])
# Make sure it wasn't deleted!
action = "message_get"
action = consts.MESSAGE_GET
body = {"queue_name": "skittle",
"message_id": message_id_2}
req = test_utils.create_request(action, body, self.headers)
@ -371,7 +372,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(200, resp['headers']['status'])
# Try to get a claim that doesn't exist
action = "claim_get"
action = consts.CLAIM_GET
body = {"queue_name": "skittle",
"claim_id": claim_id}
req = test_utils.create_request(action, body, self.headers)
@ -380,7 +381,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(404, resp['headers']['status'])
# Try to update a claim that doesn't exist
action = "claim_update"
action = consts.CLAIM_UPDATE
body = {"queue_name": "skittle",
"ttl": 60,
"grace": 60,
@ -391,7 +392,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(404, resp['headers']['status'])
def test_post_claim_nonexistent_queue(self):
action = "claim_create"
action = consts.CLAIM_CREATE
body = {"queue_name": "nonexistent",
"ttl": 100,
"grace": 60}
@ -405,7 +406,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(204, resp['headers']['status'])
def test_get_claim_nonexistent_queue(self):
action = "claim_get"
action = consts.CLAIM_GET
body = {"queue_name": "nonexistent",
"claim_id": "aaabbbba"}
@ -418,7 +419,7 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(404, resp['headers']['status'])
def _get_a_claim(self):
action = "claim_create"
action = consts.CLAIM_CREATE
body = {"queue_name": "skittle",
"ttl": 100,
"grace": 60}

View File

@ -23,6 +23,7 @@ from oslo_utils import timeutils
import six
from testtools import matchers
from zaqar.common import consts
from zaqar.tests.unit.transport.websocket import base
from zaqar.tests.unit.transport.websocket import utils as test_utils
from zaqar.transport import validation
@ -45,9 +46,9 @@ class MessagesBaseTest(base.V2Base):
'X-Project-ID': self.project_id
}
action = "queue_create"
body = {"queue_name": "kitkat"}
req = test_utils.create_request(action, body, self.headers)
req = test_utils.create_request(consts.QUEUE_CREATE,
body, self.headers)
with mock.patch.object(self.protocol, 'sendMessage') as msg_mock:
self.protocol.onMessage(req, False)
@ -56,13 +57,13 @@ class MessagesBaseTest(base.V2Base):
def tearDown(self):
super(MessagesBaseTest, self).tearDown()
action = "queue_delete"
body = {"queue_name": "kitkat"}
send_mock = mock.Mock()
self.protocol.sendMessage = send_mock
req = test_utils.create_request(action, body, self.headers)
req = test_utils.create_request(consts.QUEUE_DELETE,
body, self.headers)
self.protocol.onMessage(req, False)
@ -70,7 +71,6 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(204, resp['headers']['status'])
def _test_post(self, sample_messages, in_binary=False):
action = "message_post"
body = {"queue_name": "kitkat",
"messages": sample_messages}
@ -79,7 +79,7 @@ class MessagesBaseTest(base.V2Base):
dumps, loads, create_req = test_utils.get_pack_tools(binary=in_binary)
req = create_req(action, body, self.headers)
req = create_req(consts.MESSAGE_POST, body, self.headers)
self.protocol.onMessage(req, in_binary)
@ -100,7 +100,7 @@ class MessagesBaseTest(base.V2Base):
headers = self.headers.copy()
headers['X-Project-ID'] = '777777'
# Wrong project ID
action = "message_get"
action = consts.MESSAGE_GET
body = {"queue_name": "kitkat",
"message_id": msg_id}
@ -131,7 +131,7 @@ class MessagesBaseTest(base.V2Base):
matchers.GreaterThan(-1))
# Test bulk GET
action = "message_get_many"
action = consts.MESSAGE_GET_MANY
body = {"queue_name": "kitkat",
"message_ids": self.msg_ids}
req = create_req(action, body, self.headers)
@ -153,7 +153,7 @@ class MessagesBaseTest(base.V2Base):
# Bulk GET restriction
get_msg_ids = msg_id * 21
action = "message_get_many"
action = consts.MESSAGE_GET_MANY
body = {"queue_name": "kitkat",
"message_ids": get_msg_ids}
@ -175,7 +175,7 @@ class MessagesBaseTest(base.V2Base):
# Bulk deletion restriction
del_msg_ids = msg_id * 22
action = "message_get_many"
action = consts.MESSAGE_GET_MANY
body = {"queue_name": "kitkat",
"message_ids": del_msg_ids}
req = test_utils.create_request(action, body, self.headers)
@ -205,7 +205,7 @@ class MessagesBaseTest(base.V2Base):
messages = [{'body': 239},
{'body': {'key': 'value'}, 'ttl': 200}]
action = "message_post"
action = consts.MESSAGE_POST
body = {"queue_name": "kitkat",
"messages": messages}
req = test_utils.create_request(action, body, self.headers)
@ -219,7 +219,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(201, resp['headers']['status'])
msg_id = resp['body']['message_ids'][0]
action = "message_get"
action = consts.MESSAGE_GET
body = {"queue_name": "kitkat", "message_id": msg_id}
req = test_utils.create_request(action, body, self.headers)
@ -264,7 +264,7 @@ class MessagesBaseTest(base.V2Base):
{'body': {'key': 'value'}, 'ttl': '200'},
]
action = "message_post"
action = consts.MESSAGE_POST
body = {"queue_name": "kitkat",
"messages": sample_messages}
@ -285,7 +285,7 @@ class MessagesBaseTest(base.V2Base):
{'ttl': 200},
]
action = "message_post"
action = consts.MESSAGE_POST
body = {"queue_name": "kitkat",
"messages": sample_messages}
@ -301,7 +301,7 @@ class MessagesBaseTest(base.V2Base):
'Bad request. Missing "body" field.', resp['body']['exception'])
def test_get_from_missing_queue(self):
action = "message_list"
action = consts.MESSAGE_LIST
body = {"queue_name": "anothernonexistent"}
req = test_utils.create_request(action, body, self.headers)
@ -316,7 +316,7 @@ class MessagesBaseTest(base.V2Base):
@ddt.data('', '0xdeadbeef', '550893e0-2b6e-11e3-835a-5cf9dd72369')
def test_bad_client_id(self, text_id):
action = "message_post"
action = consts.MESSAGE_POST
body = {
"queue_name": "kinder",
"messages": [{"ttl": 60,
@ -337,7 +337,7 @@ class MessagesBaseTest(base.V2Base):
resp = json.loads(send_mock.call_args[0][0])
self.assertEqual(400, resp['headers']['status'])
action = "message_get"
action = consts.MESSAGE_GET
body = {
"queue_name": "kinder",
"limit": 3,
@ -352,7 +352,7 @@ class MessagesBaseTest(base.V2Base):
@ddt.data(None, '[', '[]', '{}', '.')
def test_post_bad_message(self, document):
action = "message_post"
action = consts.MESSAGE_POST
body = {
"queue_name": "kinder",
"messages": document
@ -370,7 +370,7 @@ class MessagesBaseTest(base.V2Base):
@ddt.data(-1, 59, 1209601)
def test_unacceptable_ttl(self, ttl):
action = "message_post"
action = consts.MESSAGE_POST
body = {"queue_name": "kinder",
"messages": [{"ttl": ttl, "body": ""}]}
@ -387,7 +387,7 @@ class MessagesBaseTest(base.V2Base):
def test_exceeded_message_posting(self):
# Total (raw request) size
document = [{'body': "some body", 'ttl': 100}] * 8000
action = "message_post"
action = consts.MESSAGE_POST
body = {
"queue_name": "kinder",
"messages": document
@ -406,7 +406,7 @@ class MessagesBaseTest(base.V2Base):
@ddt.data('{"overflow": 9223372036854775808}',
'{"underflow": -9223372036854775809}')
def test_unsupported_json(self, document):
action = "message_post"
action = consts.MESSAGE_POST
body = {
"queue_name": "fizz",
"messages": document
@ -426,7 +426,7 @@ class MessagesBaseTest(base.V2Base):
resp = self._post_messages("tofi")
msg_id = resp['body']['message_ids'][0]
action = "message_get"
action = consts.MESSAGE_GET
body = {"queue_name": "tofi",
"message_id": msg_id}
@ -441,7 +441,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(200, resp['headers']['status'])
# Delete queue
action = "message_delete"
action = consts.MESSAGE_DELETE
req = test_utils.create_request(action, body, self.headers)
self.protocol.onMessage(req, False)
@ -450,7 +450,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(204, resp['headers']['status'])
# Get non existent queue
action = "message_get"
action = consts.MESSAGE_GET
req = test_utils.create_request(action, body, self.headers)
self.protocol.onMessage(req, False)
@ -458,7 +458,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(404, resp['headers']['status'])
# Safe to delete non-existing ones
action = "message_delete"
action = consts.MESSAGE_DELETE
req = test_utils.create_request(action, body, self.headers)
self.protocol.onMessage(req, False)
@ -469,7 +469,7 @@ class MessagesBaseTest(base.V2Base):
resp = self._post_messages("nerds", repeat=5)
msg_ids = resp['body']['message_ids']
action = "message_delete_many"
action = consts.MESSAGE_DELETE_MANY
body = {"queue_name": "nerds",
"message_ids": msg_ids}
@ -483,7 +483,7 @@ class MessagesBaseTest(base.V2Base):
resp = json.loads(send_mock.call_args[0][0])
self.assertEqual(204, resp['headers']['status'])
action = "message_get"
action = consts.MESSAGE_GET
req = test_utils.create_request(action, body, self.headers)
self.protocol.onMessage(req, False)
@ -492,7 +492,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(400, resp['headers']['status'])
# Safe to delete non-existing ones
action = "message_delete_many"
action = consts.MESSAGE_DELETE_MANY
req = test_utils.create_request(action, body, self.headers)
self.protocol.onMessage(req, False)
@ -501,7 +501,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(204, resp['headers']['status'])
# Even after the queue is gone
action = "queue_delete"
action = consts.QUEUE_DELETE
body = {"queue_name": "nerds"}
req = test_utils.create_request(action, body, self.headers)
self.protocol.onMessage(req, False)
@ -509,7 +509,7 @@ class MessagesBaseTest(base.V2Base):
resp = json.loads(send_mock.call_args[0][0])
self.assertEqual(204, resp['headers']['status'])
action = "message_delete_many"
action = consts.MESSAGE_DELETE_MANY
body = {"queue_name": "nerds",
"message_ids": msg_ids}
req = test_utils.create_request(action, body, self.headers)
@ -521,7 +521,7 @@ class MessagesBaseTest(base.V2Base):
def test_pop_delete(self):
self._post_messages("kitkat", repeat=5)
action = "message_delete_many"
action = consts.MESSAGE_DELETE_MANY
body = {"queue_name": "kitkat",
"pop_limit": 2}
@ -539,7 +539,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(239, resp['body']['messages'][1]['body'])
def test_get_nonexistent_message_404s(self):
action = "message_get"
action = consts.MESSAGE_GET
body = {"queue_name": "notthere",
"message_id": "a"}
@ -553,7 +553,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(404, resp['headers']['status'])
def test_get_multiple_invalid_messages_404s(self):
action = "message_get_many"
action = consts.MESSAGE_GET_MANY
body = {"queue_name": "notnotthere",
"message_ids": ["a", "b", "c"]}
@ -567,7 +567,7 @@ class MessagesBaseTest(base.V2Base):
self.assertEqual(200, resp['headers']['status'])
def test_delete_multiple_invalid_messages_204s(self):
action = "message_delete"
action = consts.MESSAGE_DELETE
body = {"queue_name": "yetanothernotthere",
"message_ids": ["a", "b", "c"]}
@ -584,7 +584,7 @@ class MessagesBaseTest(base.V2Base):
def _post_messages(self, queue_name, repeat=1):
messages = [{'body': 239, 'ttl': 300}] * repeat
action = "message_post"
action = consts.MESSAGE_POST
body = {"queue_name": queue_name,
"messages": messages}

View File

@ -18,6 +18,7 @@ import uuid
import ddt
import mock
from zaqar.common import consts
from zaqar.storage import errors as storage_errors
from zaqar import tests as testing
from zaqar.tests.unit.transport.websocket import base
@ -34,7 +35,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol = self.transport.factory()
def test_empty_project_id(self):
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "kitkat",
"metadata": {
"key": {
@ -56,7 +57,7 @@ class QueueLifecycleBaseTest(base.V2Base):
@ddt.data('480924', 'foo')
def test_basics_thoroughly(self, project_id):
# Stats are empty - queue not created yet
action = "queue_get_stats"
action = consts.QUEUE_GET_STATS
body = {"queue_name": "gummybears"}
headers = {
'Client-ID': str(uuid.uuid4()),
@ -77,7 +78,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Create
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "gummybears",
"metadata": {
"key": {
@ -96,7 +97,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Fetch metadata
action = "queue_get"
action = consts.QUEUE_GET
body = {"queue_name": "gummybears"}
meta = {"messages": {"ttl": 600},
"key": {
@ -114,7 +115,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Stats empty queue
action = "queue_get_stats"
action = consts.QUEUE_GET_STATS
body = {"queue_name": "gummybears"}
req = test_utils.create_request(action, body, headers)
@ -126,7 +127,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Delete
action = "queue_delete"
action = consts.QUEUE_DELETE
body = {"queue_name": "gummybears"}
req = test_utils.create_request(action, body, headers)
@ -138,7 +139,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Get non-existent stats
action = "queue_get_stats"
action = consts.QUEUE_GET_STATS
body = {"queue_name": "gummybears"}
req = test_utils.create_request(action, body, headers)
@ -154,7 +155,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project'
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": 'marsbar',
"metadata": {
"key": {
@ -196,7 +197,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project' * 30
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": 'poptart'}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -230,7 +231,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project' * 30
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": test_params[0]}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -256,7 +257,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project'
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "fizbat"}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -285,7 +286,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project' * 30
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "fizbat",
"metadata": meta}
@ -307,7 +308,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project'
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "buttertoffee",
"metadata": {"messages": {"ttl": 600},
"padding": "x"}
@ -334,7 +335,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project'
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "peppermint",
"metadata": {"messages": {"ttl": 600},
"padding": "x"}
@ -362,7 +363,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project'
}
action = "queue_create"
action = consts.QUEUE_CREATE
body = {"queue_name": "bonobon"}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -393,7 +394,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Get
action = "queue_get"
action = consts.QUEUE_GET
body = {"queue_name": "bonobon"}
req = test_utils.create_request(action, body, headers)
@ -407,7 +408,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Update
action = "queue_create"
action = consts.QUEUE_CREATE
meta2 = {"messages": {"ttl": 100}, "padding": "y"}
body["metadata"] = meta2
@ -421,7 +422,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# Get again
action = "queue_get"
action = consts.QUEUE_GET
body = {"queue_name": "bonobon"}
req = test_utils.create_request(action, body, headers)
@ -454,7 +455,7 @@ class QueueLifecycleBaseTest(base.V2Base):
alt_project_id = str(arbitrary_number + 1)
# List empty
action = "queue_list"
action = consts.QUEUE_LIST
body = {}
req = test_utils.create_request(action, body, headers)
@ -483,7 +484,7 @@ class QueueLifecycleBaseTest(base.V2Base):
altheaders = {'Client-ID': client_id}
if project_id is not None:
altheaders['X-Project-ID'] = project_id
action = 'queue_create'
action = consts.QUEUE_CREATE
body['queue_name'] = queue_name
body['metadata'] = metadata
@ -537,7 +538,7 @@ class QueueLifecycleBaseTest(base.V2Base):
sender.side_effect = validator
self.protocol.onMessage(req, False)
action = "queue_get"
action = consts.QUEUE_GET
body = {"queue_name": "q1"}
req = test_utils.create_request(action, body, headers)
@ -550,7 +551,7 @@ class QueueLifecycleBaseTest(base.V2Base):
self.protocol.onMessage(req, False)
# List tail
action = "queue_list"
action = consts.QUEUE_LIST
body = {}
req = test_utils.create_request(action, body, headers)
@ -571,7 +572,7 @@ class QueueLifecycleBaseTest(base.V2Base):
'Client-ID': str(uuid.uuid4()),
'X-Project-ID': 'test-project'
}
action = "queue_list"
action = consts.QUEUE_LIST
body = {}
send_mock = mock.patch.object(self.protocol, 'sendMessage')

View File

@ -21,6 +21,7 @@ import mock
import msgpack
from zaqar.common import auth
from zaqar.common import consts
from zaqar.storage import errors as storage_errors
from zaqar.tests.unit.transport.websocket import base
from zaqar.tests.unit.transport.websocket import utils as test_utils
@ -41,9 +42,9 @@ class SubscriptionTest(base.V1_1Base):
'X-Project-ID': self.project_id
}
action = 'queue_create'
body = {'queue_name': 'kitkat'}
req = test_utils.create_request(action, body, self.headers)
req = test_utils.create_request(consts.QUEUE_CREATE,
body, self.headers)
def validator(resp, isBinary):
resp = json.loads(resp)
@ -55,14 +56,14 @@ class SubscriptionTest(base.V1_1Base):
def tearDown(self):
super(SubscriptionTest, self).tearDown()
action = 'queue_delete'
body = {'queue_name': 'kitkat'}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
self.addCleanup(send_mock.stop)
sender = send_mock.start()
req = test_utils.create_request(action, body, self.headers)
req = test_utils.create_request(consts.QUEUE_DELETE,
body, self.headers)
def validator(resp, isBinary):
resp = json.loads(resp)
@ -72,7 +73,7 @@ class SubscriptionTest(base.V1_1Base):
self.protocol.onMessage(req, False)
def test_subscription_create(self):
action = 'subscription_create'
action = consts.SUBSCRIPTION_CREATE
body = {'queue_name': 'kitkat', 'ttl': 600}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -104,7 +105,7 @@ class SubscriptionTest(base.V1_1Base):
'body': {'message': 'Subscription kitkat created.',
'subscription_id': subscriber['id']},
'headers': {'status': 201},
'request': {'action': 'subscription_create',
'request': {'action': consts.SUBSCRIPTION_CREATE,
'body': {'queue_name': 'kitkat', 'ttl': 600},
'api': 'v2', 'headers': self.headers}}
@ -122,7 +123,7 @@ class SubscriptionTest(base.V1_1Base):
@mock.patch.object(auth, 'create_trust_id')
def test_subscription_create_trust(self, create_trust):
create_trust.return_value = 'trust_id'
action = 'subscription_create'
action = consts.SUBSCRIPTION_CREATE
body = {'queue_name': 'kitkat', 'ttl': 600,
'subscriber': 'trust+http://example.com'}
self.protocol._auth_env = {}
@ -156,7 +157,7 @@ class SubscriptionTest(base.V1_1Base):
self.addCleanup(
self.boot.storage.subscription_controller.delete, 'kitkat', sub,
project=self.project_id)
action = 'subscription_delete'
action = consts.SUBSCRIPTION_DELETE
body = {'queue_name': 'kitkat', 'subscription_id': str(sub)}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -174,7 +175,7 @@ class SubscriptionTest(base.V1_1Base):
response = {
'body': 'Subscription %s removed.' % str(sub),
'headers': {'status': 204},
'request': {'action': 'subscription_delete',
'request': {'action': consts.SUBSCRIPTION_DELETE,
'body': {'queue_name': 'kitkat',
'subscription_id': str(sub)},
'api': 'v2', 'headers': self.headers}}
@ -182,7 +183,7 @@ class SubscriptionTest(base.V1_1Base):
self.assertEqual(response, json.loads(sender.call_args[0][0]))
def test_subscription_create_no_queue(self):
action = 'subscription_create'
action = consts.SUBSCRIPTION_CREATE
body = {'queue_name': 'shuffle', 'ttl': 600}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -208,7 +209,7 @@ class SubscriptionTest(base.V1_1Base):
'body': {'message': 'Subscription shuffle created.',
'subscription_id': subscriber['id']},
'headers': {'status': 201},
'request': {'action': 'subscription_create',
'request': {'action': consts.SUBSCRIPTION_CREATE,
'body': {'queue_name': 'shuffle', 'ttl': 600},
'api': 'v2', 'headers': self.headers}}
@ -221,7 +222,7 @@ class SubscriptionTest(base.V1_1Base):
self.addCleanup(
self.boot.storage.subscription_controller.delete, 'kitkat', sub,
project=self.project_id)
action = 'subscription_get'
action = consts.SUBSCRIPTION_GET
body = {'queue_name': 'kitkat', 'subscription_id': str(sub)}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -239,7 +240,7 @@ class SubscriptionTest(base.V1_1Base):
'ttl': 600,
'confirmed': False},
'headers': {'status': 200},
'request': {'action': 'subscription_get',
'request': {'action': consts.SUBSCRIPTION_GET,
'body': {'queue_name': 'kitkat',
'subscription_id': str(sub)},
'api': 'v2', 'headers': self.headers}}
@ -257,7 +258,7 @@ class SubscriptionTest(base.V1_1Base):
self.addCleanup(
self.boot.storage.subscription_controller.delete, 'kitkat', sub,
project=self.project_id)
action = 'subscription_list'
action = consts.SUBSCRIPTION_LIST
body = {'queue_name': 'kitkat'}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -277,7 +278,7 @@ class SubscriptionTest(base.V1_1Base):
'ttl': 600,
'confirmed': False}]},
'headers': {'status': 200},
'request': {'action': 'subscription_list',
'request': {'action': consts.SUBSCRIPTION_LIST,
'body': {'queue_name': 'kitkat'},
'api': 'v2', 'headers': self.headers}}
self.assertEqual(1, sender.call_count)
@ -295,7 +296,7 @@ class SubscriptionTest(base.V1_1Base):
# if the client suddenly starts sending requests in another format.
# Create a subscription in binary format
action = 'subscription_create'
action = consts.SUBSCRIPTION_CREATE
body = {'queue_name': 'kitkat', 'ttl': 600}
send_mock = mock.patch.object(self.protocol, 'sendMessage')
@ -324,7 +325,7 @@ class SubscriptionTest(base.V1_1Base):
self.addCleanup(webhook_notification_send_mock.stop)
webhook_notification_sender = webhook_notification_send_mock.start()
action = "message_post"
action = consts.MESSAGE_POST
body = {"queue_name": "kitkat",
"messages": [{'body': {'status': 'disco queen'}, 'ttl': 60}]}
req = test_utils.create_request(action, body, self.headers)
@ -357,7 +358,7 @@ class SubscriptionTest(base.V1_1Base):
self.addCleanup(
self.boot.storage.subscription_controller.delete, 'kitkat', sub,
project=self.project_id)
action = 'subscription_list'
action = consts.SUBSCRIPTION_LIST
body = {'queue_name': 'kitkat'}
send_mock = mock.patch.object(self.protocol, 'sendMessage')

View File

@ -37,6 +37,7 @@ except ImportError:
from email.mime import message
Message = message.MIMEMessage
from zaqar.common import consts
from zaqar.i18n import _LI
@ -127,7 +128,7 @@ class MessagingProtocol(websocket.WebSocketServerProtocol):
return self._authenticate(payload, isBinary)
else:
resp = self._handler.process_request(req, self)
if payload.get('action') == 'subscription_create':
if payload.get('action') == consts.SUBSCRIPTION_CREATE:
# NOTE(Eva-i): this will make further websocket
# notifications encoded in the same format as the last
# successful websocket subscription create request.