Move transport v1_1 tests out of tests/

This moves tests for wsgi v1.1 out of the tests directory.

blueprint tests-refactoring

Change-Id: I6911a1f4c597e11628c8290918e35e16f743a997
This commit is contained in:
Thomas Herve 2015-06-04 11:01:57 +02:00
parent 89293a89eb
commit 0b121ffdb2
11 changed files with 159 additions and 385 deletions

View File

@ -7,6 +7,11 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} $JIT_FLAG -m subunit.run discover -s ./zaqar/tests/unit/transport/wsgi/v2_0 $LISTOPT $IDOPTION
OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} $JIT_FLAG -m subunit.run discover -s ./zaqar/tests/unit/transport/wsgi/v1_1 $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -1,223 +0,0 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
import uuid
import ddt
import falcon
from oslo_serialization import jsonutils
from zaqar.tests.unit.transport.wsgi import base
from zaqar.tests.unit.transport.wsgi import v1_1
# --------------------------------------------------------------------------
# Identical or just minor variations across versions
# --------------------------------------------------------------------------
URL_PREFIX = '/v1.1'
class TestAuth(v1_1.TestAuth):
url_prefix = URL_PREFIX
class TestClaimsFaultyDriver(v1_1.TestClaimsFaultyDriver):
url_prefix = URL_PREFIX
class TestClaimsMongoDB(v1_1.TestClaimsMongoDB):
url_prefix = URL_PREFIX
class TestDefaultLimits(v1_1.TestDefaultLimits):
url_prefix = URL_PREFIX
class TestHomeDocument(v1_1.TestHomeDocument):
url_prefix = URL_PREFIX
class TestMediaType(v1_1.TestMediaType):
url_prefix = URL_PREFIX
class TestMessagesFaultyDriver(v1_1.TestMessagesFaultyDriver):
url_prefix = URL_PREFIX
class TestMessagesMongoDB(v1_1.TestMessagesMongoDB):
url_prefix = URL_PREFIX
class TestMessagesMongoDBPooled(v1_1.TestMessagesMongoDBPooled):
url_prefix = URL_PREFIX
class TestQueueFaultyDriver(v1_1.TestQueueFaultyDriver):
url_prefix = URL_PREFIX
# TODO(kgriffs): Having to list a separate test for each backend is
# sort of a pain; is there a better way?
class TestQueueLifecycleMongoDB(v1_1.TestQueueLifecycleMongoDB):
url_prefix = URL_PREFIX
# NOTE(flaper87): We'll need this once we split data/control plane
# class TestQueueLifecycleSqlalchemy(v1_1.TestQueueLifecycleSqlalchemy):
# url_prefix = URL_PREFIX
class TestPoolsMongoDB(v1_1.TestPoolsMongoDB):
url_prefix = URL_PREFIX
# class TestPoolsSqlalchemy(v1_1.TestPoolsSqlalchemy):
# url_prefix = URL_PREFIX
class TestValidation(v1_1.TestValidation):
url_prefix = URL_PREFIX
class TestFlavorsMongoDB(v1_1.TestFlavorsMongoDB):
url_prefix = URL_PREFIX
# --------------------------------------------------------------------------
# v1.1 only
# --------------------------------------------------------------------------
class TestPing(base.V1_1Base):
config_file = 'wsgi_mongodb.conf'
def test_get(self):
# TODO(kgriffs): Make use of setUp for setting the URL prefix
# so we can just say something like:
#
# response = self.simulate_get('/ping')
#
response = self.simulate_get('/v1.1/ping')
self.assertEqual(self.srmock.status, falcon.HTTP_204)
self.assertEqual(response, [])
def test_head(self):
response = self.simulate_head('/v1.1/ping')
self.assertEqual(self.srmock.status, falcon.HTTP_204)
self.assertEqual(response, [])
class TestHealthMongoDB(v1_1.TestHealthMongoDB):
url_prefix = URL_PREFIX
class TestHealthFaultyDriver(v1_1.TestHealthFaultyDriver):
url_prefix = URL_PREFIX
@ddt.ddt
class TestMessages(base.V1_1Base):
config_file = 'wsgi_mongodb.conf'
def setUp(self):
super(TestMessages, self).setUp()
self.queue_path = '/v1.1/queues/test-queue'
self.messages_path = self.queue_path + '/messages'
self.project_id = 'e8ba1038'
self.headers = {'Client-ID': str(uuid.uuid4())}
self.simulate_put(self.queue_path, self.project_id)
def tearDown(self):
self.simulate_delete(self.queue_path, self.project_id)
super(TestMessages, self).tearDown()
def _post_messages(self, target, repeat=1):
doc = {'messages': [{'body': 239, 'ttl': 300}] * repeat}
body = jsonutils.dumps(doc)
return self.simulate_post(target, self.project_id, body=body,
headers=self.headers)
def _get_msg_id(self, headers):
return self._get_msg_ids(headers)[0]
def _get_msg_ids(self, headers):
return headers['Location'].rsplit('=', 1)[-1].split(',')
@ddt.data(1, 2, 10)
def test_pop(self, message_count):
self._post_messages(self.messages_path, repeat=message_count)
msg_id = self._get_msg_id(self.srmock.headers_dict)
target = self.messages_path + '/' + msg_id
self.simulate_get(target, self.project_id)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
query_string = 'pop=' + str(message_count)
result = self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
result_doc = jsonutils.loads(result[0])
self.assertEqual(len(result_doc['messages']), message_count)
self.simulate_get(target, self.project_id)
self.assertEqual(self.srmock.status, falcon.HTTP_404)
@ddt.data('', 'pop=1000000', 'pop=10&ids=1', 'pop=-1')
def test_pop_invalid(self, query_string):
self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_400)
def test_pop_empty_queue(self):
query_string = 'pop=1'
result = self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
result_doc = jsonutils.loads(result[0])
self.assertEqual(result_doc['messages'], [])
def test_pop_single_message(self):
self._post_messages(self.messages_path, repeat=5)
msg_id = self._get_msg_id(self.srmock.headers_dict)
target = self.messages_path + '/' + msg_id
self.simulate_get(target, self.project_id)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
# Pop Single message from the queue
query_string = 'pop=1'
result = self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
# Get messages from the queue & verify message count
query_string = 'echo=True'
result = self.simulate_get(self.messages_path, self.project_id,
query_string=query_string,
headers=self.headers)
result_doc = jsonutils.loads(result[0])
actual_msg_count = len(result_doc['messages'])
expected_msg_count = 4
self.assertEqual(actual_msg_count, expected_msg_count)

View File

@ -142,6 +142,7 @@ class V1_1Base(TestBase):
Should contain methods specific to V1.1 of the API
"""
url_prefix = '/v1.1'
def _empty_message_list(self, body):
self.assertEqual(jsonutils.loads(body[0])['messages'], [])
@ -152,7 +153,7 @@ class V1_1BaseFaulty(TestBaseFaulty):
Should contain methods specific to V1.1 exception testing
"""
pass
url_prefix = '/v1.1'
class V2Base(V1_1Base):

View File

@ -1,44 +0,0 @@
# Copyright (c) 2014 Rackspace, Inc.
#
# 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.
from zaqar.tests.unit.transport.wsgi.v1_1 import test_auth
from zaqar.tests.unit.transport.wsgi.v1_1 import test_claims
from zaqar.tests.unit.transport.wsgi.v1_1 import test_default_limits
from zaqar.tests.unit.transport.wsgi.v1_1 import test_flavors
from zaqar.tests.unit.transport.wsgi.v1_1 import test_health
from zaqar.tests.unit.transport.wsgi.v1_1 import test_home
from zaqar.tests.unit.transport.wsgi.v1_1 import test_media_type
from zaqar.tests.unit.transport.wsgi.v1_1 import test_messages
from zaqar.tests.unit.transport.wsgi.v1_1 import test_pools
from zaqar.tests.unit.transport.wsgi.v1_1 import test_queue_lifecycle as l
from zaqar.tests.unit.transport.wsgi.v1_1 import test_validation
TestAuth = test_auth.TestAuth
TestClaimsFaultyDriver = test_claims.TestClaimsFaultyDriver
TestClaimsMongoDB = test_claims.TestClaimsMongoDB
TestDefaultLimits = test_default_limits.TestDefaultLimits
TestHealthMongoDB = test_health.TestHealthMongoDB
TestHealthFaultyDriver = test_health.TestHealthFaultyDriver
TestHomeDocument = test_home.TestHomeDocument
TestMediaType = test_media_type.TestMediaType
TestMessagesFaultyDriver = test_messages.TestMessagesFaultyDriver
TestMessagesMongoDB = test_messages.TestMessagesMongoDB
TestMessagesMongoDBPooled = test_messages.TestMessagesMongoDBPooled
TestQueueFaultyDriver = l.TestQueueLifecycleFaultyDriver
TestQueueLifecycleMongoDB = l.TestQueueLifecycleMongoDB
TestQueueLifecycleSqlalchemy = l.TestQueueLifecycleSqlalchemy
TestPoolsMongoDB = test_pools.TestPoolsMongoDB
TestPoolsSqlalchemy = test_pools.TestPoolsSqlalchemy
TestValidation = test_validation.TestValidation
TestFlavorsMongoDB = test_flavors.TestFlavorsMongoDB

View File

@ -29,10 +29,13 @@ from zaqar.tests.unit.transport.wsgi import base
@ddt.ddt
class ClaimsBaseTest(base.V1_1Base):
class TestClaimsMongoDB(base.V1_1Base):
config_file = 'wsgi_mongodb.conf'
@testing.requires_mongodb
def setUp(self):
super(ClaimsBaseTest, self).setUp()
super(TestClaimsMongoDB, self).setUp()
self.default_claim_ttl = self.boot.transport._defaults.claim_ttl
self.project_id = '737_abc8332832'
@ -55,9 +58,17 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(self.srmock.status, falcon.HTTP_201)
def tearDown(self):
storage = self.boot.storage._storage
control = self.boot.control
connection = storage.connection
connection.drop_database(control.queues_database)
for db in storage.message_databases:
connection.drop_database(db)
self.simulate_delete(self.queue_path, headers=self.headers)
super(ClaimsBaseTest, self).tearDown()
super(TestClaimsMongoDB, self).tearDown()
@ddt.data('[', '[]', '.', '"fail"')
def test_bad_claim(self, doc):
@ -276,27 +287,6 @@ class ClaimsBaseTest(base.V1_1Base):
self.assertEqual(self.srmock.status, falcon.HTTP_404)
class TestClaimsMongoDB(ClaimsBaseTest):
config_file = 'wsgi_mongodb.conf'
@testing.requires_mongodb
def setUp(self):
super(TestClaimsMongoDB, self).setUp()
def tearDown(self):
storage = self.boot.storage._storage
control = self.boot.control
connection = storage.connection
connection.drop_database(control.queues_database)
for db in storage.message_databases:
connection.drop_database(db)
super(TestClaimsMongoDB, self).tearDown()
class TestClaimsFaultyDriver(base.V1_1BaseFaulty):
config_file = 'wsgi_faulty.conf'

View File

@ -80,10 +80,13 @@ def flavors(test, count, pool):
@ddt.ddt
class FlavorsBaseTest(base.V1_1Base):
class TestFlavorsMongoDB(base.V1_1Base):
config_file = 'wsgi_mongodb_pooled.conf'
@testing.requires_mongodb
def setUp(self):
super(FlavorsBaseTest, self).setUp()
super(TestFlavorsMongoDB, self).setUp()
self.queue = 'test-queue'
self.queue_path = self.url_prefix + '/queues/' + self.queue
@ -102,7 +105,7 @@ class FlavorsBaseTest(base.V1_1Base):
self.assertEqual(self.srmock.status, falcon.HTTP_201)
def tearDown(self):
super(FlavorsBaseTest, self).tearDown()
super(TestFlavorsMongoDB, self).tearDown()
self.simulate_delete(self.flavor_path)
self.assertEqual(self.srmock.status, falcon.HTTP_204)
@ -328,12 +331,3 @@ class FlavorsBaseTest(base.V1_1Base):
self.simulate_put(self.queue_path, body=jsonutils.dumps(metadata))
self.assertEqual(self.srmock.status, falcon.HTTP_400)
class TestFlavorsMongoDB(FlavorsBaseTest):
config_file = 'wsgi_mongodb_pooled.conf'
@testing.requires_mongodb
def setUp(self):
super(TestFlavorsMongoDB, self).setUp()

View File

@ -26,10 +26,13 @@ from zaqar.tests.unit.transport.wsgi import base
@ddt.ddt
class TestHealth(base.TestBase):
class TestHealthMongoDB(base.V1_1Base):
config_file = 'wsgi_mongodb.conf'
@testing.requires_mongodb
def setUp(self):
super(TestHealth, self).setUp()
super(TestHealthMongoDB, self).setUp()
def test_basic(self):
path = self.url_prefix + '/health'
@ -76,19 +79,7 @@ class TestHealth(base.TestBase):
self.assertTrue(op_status[op]['succeeded'])
class TestHealthMongoDB(TestHealth):
config_file = 'wsgi_mongodb.conf'
@testing.requires_mongodb
def setUp(self):
super(TestHealthMongoDB, self).setUp()
def tearDown(self):
super(TestHealthMongoDB, self).tearDown()
class TestHealthFaultyDriver(base.TestBaseFaulty):
class TestHealthFaultyDriver(base.V1_1BaseFaulty):
config_file = 'wsgi_faulty.conf'

View File

@ -30,10 +30,13 @@ from zaqar.transport import validation
@ddt.ddt
class MessagesBaseTest(base.V1_1Base):
class TestMessagesMongoDB(base.V1_1Base):
config_file = 'wsgi_mongodb.conf'
@testing.requires_mongodb
def setUp(self):
super(MessagesBaseTest, self).setUp()
super(TestMessagesMongoDB, self).setUp()
self.default_message_ttl = self.boot.transport._defaults.message_ttl
@ -67,7 +70,7 @@ class MessagesBaseTest(base.V1_1Base):
self.simulate_delete(self.url_prefix + '/pools/' + str(i),
headers=self.headers)
super(MessagesBaseTest, self).tearDown()
super(TestMessagesMongoDB, self).tearDown()
def test_name_restrictions(self):
sample_messages = [
@ -538,28 +541,74 @@ class MessagesBaseTest(base.V1_1Base):
def _get_msg_ids(self, headers):
return headers['location'].rsplit('=', 1)[-1].split(',')
@ddt.data(1, 2, 10)
def test_pop(self, message_count):
class TestMessagesMongoDB(MessagesBaseTest):
config_file = 'wsgi_mongodb.conf'
self._post_messages(self.messages_path, repeat=message_count)
msg_id = self._get_msg_id(self.srmock.headers_dict)
target = self.messages_path + '/' + msg_id
@testing.requires_mongodb
def setUp(self):
super(TestMessagesMongoDB, self).setUp()
self.simulate_get(target, self.project_id)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
def tearDown(self):
super(TestMessagesMongoDB, self).tearDown()
query_string = 'pop=' + str(message_count)
result = self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
result_doc = jsonutils.loads(result[0])
self.assertEqual(len(result_doc['messages']), message_count)
self.simulate_get(target, self.project_id)
self.assertEqual(self.srmock.status, falcon.HTTP_404)
@ddt.data('', 'pop=1000000', 'pop=10&ids=1', 'pop=-1')
def test_pop_invalid(self, query_string):
self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_400)
def test_pop_empty_queue(self):
query_string = 'pop=1'
result = self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
result_doc = jsonutils.loads(result[0])
self.assertEqual(result_doc['messages'], [])
def test_pop_single_message(self):
self._post_messages(self.messages_path, repeat=5)
msg_id = self._get_msg_id(self.srmock.headers_dict)
target = self.messages_path + '/' + msg_id
self.simulate_get(target, self.project_id)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
# Pop Single message from the queue
query_string = 'pop=1'
result = self.simulate_delete(self.messages_path, self.project_id,
query_string=query_string)
self.assertEqual(self.srmock.status, falcon.HTTP_200)
# Get messages from the queue & verify message count
query_string = 'echo=True'
result = self.simulate_get(self.messages_path, self.project_id,
query_string=query_string,
headers=self.headers)
result_doc = jsonutils.loads(result[0])
actual_msg_count = len(result_doc['messages'])
expected_msg_count = 4
self.assertEqual(actual_msg_count, expected_msg_count)
class TestMessagesMongoDBPooled(MessagesBaseTest):
class TestMessagesMongoDBPooled(TestMessagesMongoDB):
config_file = 'wsgi_mongodb_pooled.conf'
@testing.requires_mongodb
def setUp(self):
super(TestMessagesMongoDBPooled, self).setUp()
def tearDown(self):
super(TestMessagesMongoDBPooled, self).tearDown()
# TODO(cpp-cabrera): remove this skipTest once pooled queue
# listing is implemented
def test_list(self):

View File

@ -0,0 +1,38 @@
# Copyright (c) 2015 Red Hat, Inc.
#
# 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.
import falcon
from zaqar.tests.unit.transport.wsgi import base
class TestPing(base.V1_1Base):
config_file = 'wsgi_mongodb.conf'
def test_get(self):
# TODO(kgriffs): Make use of setUp for setting the URL prefix
# so we can just say something like:
#
# response = self.simulate_get('/ping')
#
response = self.simulate_get('/v1.1/ping')
self.assertEqual(self.srmock.status, falcon.HTTP_204)
self.assertEqual(response, [])
def test_head(self):
response = self.simulate_head('/v1.1/ping')
self.assertEqual(self.srmock.status, falcon.HTTP_204)
self.assertEqual(response, [])

View File

@ -83,10 +83,13 @@ def pools(test, count, uri, group):
@ddt.ddt
class PoolsBaseTest(base.V1_1Base):
class TestPoolsMongoDB(base.V1_1Base):
config_file = 'wsgi_mongodb_pooled.conf'
@testing.requires_mongodb
def setUp(self):
super(PoolsBaseTest, self).setUp()
super(TestPoolsMongoDB, self).setUp()
self.doc = {'weight': 100,
'group': 'mygroup',
'uri': 'mongodb://localhost:27017'}
@ -95,7 +98,7 @@ class PoolsBaseTest(base.V1_1Base):
self.assertEqual(self.srmock.status, falcon.HTTP_201)
def tearDown(self):
super(PoolsBaseTest, self).tearDown()
super(TestPoolsMongoDB, self).tearDown()
self.simulate_delete(self.pool)
self.assertEqual(self.srmock.status, falcon.HTTP_204)
@ -333,20 +336,3 @@ class PoolsBaseTest(base.V1_1Base):
self.assertEqual(len(pool_list), 6)
path, weight = expected[4][:2]
self._pool_expect(pool_list[0], path, weight, self.doc['uri'])
class TestPoolsMongoDB(PoolsBaseTest):
config_file = 'wsgi_mongodb_pooled.conf'
@testing.requires_mongodb
def setUp(self):
super(TestPoolsMongoDB, self).setUp()
class TestPoolsSqlalchemy(PoolsBaseTest):
config_file = 'wsgi_sqlalchemy_pooled.conf'
def setUp(self):
super(TestPoolsSqlalchemy, self).setUp()

View File

@ -24,12 +24,13 @@ from zaqar.tests.unit.transport.wsgi import base
@ddt.ddt
class QueueLifecycleBaseTest(base.V1_1Base):
class TestQueueLifecycleMongoDB(base.V1_1Base):
config_file = None
config_file = 'wsgi_mongodb.conf'
@testing.requires_mongodb
def setUp(self):
super(QueueLifecycleBaseTest, self).setUp()
super(TestQueueLifecycleMongoDB, self).setUp()
self.queue_path = self.url_prefix + '/queues'
self.gumshoe_queue_path = self.queue_path + '/gumshoe'
@ -40,6 +41,17 @@ class QueueLifecycleBaseTest(base.V1_1Base):
'X-Project-ID': '3387309841abc_'
}
def tearDown(self):
storage = self.boot.storage._storage
connection = storage.connection
connection.drop_database(self.boot.control.queues_database)
for db in storage.message_databases:
connection.drop_database(db)
super(TestQueueLifecycleMongoDB, self).tearDown()
def test_empty_project_id(self):
headers = {
'Client-ID': str(uuid.uuid4()),
@ -317,31 +329,6 @@ class QueueLifecycleBaseTest(base.V1_1Base):
self.assertEqual(self.srmock.status, falcon.HTTP_200)
class TestQueueLifecycleMongoDB(QueueLifecycleBaseTest):
config_file = 'wsgi_mongodb.conf'
@testing.requires_mongodb
def setUp(self):
super(TestQueueLifecycleMongoDB, self).setUp()
def tearDown(self):
storage = self.boot.storage._storage
connection = storage.connection
connection.drop_database(self.boot.control.queues_database)
for db in storage.message_databases:
connection.drop_database(db)
super(TestQueueLifecycleMongoDB, self).tearDown()
class TestQueueLifecycleSqlalchemy(QueueLifecycleBaseTest):
config_file = 'wsgi_sqlalchemy.conf'
class TestQueueLifecycleFaultyDriver(base.V1_1BaseFaulty):
config_file = 'wsgi_faulty.conf'