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