WebSocket functional tests

This adds infrastructure for websocket functional tests, and a new tox
target running them.

Change-Id: Ib4ab6cbaaf4a7295e6a6f2f26b2e9e935e3b88ef
This commit is contained in:
Thomas Herve 2015-09-14 10:18:20 +02:00
parent 9535304b18
commit 5e5eea778f
6 changed files with 88 additions and 5 deletions

View File

@ -10,6 +10,7 @@ mock>=1.2
# Backends
redis>=2.10.0
pymongo>=3.0.2
websocket-client>=0.32.0 # LGPLv2+
# Unit testing
coverage>=3.6

View File

@ -23,6 +23,13 @@ setenv = ZAQAR_TEST_MONGODB=1
setenv = JIT_FLAG=--jit off
{[testenv]setenv}
[testenv:integration]
setenv = ZAQAR_TEST_MONGODB=1
ZAQAR_TEST_SLOW=1
ZAQAR_TEST_INTEGRATION=1
{[testenv]setenv}
commands = python setup.py testr --slowest --testr-args='--concurrency 1 zaqar.tests.functional'
[tox:jenkins]
downloadcache = ~/cache/pip

View File

@ -75,6 +75,10 @@ class FunctionalTestBase(testing.TestBase):
self.resource_defaults = transport_base.ResourceDefaults(self.mconf)
# Always register options
wrapper = bootstrap.Bootstrap(self.mconf)
wrapper.transport
if _TEST_INTEGRATION:
# TODO(kgriffs): This code should be replaced to use
# an external wsgi server instance.
@ -92,10 +96,9 @@ class FunctionalTestBase(testing.TestBase):
self.mconf.pooling = True
self.mconf.admin_mode = True
boot = bootstrap.Bootstrap(self.mconf)
self.addCleanup(boot.storage.close)
self.addCleanup(boot.control.close)
self.client = http.WSGIClient(boot.transport.app)
self.addCleanup(wrapper.storage.close)
self.addCleanup(wrapper.control.close)
self.client = http.WSGIClient(wrapper.transport.app)
self.headers = helpers.create_zaqar_headers(self.cfg)

View File

@ -0,0 +1,72 @@
# 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 json
import uuid
from testtools import testcase
import websocket
from zaqar.tests.functional import base
class TestQueues(base.V1_1FunctionalTestBase):
config_file = 'websocket_mongodb.conf'
server_class = base.ZaqarServer
def setUp(self):
if not base._TEST_INTEGRATION:
raise testcase.TestSkipped('Only run in integration mode')
super(TestQueues, self).setUp()
self.project_id = str(uuid.uuid4())
self.headers = {'Client-ID': str(uuid.uuid4()),
'X-Project-ID': self.project_id}
self.client = websocket.create_connection('ws://localhost:9000/')
self.addCleanup(self.client.close)
def test_list_empty(self):
self.client.send(
json.dumps({'action': 'queue_list', 'headers': self.headers}))
response = json.loads(self.client.recv())
self.assertEqual(
{'body': {'queues': []},
'headers': {'status': 200},
'request': {'action': 'queue_list', 'body': {}, 'api': 'v2',
'headers': self.headers}},
response)
def test_list(self):
self.client.send(
json.dumps({'action': 'queue_create',
'body': {'queue_name': 'my_queue'},
'headers': self.headers}))
response = json.loads(self.client.recv())
self.assertEqual(
{'body': 'Queue my_queue created.',
'headers': {'status': 201},
'request': {'action': 'queue_create',
'body': {'queue_name': 'my_queue'}, 'api': 'v2',
'headers': self.headers}},
response)
self.client.send(
json.dumps({'action': 'queue_list', 'headers': self.headers}))
response = json.loads(self.client.recv())
self.assertEqual(
{'body': {'queues': [{'name': 'my_queue'}]},
'headers': {'status': 200},
'request': {'action': 'queue_list', 'body': {}, 'api': 'v2',
'headers': self.headers}},
response)

View File

@ -19,7 +19,7 @@ import uuid
import ddt
import six
from zaqar.tests.functional import base # noqa
from zaqar.tests.functional import base
from zaqar.tests.functional import helpers