Implement small http client for tests
Instead of an HTTP module, use an http client that can be instantiated once per test and uses requests' sessions. This reduces the code needed for tests and centralizes the serialization process. Implements blueprint: refactor-system-tests Change-Id: I96ec90afb18e3fd0249bc323c85fb216c5878d4d
This commit is contained in:
parent
226e813db8
commit
30efa29251
@ -21,6 +21,7 @@ from marconi import bootstrap
|
|||||||
from marconi import tests as testing
|
from marconi import tests as testing
|
||||||
from marconi.tests.functional import config
|
from marconi.tests.functional import config
|
||||||
from marconi.tests.functional import helpers
|
from marconi.tests.functional import helpers
|
||||||
|
from marconi.tests.functional import http
|
||||||
# NOTE(flaper87): This is necessary to register,
|
# NOTE(flaper87): This is necessary to register,
|
||||||
# wsgi configs and won't be permanent. It'll be
|
# wsgi configs and won't be permanent. It'll be
|
||||||
# refactored as part of the work for this blueprint
|
# refactored as part of the work for this blueprint
|
||||||
@ -57,6 +58,11 @@ class FunctionalTestBase(testing.TestBase):
|
|||||||
self.headers_response_with_body = set(['location',
|
self.headers_response_with_body = set(['location',
|
||||||
'content-type'])
|
'content-type'])
|
||||||
|
|
||||||
|
# NOTE(flaper87): Create client
|
||||||
|
# for this test unit.
|
||||||
|
self.client = http.Client()
|
||||||
|
self.client.set_headers(self.header)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
if cls.server:
|
if cls.server:
|
||||||
|
@ -12,99 +12,74 @@
|
|||||||
# implied.
|
# implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import functools
|
||||||
|
import json
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def get(url, header=''):
|
class Client(object):
|
||||||
"""Does http GET."""
|
|
||||||
try:
|
|
||||||
response = requests.get(url, headers=header)
|
|
||||||
except requests.ConnectionError as detail:
|
|
||||||
print('ConnectionError: Exception in http.get {}'.format(detail))
|
|
||||||
except requests.HTTPError as detail:
|
|
||||||
print('HTTPError: Exception in http.get {}'.format(detail))
|
|
||||||
except requests.Timeout as detail:
|
|
||||||
print('Timeout: Exception in http.get {}'.format(detail))
|
|
||||||
except requests.TooManyRedirects as detail:
|
|
||||||
print('TooManyRedirects: Exception in http.get {}'.format(detail))
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.base_url = None
|
||||||
|
self.session = requests.session()
|
||||||
|
|
||||||
def head(url, header=''):
|
def set_base_url(self, base_url):
|
||||||
"""Does http HEAD."""
|
self.base_url = base_url
|
||||||
try:
|
|
||||||
response = requests.head(url, headers=header)
|
|
||||||
except requests.ConnectionError as detail:
|
|
||||||
print('ConnectionError: Exception in http.head {}'.format(detail))
|
|
||||||
except requests.HTTPError as detail:
|
|
||||||
print('HTTPError: Exception in http.head {}'.format(detail))
|
|
||||||
except requests.Timeout as detail:
|
|
||||||
print('Timeout: Exception in http.head {}'.format(detail))
|
|
||||||
except requests.TooManyRedirects as detail:
|
|
||||||
print('TooManyRedirects: Exception in http.head {}'.format(detail))
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
def set_headers(self, headers):
|
||||||
|
self.session.headers.update(headers)
|
||||||
|
|
||||||
def post(url, header='', body=''):
|
def _build_url(method):
|
||||||
"""Does http POST."""
|
|
||||||
body = str(body)
|
|
||||||
body = body.replace("'", '"')
|
|
||||||
try:
|
|
||||||
response = requests.post(url, headers=header, data=body)
|
|
||||||
except requests.ConnectionError as detail:
|
|
||||||
print('ConnectionError: Exception in http.post {}'.format(detail))
|
|
||||||
except requests.HTTPError as detail:
|
|
||||||
print('HTTPError: Exception in http.post {}'.format(detail))
|
|
||||||
except requests.Timeout as detail:
|
|
||||||
print('Timeout: Exception in http.post {}'.format(detail))
|
|
||||||
except requests.TooManyRedirects as detail:
|
|
||||||
print('TooManyRedirects: Exception in http.post {}'.format(detail))
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
@functools.wraps(method)
|
||||||
|
def wrapper(self, url='', **kwargs):
|
||||||
|
|
||||||
def put(url, header='', body=''):
|
if not url.startswith("http"):
|
||||||
"""Does http PUT."""
|
if not self.base_url:
|
||||||
response = None
|
raise RuntimeError("Base url not set")
|
||||||
try:
|
url = self.base_url + url or ''
|
||||||
response = requests.put(url, headers=header, data=body)
|
|
||||||
except requests.ConnectionError as detail:
|
|
||||||
print('ConnectionError: Exception in http.put {}'.format(detail))
|
|
||||||
except requests.HTTPError as detail:
|
|
||||||
print('HTTPError: Exception in http.put {}'.format(detail))
|
|
||||||
except requests.Timeout as detail:
|
|
||||||
print('Timeout: Exception in http.put {}'.format(detail))
|
|
||||||
except requests.TooManyRedirects as detail:
|
|
||||||
print('TooManyRedirects: Exception in http.put {}'.format(detail))
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
return method(self, url, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
def delete(url, header=''):
|
@_build_url
|
||||||
"""Does http DELETE."""
|
def get(self, url=None, **kwargs):
|
||||||
response = None
|
"""Does http GET."""
|
||||||
try:
|
return self.session.get(url, **kwargs)
|
||||||
response = requests.delete(url, headers=header)
|
|
||||||
except requests.ConnectionError as detail:
|
|
||||||
print('ConnectionError: Exception in http.delete {}'.format(detail))
|
|
||||||
except requests.HTTPError as detail:
|
|
||||||
print('HTTPError: Exception in http.delete {}'.format(detail))
|
|
||||||
except requests.Timeout as detail:
|
|
||||||
print('Timeout: Exception in http.delete {}'.format(detail))
|
|
||||||
except requests.TooManyRedirects as detail:
|
|
||||||
print('TooManyRedirects: Exception in http.delete {}'.format(detail))
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
@_build_url
|
||||||
|
def head(self, url=None, **kwargs):
|
||||||
|
"""Does http HEAD."""
|
||||||
|
return self.session.head(url, **kwargs)
|
||||||
|
|
||||||
def patch(url, header='', body=''):
|
@_build_url
|
||||||
"""Does http PATCH."""
|
def post(self, url=None, **kwargs):
|
||||||
response = None
|
"""Does http POST."""
|
||||||
try:
|
|
||||||
response = requests.patch(url, headers=header, data=body)
|
if "data" in kwargs:
|
||||||
except requests.ConnectionError as detail:
|
kwargs['data'] = json.dumps(kwargs["data"])
|
||||||
print('ConnectionError: Exception in http.patch {}'.format(detail))
|
|
||||||
except requests.HTTPError as detail:
|
return self.session.post(url, **kwargs)
|
||||||
print('HTTPError: Exception in http.patch {}'.format(detail))
|
|
||||||
except requests.Timeout as detail:
|
@_build_url
|
||||||
print('Timeout: Exception in http.patch {}'.format(detail))
|
def put(self, url=None, **kwargs):
|
||||||
except requests.TooManyRedirects as detail:
|
"""Does http PUT."""
|
||||||
print('TooManyRedirects: Exception in http.patch {}'.format(detail))
|
|
||||||
return response
|
if "data" in kwargs:
|
||||||
|
kwargs['data'] = json.dumps(kwargs["data"])
|
||||||
|
|
||||||
|
return self.session.put(url, **kwargs)
|
||||||
|
|
||||||
|
@_build_url
|
||||||
|
def delete(self, url=None, **kwargs):
|
||||||
|
"""Does http DELETE."""
|
||||||
|
return self.session.delete(url, **kwargs)
|
||||||
|
|
||||||
|
@_build_url
|
||||||
|
def patch(self, url=None, **kwargs):
|
||||||
|
"""Does http PATCH."""
|
||||||
|
if "data" in kwargs:
|
||||||
|
kwargs['data'] = json.dumps(kwargs["data"])
|
||||||
|
return self.session.patch(url, **kwargs)
|
||||||
|
@ -14,12 +14,10 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ddt
|
import ddt
|
||||||
import json
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from marconi.tests.functional import base
|
from marconi.tests.functional import base
|
||||||
from marconi.tests.functional import helpers
|
from marconi.tests.functional import helpers
|
||||||
from marconi.tests.functional import http
|
|
||||||
|
|
||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
@ -37,29 +35,26 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
'version': self.cfg.marconi.version,
|
'version': self.cfg.marconi.version,
|
||||||
'queue': self.queue})
|
'queue': self.queue})
|
||||||
|
|
||||||
http.put(self.queue_url, self.header)
|
self.client.put(self.queue_url)
|
||||||
|
|
||||||
self.claim_url = self.queue_url + '/claims'
|
self.claim_url = self.queue_url + '/claims'
|
||||||
|
self.client.set_base_url(self.claim_url)
|
||||||
|
|
||||||
#Post Messages
|
#Post Messages
|
||||||
url = self.queue_url + '/messages'
|
url = self.queue_url + '/messages'
|
||||||
doc = helpers.get_message_body(messagecount=
|
doc = helpers.get_message_body(messagecount=
|
||||||
self.limits.message_paging_uplimit)
|
self.limits.message_paging_uplimit)
|
||||||
for i in range(25):
|
for i in range(25):
|
||||||
http.post(url, self.header, doc)
|
self.client.post(url, data=doc)
|
||||||
|
|
||||||
@ddt.data('', '?limit=2')
|
@ddt.data({}, dict(limit=2))
|
||||||
def test_claim_messages(self, url_appender):
|
def test_claim_messages(self, params):
|
||||||
"""Claim messages."""
|
"""Claim messages."""
|
||||||
if url_appender:
|
message_count = params.get('limit', 10)
|
||||||
message_count = int(url_appender.split('?limit=')[1])
|
|
||||||
else:
|
|
||||||
message_count = 10
|
|
||||||
|
|
||||||
url = self.claim_url + url_appender
|
doc = {"ttl": 300, "grace": 100}
|
||||||
doc = '{"ttl": 300, "grace": 100}'
|
|
||||||
|
|
||||||
result = http.post(url, self.header, doc)
|
result = self.client.post(params=params, data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
actual_message_count = len(result.json())
|
actual_message_count = len(result.json())
|
||||||
@ -72,15 +67,15 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
|
|
||||||
def test_query_claim(self):
|
def test_query_claim(self):
|
||||||
"""Query Claim."""
|
"""Query Claim."""
|
||||||
url = self.claim_url + '?limit=1'
|
params = {'limit': 1}
|
||||||
doc = '{"ttl": 300, "grace": 100}'
|
doc = {"ttl": 300, "grace": 100}
|
||||||
|
|
||||||
result = http.post(url, self.header, doc)
|
result = self.client.post(params=params, data=doc)
|
||||||
location = result.headers['Location']
|
location = result.headers['Location']
|
||||||
|
|
||||||
url = self.cfg.marconi.url + location
|
url = self.cfg.marconi.url + location
|
||||||
|
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
test_query_claim.tags = ['smoke', 'positive']
|
test_query_claim.tags = ['smoke', 'positive']
|
||||||
@ -90,11 +85,10 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
|
|
||||||
Marconi allows a maximum of 20 messages per claim.
|
Marconi allows a maximum of 20 messages per claim.
|
||||||
"""
|
"""
|
||||||
url = self.claim_url + '?limit=' + \
|
params = {"limit": self.limits.message_paging_uplimit + 1}
|
||||||
str(self.limits.message_paging_uplimit + 1)
|
doc = {"ttl": 300, "grace": 100}
|
||||||
doc = '{"ttl": 300, "grace": 100}'
|
|
||||||
|
|
||||||
result = http.post(url, self.header, doc)
|
result = self.client.post(params=params, data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_claim_more_than_allowed.tags = ['negative']
|
test_claim_more_than_allowed.tags = ['negative']
|
||||||
@ -102,21 +96,21 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
def test_claim_patch(self):
|
def test_claim_patch(self):
|
||||||
"""Update Claim."""
|
"""Update Claim."""
|
||||||
#Test Setup - Post Claim
|
#Test Setup - Post Claim
|
||||||
doc = '{"ttl": 300, "grace": 400}'
|
doc = {"ttl": 300, "grace": 400}
|
||||||
|
|
||||||
result = http.post(self.claim_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
#Patch Claim
|
#Patch Claim
|
||||||
claim_location = result.headers['Location']
|
claim_location = result.headers['Location']
|
||||||
url = self.cfg.marconi.url + claim_location
|
url = self.cfg.marconi.url + claim_location
|
||||||
doc_updated = '{"ttl": 300}'
|
doc_updated = {"ttl": 300}
|
||||||
|
|
||||||
result = http.patch(url, self.header, doc_updated)
|
result = self.client.patch(url, data=doc_updated)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
#verify that the claim TTL is updated
|
#verify that the claim TTL is updated
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
new_ttl = result.json()['ttl']
|
new_ttl = result.json()['ttl']
|
||||||
self.assertEqual(new_ttl, 300)
|
self.assertEqual(new_ttl, 300)
|
||||||
|
|
||||||
@ -125,28 +119,25 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
def test_delete_claimed_message(self):
|
def test_delete_claimed_message(self):
|
||||||
"""Delete message belonging to a Claim."""
|
"""Delete message belonging to a Claim."""
|
||||||
#Test Setup - Post claim
|
#Test Setup - Post claim
|
||||||
doc = '{"ttl": 60, "grace": 60}'
|
doc = {"ttl": 60, "grace": 60}
|
||||||
|
|
||||||
result = http.post(self.claim_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
href_list = [result.json()[i]['href']
|
|
||||||
for i in range(len(result.json()))]
|
|
||||||
url_list = [self.cfg.marconi.url + href
|
|
||||||
for href in href_list]
|
|
||||||
|
|
||||||
#Delete Claimed Messages
|
#Delete Claimed Messages
|
||||||
for url in url_list:
|
for rst in result.json():
|
||||||
result = http.delete(url, self.header)
|
href = rst['href']
|
||||||
|
url = self.cfg.marconi.url + href
|
||||||
|
result = self.client.delete(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_delete_claimed_message.tags = ['smoke', 'positive']
|
test_delete_claimed_message.tags = ['smoke', 'positive']
|
||||||
|
|
||||||
def test_claim_release(self):
|
def test_claim_release(self):
|
||||||
"""Release Claim."""
|
"""Release Claim."""
|
||||||
doc = '{"ttl": 300, "grace": 100}'
|
doc = {"ttl": 300, "grace": 100}
|
||||||
|
|
||||||
result = http.post(self.claim_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
#Extract claim location and construct the claim URL.
|
#Extract claim location and construct the claim URL.
|
||||||
@ -154,7 +145,7 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
url = self.cfg.marconi.url + location
|
url = self.cfg.marconi.url + location
|
||||||
|
|
||||||
#Release Claim.
|
#Release Claim.
|
||||||
result = http.delete(url, self.header)
|
result = self.client.delete(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_claim_release.tags = ['smoke', 'positive']
|
test_claim_release.tags = ['smoke', 'positive']
|
||||||
@ -169,7 +160,7 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
"""
|
"""
|
||||||
doc = {"ttl": ttl, "grace": 100}
|
doc = {"ttl": ttl, "grace": 100}
|
||||||
|
|
||||||
result = http.post(self.claim_url, self.header, json.dumps(doc))
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_claim_invalid_ttl.tags = ['negative']
|
test_claim_invalid_ttl.tags = ['negative']
|
||||||
@ -184,7 +175,7 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
"""
|
"""
|
||||||
doc = {"ttl": 100, "grace": grace}
|
doc = {"ttl": 100, "grace": grace}
|
||||||
|
|
||||||
result = http.post(self.claim_url, self.header, json.dumps(doc))
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_claim_invalid_grace.tags = ['negative']
|
test_claim_invalid_grace.tags = ['negative']
|
||||||
@ -198,7 +189,7 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
"""
|
"""
|
||||||
doc = {"ttl": 100, "grace": grace}
|
doc = {"ttl": 100, "grace": grace}
|
||||||
|
|
||||||
result = http.post(self.claim_url, self.header, json.dumps(doc))
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_claim_invalid_limit.tags = ['negative']
|
test_claim_invalid_limit.tags = ['negative']
|
||||||
@ -211,9 +202,9 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
outside the allowed range.Allowed ttl values is
|
outside the allowed range.Allowed ttl values is
|
||||||
60 <= ttl <= 43200.
|
60 <= ttl <= 43200.
|
||||||
"""
|
"""
|
||||||
doc = '{"ttl": 100, "grace": 100}'
|
doc = {"ttl": 100, "grace": 100}
|
||||||
|
|
||||||
result = http.post(self.claim_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
#Extract claim location and construct the claim URL.
|
#Extract claim location and construct the claim URL.
|
||||||
@ -222,7 +213,7 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
|
|
||||||
#Patch Claim.
|
#Patch Claim.
|
||||||
doc = {"ttl": ttl}
|
doc = {"ttl": ttl}
|
||||||
result = http.patch(url, self.header, json.dumps(doc))
|
result = self.client.patch(url, data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_patch_claim_invalid_ttl.tags = ['negative']
|
test_patch_claim_invalid_ttl.tags = ['negative']
|
||||||
@ -230,4 +221,4 @@ class TestClaims(base.FunctionalTestBase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""Delete Queue after Claim Test."""
|
"""Delete Queue after Claim Test."""
|
||||||
super(TestClaims, self).tearDown()
|
super(TestClaims, self).tearDown()
|
||||||
http.delete(self.queue_url, self.header)
|
self.client.delete(self.queue_url)
|
||||||
|
@ -17,7 +17,6 @@ import uuid
|
|||||||
|
|
||||||
from marconi.tests.functional import base # noqa
|
from marconi.tests.functional import base # noqa
|
||||||
from marconi.tests.functional import helpers
|
from marconi.tests.functional import helpers
|
||||||
from marconi.tests.functional import http
|
|
||||||
|
|
||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
@ -35,9 +34,10 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
'version': self.cfg.marconi.version,
|
'version': self.cfg.marconi.version,
|
||||||
'queue': self.queue})
|
'queue': self.queue})
|
||||||
|
|
||||||
http.put(self.queue_url, self.header)
|
self.client.put(self.queue_url)
|
||||||
|
|
||||||
self.message_url = self.queue_url + '/messages'
|
self.message_url = self.queue_url + '/messages'
|
||||||
|
self.client.set_base_url(self.message_url)
|
||||||
|
|
||||||
def test_message_single_insert(self):
|
def test_message_single_insert(self):
|
||||||
"""Insert Single Message into the Queue.
|
"""Insert Single Message into the Queue.
|
||||||
@ -47,7 +47,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
"""
|
"""
|
||||||
doc = helpers.get_message_body(messagecount=1)
|
doc = helpers.get_message_body(messagecount=1)
|
||||||
|
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
response_headers = set(result.headers.keys())
|
response_headers = set(result.headers.keys())
|
||||||
@ -57,7 +57,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
href = result.json()['resources'][0]
|
href = result.json()['resources'][0]
|
||||||
url = self.cfg.marconi.url + href
|
url = self.cfg.marconi.url + href
|
||||||
|
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
# Compare message metadata
|
# Compare message metadata
|
||||||
@ -67,19 +67,20 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
# Post a claim & verify the include_claimed flag.
|
# Post a claim & verify the include_claimed flag.
|
||||||
url = self.queue_url + '/claims'
|
url = self.queue_url + '/claims'
|
||||||
doc = '{"ttl": 300, "grace": 100}'
|
doc = {"ttl": 300, "grace": 100}
|
||||||
result = http.post(url, self.header, doc)
|
result = self.client.post(url, data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
url = self.message_url + '?include_claimed=true&echo=true'
|
params = {'include_claimed': True,
|
||||||
result = http.get(url, self.header)
|
'echo': True}
|
||||||
|
result = self.client.get(params=params)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
response_message_body = result.json()["messages"][0]["body"]
|
response_message_body = result.json()["messages"][0]["body"]
|
||||||
self.assertEqual(response_message_body, posted_metadata)
|
self.assertEqual(response_message_body, posted_metadata)
|
||||||
|
|
||||||
# By default, include_claimed = false
|
# By default, include_claimed = false
|
||||||
result = http.get(self.message_url, self.header)
|
result = self.client.get(self.message_url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_message_single_insert.tags = ['smoke', 'positive']
|
test_message_single_insert.tags = ['smoke', 'positive']
|
||||||
@ -89,13 +90,13 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
message_count = 10
|
message_count = 10
|
||||||
doc = helpers.get_message_body(messagecount=message_count)
|
doc = helpers.get_message_body(messagecount=message_count)
|
||||||
|
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
# GET on posted messages
|
# GET on posted messages
|
||||||
location = result.headers['location']
|
location = result.headers['location']
|
||||||
url = self.cfg.marconi.url + location
|
url = self.cfg.marconi.url + location
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
# Compare message metadata
|
# Compare message metadata
|
||||||
@ -111,24 +112,23 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
test_message_bulk_insert.tags = ['smoke', 'positive']
|
test_message_bulk_insert.tags = ['smoke', 'positive']
|
||||||
|
|
||||||
@ddt.data('', '&limit=5')
|
@ddt.data({}, {'limit': 5})
|
||||||
def test_get_message(self, url_param):
|
def test_get_message(self, params):
|
||||||
"""Get Messages."""
|
"""Get Messages."""
|
||||||
if url_param:
|
|
||||||
expected_msg_count = int(url_param.split('&limit=')[1])
|
expected_msg_count = params.get('limit', 10)
|
||||||
else:
|
|
||||||
expected_msg_count = 10
|
|
||||||
|
|
||||||
# Test Setup
|
# Test Setup
|
||||||
doc = helpers.get_message_body(messagecount=20)
|
doc = helpers.get_message_body(messagecount=20)
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
url = self.message_url + '?echo=True' + url_param
|
url = ''
|
||||||
|
params['echo'] = True
|
||||||
|
|
||||||
#Follow the hrefs & perform GET, till the end of messages i.e. http 204
|
#Follow the hrefs & perform GET, till the end of messages i.e. http 204
|
||||||
while result.status_code in [201, 200]:
|
while result.status_code in [201, 200]:
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url, params=params)
|
||||||
self.assertIn(result.status_code, [200, 204])
|
self.assertIn(result.status_code, [200, 204])
|
||||||
|
|
||||||
if result.status_code == 200:
|
if result.status_code == 200:
|
||||||
@ -146,17 +146,17 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
"""Delete Message."""
|
"""Delete Message."""
|
||||||
# Test Setup
|
# Test Setup
|
||||||
doc = helpers.get_message_body(messagecount=1)
|
doc = helpers.get_message_body(messagecount=1)
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
# Delete posted message
|
# Delete posted message
|
||||||
href = result.json()['resources'][0]
|
href = result.json()['resources'][0]
|
||||||
url = self.cfg.marconi.url + href
|
url = self.cfg.marconi.url + href
|
||||||
|
|
||||||
result = http.delete(url, self.header)
|
result = self.client.delete(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 404)
|
self.assertEqual(result.status_code, 404)
|
||||||
|
|
||||||
test_message_delete.tags = ['smoke', 'positive']
|
test_message_delete.tags = ['smoke', 'positive']
|
||||||
@ -164,7 +164,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
def test_message_bulk_delete(self):
|
def test_message_bulk_delete(self):
|
||||||
"""Bulk Delete Messages."""
|
"""Bulk Delete Messages."""
|
||||||
doc = helpers.get_message_body(messagecount=10)
|
doc = helpers.get_message_body(messagecount=10)
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
@ -172,18 +172,17 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
location = result.headers['Location']
|
location = result.headers['Location']
|
||||||
url = self.cfg.marconi.url + location
|
url = self.cfg.marconi.url + location
|
||||||
|
|
||||||
result = http.delete(url, self.header)
|
result = self.client.delete(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_message_bulk_delete.tags = ['smoke', 'positive']
|
test_message_bulk_delete.tags = ['smoke', 'positive']
|
||||||
|
|
||||||
def test_message_delete_nonexisting(self):
|
def test_message_delete_nonexisting(self):
|
||||||
"""Delete non-existing Messages."""
|
"""Delete non-existing Messages."""
|
||||||
url = self.message_url + '/non-existing'
|
result = self.client.delete('/non-existing')
|
||||||
result = http.delete(url, self.header)
|
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
@ -192,7 +191,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
def test_message_partial_delete(self):
|
def test_message_partial_delete(self):
|
||||||
"""Delete Messages will be partially successful."""
|
"""Delete Messages will be partially successful."""
|
||||||
doc = helpers.get_message_body(messagecount=3)
|
doc = helpers.get_message_body(messagecount=3)
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
@ -200,7 +199,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
location = result.headers['Location']
|
location = result.headers['Location']
|
||||||
url = self.cfg.marconi.url + location
|
url = self.cfg.marconi.url + location
|
||||||
url += ',nonexisting'
|
url += ',nonexisting'
|
||||||
result = http.delete(url, self.header)
|
result = self.client.delete(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_message_partial_delete.tags = ['negative']
|
test_message_partial_delete.tags = ['negative']
|
||||||
@ -208,7 +207,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
def test_message_partial_get(self):
|
def test_message_partial_get(self):
|
||||||
"""Get Messages will be partially successful."""
|
"""Get Messages will be partially successful."""
|
||||||
doc = helpers.get_message_body(messagecount=3)
|
doc = helpers.get_message_body(messagecount=3)
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
@ -216,7 +215,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
location = result.headers['Location']
|
location = result.headers['Location']
|
||||||
url = self.cfg.marconi.url + location
|
url = self.cfg.marconi.url + location
|
||||||
url += ',nonexisting'
|
url += ',nonexisting'
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
test_message_partial_get.tags = ['negative']
|
test_message_partial_get.tags = ['negative']
|
||||||
@ -228,7 +227,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
"""
|
"""
|
||||||
doc = helpers.get_message_body(messagecount=60)
|
doc = helpers.get_message_body(messagecount=60)
|
||||||
|
|
||||||
result = http.post(self.message_url, self.header, doc)
|
result = self.client.post(data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_message_bulk_insert_60.tags = ['negative']
|
test_message_bulk_insert_60.tags = ['negative']
|
||||||
@ -239,8 +238,8 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
|
|
||||||
Allowed values for limit are 0 < limit <= 20(configurable).
|
Allowed values for limit are 0 < limit <= 20(configurable).
|
||||||
"""
|
"""
|
||||||
url = self.message_url + '?limit=' + str(limit)
|
params = {'limit': limit}
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(params=params)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_message_get_invalid_limit.tags = ['negative']
|
test_message_get_invalid_limit.tags = ['negative']
|
||||||
@ -254,7 +253,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
url = self.message_url + '?ids=' \
|
url = self.message_url + '?ids=' \
|
||||||
+ ','.join(str(i) for i in
|
+ ','.join(str(i) for i in
|
||||||
range(self.limits.message_paging_uplimit + 1))
|
range(self.limits.message_paging_uplimit + 1))
|
||||||
result = http.delete(url, self.header)
|
result = self.client.delete(url)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
@ -269,7 +268,7 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
url = self.message_url + '?ids=' \
|
url = self.message_url + '?ids=' \
|
||||||
+ ','.join(str(i) for i in
|
+ ','.join(str(i) for i in
|
||||||
range(self.limits.message_paging_uplimit + 1))
|
range(self.limits.message_paging_uplimit + 1))
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
@ -279,11 +278,11 @@ class TestMessages(base.FunctionalTestBase):
|
|||||||
"""Get messages with non-existing marker."""
|
"""Get messages with non-existing marker."""
|
||||||
url = self.message_url + '?marker=invalid'
|
url = self.message_url + '?marker=invalid'
|
||||||
|
|
||||||
result = http.get(url, self.header)
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_get_messages_malformed_marker.tags = ['negative']
|
test_get_messages_malformed_marker.tags = ['negative']
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestMessages, self).tearDown()
|
super(TestMessages, self).tearDown()
|
||||||
http.delete(self.queue_url, self.header)
|
self.client.delete(self.queue_url)
|
||||||
|
@ -15,11 +15,9 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import copy
|
import copy
|
||||||
import ddt
|
import ddt
|
||||||
import json
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from marconi.tests.functional import base # noqa
|
from marconi.tests.functional import base # noqa
|
||||||
from marconi.tests.functional import http
|
|
||||||
|
|
||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
@ -34,6 +32,7 @@ class TestInsertQueue(base.FunctionalTestBase):
|
|||||||
self.cfg.marconi.version)
|
self.cfg.marconi.version)
|
||||||
|
|
||||||
self.headers_response_empty = set(['location'])
|
self.headers_response_empty = set(['location'])
|
||||||
|
self.client.set_base_url(self.base_url)
|
||||||
|
|
||||||
@ddt.data('qtestqueue', 'TESTqueue', 'hyphen-name', '_undersore',
|
@ddt.data('qtestqueue', 'TESTqueue', 'hyphen-name', '_undersore',
|
||||||
'i' * 64)
|
'i' * 64)
|
||||||
@ -41,14 +40,14 @@ class TestInsertQueue(base.FunctionalTestBase):
|
|||||||
"""Create Queue."""
|
"""Create Queue."""
|
||||||
self.url = self.base_url + '/queues/' + queue_name
|
self.url = self.base_url + '/queues/' + queue_name
|
||||||
|
|
||||||
result = http.put(self.url, self.header)
|
result = self.client.put(self.url)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
response_headers = set(result.headers.keys())
|
response_headers = set(result.headers.keys())
|
||||||
self.assertIsSubset(self.headers_response_empty, response_headers)
|
self.assertIsSubset(self.headers_response_empty, response_headers)
|
||||||
|
|
||||||
self.url = self.url + '/metadata'
|
self.url = self.url + '/metadata'
|
||||||
result = http.get(self.url, self.header)
|
result = self.client.get(self.url)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
self.assertEqual(result.json(), {})
|
self.assertEqual(result.json(), {})
|
||||||
|
|
||||||
@ -60,11 +59,11 @@ class TestInsertQueue(base.FunctionalTestBase):
|
|||||||
self.url = self.base_url + '/queues/' + queue_name
|
self.url = self.base_url + '/queues/' + queue_name
|
||||||
self.skipTest("Test fails, needs fix")
|
self.skipTest("Test fails, needs fix")
|
||||||
|
|
||||||
result = http.put(self.url, self.header)
|
result = self.client.put(self.url)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
self.url = self.url + '/metadata'
|
self.url = self.url + '/metadata'
|
||||||
result = http.get(self.url, self.header)
|
result = self.client.get(self.url)
|
||||||
self.assertEqual(result.status_code, 404)
|
self.assertEqual(result.status_code, 404)
|
||||||
|
|
||||||
test_insert_queue_invalid_name.tags = ['negative']
|
test_insert_queue_invalid_name.tags = ['negative']
|
||||||
@ -83,29 +82,29 @@ class TestInsertQueue(base.FunctionalTestBase):
|
|||||||
header = copy.copy(self.header)
|
header = copy.copy(self.header)
|
||||||
header["X-Auth-Token"] = 'invalid'
|
header["X-Auth-Token"] = 'invalid'
|
||||||
|
|
||||||
result = http.put(self.url, header)
|
result = self.client.put(self.url, header)
|
||||||
self.assertEqual(result.status_code, 401)
|
self.assertEqual(result.status_code, 401)
|
||||||
|
|
||||||
test_insert_queue_invalid_authtoken.tags = ['negative']
|
test_insert_queue_invalid_authtoken.tags = ['negative']
|
||||||
|
|
||||||
def test_insert_queue_header_plaintext(self):
|
def test_insert_queue_header_plaintext(self):
|
||||||
"""Insert Queue with 'Accept': 'plain/text'."""
|
"""Insert Queue with 'Accept': 'plain/text'."""
|
||||||
self.url = self.base_url + '/queues/plaintextheader'
|
path = '/queues/plaintextheader'
|
||||||
header = copy.copy(self.header)
|
self.addCleanup(self.client.delete, path)
|
||||||
header["Accept"] = 'plain/text'
|
|
||||||
|
|
||||||
result = http.put(self.url, header)
|
header = {"Accept": 'plain/text'}
|
||||||
|
result = self.client.put(path, headers=header)
|
||||||
self.assertEqual(result.status_code, 406)
|
self.assertEqual(result.status_code, 406)
|
||||||
|
|
||||||
test_insert_queue_header_plaintext.tags = ['negative']
|
test_insert_queue_header_plaintext.tags = ['negative']
|
||||||
|
|
||||||
def test_insert_queue_header_asterisk(self):
|
def test_insert_queue_header_asterisk(self):
|
||||||
"""Insert Queue with 'Accept': '*/*'."""
|
"""Insert Queue with 'Accept': '*/*'."""
|
||||||
self.url = self.base_url + '/queues/asteriskinheader'
|
path = '/queues/asteriskinheader'
|
||||||
header = copy.copy(self.header)
|
self.addCleanup(self.client.delete, path)
|
||||||
header["Accept"] = '*/*'
|
|
||||||
|
|
||||||
result = http.put(self.url, header)
|
header = {"Accept": '*/*'}
|
||||||
|
result = self.client.put(path, headers=header)
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
test_insert_queue_header_asterisk.tags = ['positive']
|
test_insert_queue_header_asterisk.tags = ['positive']
|
||||||
@ -113,13 +112,13 @@ class TestInsertQueue(base.FunctionalTestBase):
|
|||||||
def test_insert_queue_with_metadata(self):
|
def test_insert_queue_with_metadata(self):
|
||||||
"""Insert queue with a non-empty request body."""
|
"""Insert queue with a non-empty request body."""
|
||||||
self.url = self.base_url + '/queues/hasmetadata'
|
self.url = self.base_url + '/queues/hasmetadata'
|
||||||
doc = '{"queue": "Has Metadata"}'
|
doc = {"queue": "Has Metadata"}
|
||||||
result = http.put(self.url, self.header, doc)
|
result = self.client.put(self.url, data=doc)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 201)
|
self.assertEqual(result.status_code, 201)
|
||||||
|
|
||||||
self.url = self.base_url + '/queues/hasmetadata/metadata'
|
self.url = self.base_url + '/queues/hasmetadata/metadata'
|
||||||
result = http.get(self.url, self.header)
|
result = self.client.get(self.url)
|
||||||
|
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
self.assertEqual(result.json(), {})
|
self.assertEqual(result.json(), {})
|
||||||
@ -128,7 +127,6 @@ class TestInsertQueue(base.FunctionalTestBase):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestInsertQueue, self).tearDown()
|
super(TestInsertQueue, self).tearDown()
|
||||||
http.delete(self.url, self.header)
|
|
||||||
|
|
||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
@ -144,9 +142,10 @@ class TestQueueMetaData(base.FunctionalTestBase):
|
|||||||
self.cfg.marconi.version)
|
self.cfg.marconi.version)
|
||||||
|
|
||||||
self.queue_url = self.base_url + '/queues/{0}'.format(uuid.uuid1())
|
self.queue_url = self.base_url + '/queues/{0}'.format(uuid.uuid1())
|
||||||
http.put(self.queue_url, self.header)
|
self.client.put(self.queue_url)
|
||||||
|
|
||||||
self.queue_metadata_url = self.queue_url + '/metadata'
|
self.queue_metadata_url = self.queue_url + '/metadata'
|
||||||
|
self.client.set_base_url(self.queue_metadata_url)
|
||||||
|
|
||||||
@ddt.data({},
|
@ddt.data({},
|
||||||
{"_queue": "Top Level field with _"},
|
{"_queue": "Top Level field with _"},
|
||||||
@ -157,30 +156,27 @@ class TestQueueMetaData(base.FunctionalTestBase):
|
|||||||
def test_insert_queue_metadata(self, doc):
|
def test_insert_queue_metadata(self, doc):
|
||||||
"""Insert Queue with empty json."""
|
"""Insert Queue with empty json."""
|
||||||
self.skipTest("Test fails, needs fix")
|
self.skipTest("Test fails, needs fix")
|
||||||
result = http.put(self.queue_metadata_url, self.header,
|
result = self.client.put(data=doc)
|
||||||
json.dumps(doc))
|
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
result = http.get(self.queue_metadata_url, self.header)
|
result = self.client.get()
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
self.assertEqual(result.json(), doc)
|
self.assertEqual(result.json(), doc)
|
||||||
|
|
||||||
test_insert_queue_metadata.tags = ['smoke', 'positive']
|
test_insert_queue_metadata.tags = ['smoke', 'positive']
|
||||||
|
|
||||||
@ddt.data('not_a_dict',
|
@ddt.data('not_a_dict', {"queue": "i" * 65537})
|
||||||
{"queue": "i" * 65537}
|
|
||||||
)
|
|
||||||
def test_insert_queue_invalid_metadata(self, doc):
|
def test_insert_queue_invalid_metadata(self, doc):
|
||||||
"""Insert invalid metadata."""
|
"""Insert invalid metadata."""
|
||||||
|
|
||||||
result = http.put(self.queue_metadata_url, self.header, str(doc))
|
result = self.client.put(data=doc)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_insert_queue_invalid_metadata.tags = ['negative']
|
test_insert_queue_invalid_metadata.tags = ['negative']
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestQueueMetaData, self).tearDown()
|
super(TestQueueMetaData, self).tearDown()
|
||||||
http.delete(self.queue_url, self.header)
|
self.client.delete(self.queue_url)
|
||||||
|
|
||||||
|
|
||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
@ -194,90 +190,81 @@ class TestQueueMisc(base.FunctionalTestBase):
|
|||||||
self.base_url = '%s/%s' % (self.cfg.marconi.url,
|
self.base_url = '%s/%s' % (self.cfg.marconi.url,
|
||||||
self.cfg.marconi.version)
|
self.cfg.marconi.version)
|
||||||
|
|
||||||
|
self.client.set_base_url(self.base_url)
|
||||||
|
|
||||||
def test_list_queues(self):
|
def test_list_queues(self):
|
||||||
"""List Queues."""
|
"""List Queues."""
|
||||||
url = self.base_url + '/queues'
|
|
||||||
result = http.get(url, self.header)
|
|
||||||
|
|
||||||
|
result = self.client.get('/queues')
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
response_keys_actual = result.json().keys()
|
response_keys = result.json().keys()
|
||||||
response_keys_actual.sort()
|
for key in ['links', 'queues']:
|
||||||
response_keys_expected = ['links', 'queues']
|
self.assertIn(key, response_keys)
|
||||||
self.assertEqual(response_keys_actual, response_keys_expected)
|
|
||||||
|
|
||||||
test_list_queues.tags = ['smoke', 'positive']
|
test_list_queues.tags = ['smoke', 'positive']
|
||||||
|
|
||||||
def test_list_queues_detailed(self):
|
def test_list_queues_detailed(self):
|
||||||
"""List Queues with detailed = True."""
|
"""List Queues with detailed = True."""
|
||||||
url = self.base_url + '/queues?detailed=True'
|
|
||||||
result = http.get(url, self.header)
|
|
||||||
|
|
||||||
|
params = {'detailed': True}
|
||||||
|
result = self.client.get('/queues', params=params)
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
response_keys_actual = result.json()['queues'][0].keys()
|
response_keys = result.json()['queues'][0].keys()
|
||||||
response_keys_actual.sort()
|
for key in ['href', 'metadata', 'name']:
|
||||||
response_keys_expected = ['href', 'metadata', 'name']
|
self.assertIn(key, response_keys)
|
||||||
self.assertEqual(response_keys_actual, response_keys_expected)
|
|
||||||
|
|
||||||
test_list_queues_detailed.tags = ['smoke', 'positive']
|
test_list_queues_detailed.tags = ['smoke', 'positive']
|
||||||
|
|
||||||
@ddt.data(0, -1, 30)
|
@ddt.data(0, -1, 30)
|
||||||
def test_list_queue_invalid_limit(self, limit):
|
def test_list_queue_invalid_limit(self, limit):
|
||||||
"""List Queues with a limit value that is not allowed."""
|
"""List Queues with a limit value that is not allowed."""
|
||||||
url = self.base_url + '/queues?limit=' + str(limit)
|
|
||||||
result = http.get(url, self.header)
|
|
||||||
|
|
||||||
|
params = {'limit': limit}
|
||||||
|
result = self.client.get('/queues', params=params)
|
||||||
self.assertEqual(result.status_code, 400)
|
self.assertEqual(result.status_code, 400)
|
||||||
|
|
||||||
test_list_queue_invalid_limit.tags = ['negative']
|
test_list_queue_invalid_limit.tags = ['negative']
|
||||||
|
|
||||||
def test_check_health(self):
|
def test_check_health(self):
|
||||||
"""Test health endpoint."""
|
"""Test health endpoint."""
|
||||||
url = self.base_url + '/health'
|
|
||||||
result = http.get(url, self.header)
|
|
||||||
|
|
||||||
|
result = self.client.get('/health')
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_check_health.tags = ['positive']
|
test_check_health.tags = ['positive']
|
||||||
|
|
||||||
def test_check_queue_exists(self):
|
def test_check_queue_exists(self):
|
||||||
"""Checks if queue exists."""
|
"""Checks if queue exists."""
|
||||||
url = self.base_url + '/queues/testqueue'
|
|
||||||
http.put(url, self.header)
|
|
||||||
|
|
||||||
result = http.get(url, self.header)
|
path = '/queues/testqueue'
|
||||||
|
self.client.put(path)
|
||||||
|
result = self.client.get(path)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
result = http.head(url, self.header)
|
result = self.client.head(path)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_check_queue_exists.tags = ['positive']
|
test_check_queue_exists.tags = ['positive']
|
||||||
|
|
||||||
def test_check_queue_exists_negative(self):
|
def test_check_queue_exists_negative(self):
|
||||||
"""Checks non-existing queue."""
|
"""Checks non-existing queue."""
|
||||||
url = self.base_url + '/queues/nonexistingqueue'
|
path = '/queues/nonexistingqueue'
|
||||||
|
result = self.client.get(path)
|
||||||
result = http.get(url, self.header)
|
|
||||||
self.assertEqual(result.status_code, 404)
|
self.assertEqual(result.status_code, 404)
|
||||||
|
|
||||||
result = http.head(url, self.header)
|
result = self.client.head(path)
|
||||||
self.assertEqual(result.status_code, 404)
|
self.assertEqual(result.status_code, 404)
|
||||||
|
|
||||||
test_check_queue_exists_negative.tags = ['negative']
|
test_check_queue_exists_negative.tags = ['negative']
|
||||||
|
|
||||||
def test_get_queue_malformed_marker(self):
|
def test_get_queue_malformed_marker(self):
|
||||||
"""List queues with invalid marker."""
|
"""List queues with invalid marker."""
|
||||||
url = self.base_url + '/queues?marker=invalid'
|
|
||||||
self.skipTest("Test fails, needs fix")
|
self.skipTest("Test fails, needs fix")
|
||||||
|
|
||||||
result = http.get(url, self.header)
|
url = self.base_url + '/queues?marker=invalid'
|
||||||
|
result = self.client.get(url)
|
||||||
self.assertEqual(result.status_code, 204)
|
self.assertEqual(result.status_code, 204)
|
||||||
|
|
||||||
test_get_queue_malformed_marker.tags = ['negative']
|
test_get_queue_malformed_marker.tags = ['negative']
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
"""Delete Queue."""
|
|
||||||
url = cls.base_url + '/queues/testqueue'
|
|
||||||
http.delete(url, cls.header)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user