test: DRY up test_error and removing wrapper classes for router and dep tests (#1065)
This commit is contained in:
parent
5da8aad15b
commit
7e31c65b9a
|
@ -2,119 +2,121 @@ import falcon
|
|||
from falcon import testing
|
||||
|
||||
|
||||
class TestCustomRouter(object):
|
||||
def test_custom_router_add_route_should_be_used():
|
||||
check = []
|
||||
|
||||
def test_custom_router_add_route_should_be_used(self):
|
||||
check = []
|
||||
class CustomRouter(object):
|
||||
def add_route(self, uri_template, *args, **kwargs):
|
||||
check.append(uri_template)
|
||||
|
||||
class CustomRouter(object):
|
||||
def add_route(self, uri_template, *args, **kwargs):
|
||||
check.append(uri_template)
|
||||
def find(self, uri):
|
||||
pass
|
||||
|
||||
def find(self, uri):
|
||||
pass
|
||||
app = falcon.API(router=CustomRouter())
|
||||
app.add_route('/test', 'resource')
|
||||
|
||||
app = falcon.API(router=CustomRouter())
|
||||
app.add_route('/test', 'resource')
|
||||
assert len(check) == 1
|
||||
assert '/test' in check
|
||||
|
||||
assert len(check) == 1
|
||||
assert '/test' in check
|
||||
|
||||
def test_custom_router_find_should_be_used(self):
|
||||
def test_custom_router_find_should_be_used():
|
||||
|
||||
def resource(req, resp, **kwargs):
|
||||
resp.body = '{{"uri_template": "{0}"}}'.format(req.uri_template)
|
||||
def resource(req, resp, **kwargs):
|
||||
resp.body = '{{"uri_template": "{0}"}}'.format(req.uri_template)
|
||||
|
||||
class CustomRouter(object):
|
||||
def __init__(self):
|
||||
self.reached_backwards_compat = False
|
||||
class CustomRouter(object):
|
||||
def __init__(self):
|
||||
self.reached_backwards_compat = False
|
||||
|
||||
def find(self, uri):
|
||||
if uri == '/test/42':
|
||||
return resource, {'GET': resource}, {}, '/test/{id}'
|
||||
def find(self, uri):
|
||||
if uri == '/test/42':
|
||||
return resource, {'GET': resource}, {}, '/test/{id}'
|
||||
|
||||
if uri == '/test/42/no-uri-template':
|
||||
return resource, {'GET': resource}, {}, None
|
||||
if uri == '/test/42/no-uri-template':
|
||||
return resource, {'GET': resource}, {}, None
|
||||
|
||||
if uri == '/test/42/uri-template/backwards-compat':
|
||||
return resource, {'GET': resource}, {}
|
||||
if uri == '/test/42/uri-template/backwards-compat':
|
||||
return resource, {'GET': resource}, {}
|
||||
|
||||
if uri == '/404/backwards-compat':
|
||||
self.reached_backwards_compat = True
|
||||
return (None, None, None)
|
||||
if uri == '/404/backwards-compat':
|
||||
self.reached_backwards_compat = True
|
||||
return (None, None, None)
|
||||
|
||||
return None
|
||||
return None
|
||||
|
||||
router = CustomRouter()
|
||||
app = falcon.API(router=router)
|
||||
client = testing.TestClient(app)
|
||||
router = CustomRouter()
|
||||
app = falcon.API(router=router)
|
||||
client = testing.TestClient(app)
|
||||
|
||||
response = client.simulate_request(path='/test/42')
|
||||
assert response.content == b'{"uri_template": "/test/{id}"}'
|
||||
response = client.simulate_request(path='/test/42')
|
||||
assert response.content == b'{"uri_template": "/test/{id}"}'
|
||||
|
||||
response = client.simulate_request(path='/test/42/no-uri-template')
|
||||
assert response.content == b'{"uri_template": "None"}'
|
||||
response = client.simulate_request(path='/test/42/no-uri-template')
|
||||
assert response.content == b'{"uri_template": "None"}'
|
||||
|
||||
response = client.simulate_request(path='/test/42/uri-template/backwards-compat')
|
||||
assert response.content == b'{"uri_template": "None"}'
|
||||
response = client.simulate_request(path='/test/42/uri-template/backwards-compat')
|
||||
assert response.content == b'{"uri_template": "None"}'
|
||||
|
||||
for uri in ('/404', '/404/backwards-compat'):
|
||||
response = client.simulate_request(path=uri)
|
||||
assert not response.content
|
||||
assert response.status == falcon.HTTP_404
|
||||
for uri in ('/404', '/404/backwards-compat'):
|
||||
response = client.simulate_request(path=uri)
|
||||
assert not response.content
|
||||
assert response.status == falcon.HTTP_404
|
||||
|
||||
assert router.reached_backwards_compat
|
||||
assert router.reached_backwards_compat
|
||||
|
||||
def test_can_pass_additional_params_to_add_route(self):
|
||||
|
||||
check = []
|
||||
def test_can_pass_additional_params_to_add_route():
|
||||
|
||||
class CustomRouter(object):
|
||||
def add_route(self, uri_template, method_map, resource, name):
|
||||
self._index = {name: uri_template}
|
||||
check.append(name)
|
||||
check = []
|
||||
|
||||
def find(self, uri):
|
||||
pass
|
||||
class CustomRouter(object):
|
||||
def add_route(self, uri_template, method_map, resource, name):
|
||||
self._index = {name: uri_template}
|
||||
check.append(name)
|
||||
|
||||
app = falcon.API(router=CustomRouter())
|
||||
app.add_route('/test', 'resource', name='my-url-name')
|
||||
def find(self, uri):
|
||||
pass
|
||||
|
||||
assert len(check) == 1
|
||||
assert 'my-url-name' in check
|
||||
app = falcon.API(router=CustomRouter())
|
||||
app.add_route('/test', 'resource', name='my-url-name')
|
||||
|
||||
# Also as arg.
|
||||
app.add_route('/test', 'resource', 'my-url-name-arg')
|
||||
assert len(check) == 1
|
||||
assert 'my-url-name' in check
|
||||
|
||||
assert len(check) == 2
|
||||
assert 'my-url-name-arg' in check
|
||||
# Also as arg.
|
||||
app.add_route('/test', 'resource', 'my-url-name-arg')
|
||||
|
||||
def test_custom_router_takes_req_positional_argument(self):
|
||||
def responder(req, resp):
|
||||
resp.body = 'OK'
|
||||
assert len(check) == 2
|
||||
assert 'my-url-name-arg' in check
|
||||
|
||||
class CustomRouter(object):
|
||||
def find(self, uri, req):
|
||||
if uri == '/test' and isinstance(req, falcon.Request):
|
||||
return responder, {'GET': responder}, {}, None
|
||||
|
||||
router = CustomRouter()
|
||||
app = falcon.API(router=router)
|
||||
client = testing.TestClient(app)
|
||||
response = client.simulate_request(path='/test')
|
||||
assert response.content == b'OK'
|
||||
def test_custom_router_takes_req_positional_argument():
|
||||
def responder(req, resp):
|
||||
resp.body = 'OK'
|
||||
|
||||
def test_custom_router_takes_req_keyword_argument(self):
|
||||
def responder(req, resp):
|
||||
resp.body = 'OK'
|
||||
class CustomRouter(object):
|
||||
def find(self, uri, req):
|
||||
if uri == '/test' and isinstance(req, falcon.Request):
|
||||
return responder, {'GET': responder}, {}, None
|
||||
|
||||
class CustomRouter(object):
|
||||
def find(self, uri, req=None):
|
||||
if uri == '/test' and isinstance(req, falcon.Request):
|
||||
return responder, {'GET': responder}, {}, None
|
||||
router = CustomRouter()
|
||||
app = falcon.API(router=router)
|
||||
client = testing.TestClient(app)
|
||||
response = client.simulate_request(path='/test')
|
||||
assert response.content == b'OK'
|
||||
|
||||
router = CustomRouter()
|
||||
app = falcon.API(router=router)
|
||||
client = testing.TestClient(app)
|
||||
response = client.simulate_request(path='/test')
|
||||
assert response.content == b'OK'
|
||||
|
||||
def test_custom_router_takes_req_keyword_argument():
|
||||
def responder(req, resp):
|
||||
resp.body = 'OK'
|
||||
|
||||
class CustomRouter(object):
|
||||
def find(self, uri, req=None):
|
||||
if uri == '/test' and isinstance(req, falcon.Request):
|
||||
return responder, {'GET': responder}, {}, None
|
||||
|
||||
router = CustomRouter()
|
||||
app = falcon.API(router=router)
|
||||
client = testing.TestClient(app)
|
||||
response = client.simulate_request(path='/test')
|
||||
assert response.content == b'OK'
|
||||
|
|
|
@ -132,9 +132,15 @@ def test_user_regression_versioned_url():
|
|||
def test_user_regression_recipes():
|
||||
router = DefaultRouter()
|
||||
router.add_route(
|
||||
'/recipes/{activity}/{type_id}', {}, ResourceWithId(1))
|
||||
'/recipes/{activity}/{type_id}',
|
||||
{},
|
||||
ResourceWithId(1)
|
||||
)
|
||||
router.add_route(
|
||||
'/recipes/baking', {}, ResourceWithId(2))
|
||||
'/recipes/baking',
|
||||
{},
|
||||
ResourceWithId(2)
|
||||
)
|
||||
|
||||
resource, __, __, __ = router.find('/recipes/baking/4242')
|
||||
assert resource.resource_id == 1
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import mimeparse
|
||||
|
||||
|
||||
class TestDeps(object):
|
||||
def test_deps_mimeparse_correct_package():
|
||||
"""Ensure we are dealing with python-mimeparse, not mimeparse."""
|
||||
|
||||
def test_mimeparse_correct_package(self):
|
||||
"""Ensure we are dealing with python-mimeparse, not mimeparse."""
|
||||
tokens = mimeparse.__version__.split('.')
|
||||
msg = (
|
||||
'Incorrect dependency detected. Please install the '
|
||||
'"python-mimeparse" package instead of the "mimeparse" '
|
||||
'package.'
|
||||
)
|
||||
|
||||
tokens = mimeparse.__version__.split('.')
|
||||
msg = ('Incorrect dependency detected. Please install the '
|
||||
'"python-mimeparse" package instead of the "mimeparse" '
|
||||
'package.')
|
||||
|
||||
# NOTE(kgriffs): python-mimeparse starts at version 1.5.2,
|
||||
# whereas the mimeparse package is at version 0.1.4 at the time
|
||||
# of this writing.
|
||||
assert int(tokens[0]) > 0, msg
|
||||
# NOTE(kgriffs): python-mimeparse starts at version 1.5.2,
|
||||
# whereas the mimeparse package is at version 0.1.4 at the time
|
||||
# of this writing.
|
||||
assert int(tokens[0]) > 0, msg
|
||||
|
|
|
@ -1,379 +1,135 @@
|
|||
import pytest
|
||||
|
||||
import falcon
|
||||
import falcon.status_codes as status
|
||||
|
||||
|
||||
class TestError(object):
|
||||
def test_http_bad_request_no_title_and_desc(self):
|
||||
try:
|
||||
raise falcon.HTTPBadRequest()
|
||||
except falcon.HTTPBadRequest as e:
|
||||
assert status.HTTP_400 == e.title, \
|
||||
'The title should be ' + status.HTTP_400 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
@pytest.mark.parametrize('err, title', [
|
||||
(falcon.HTTPBadRequest, status.HTTP_400),
|
||||
(falcon.HTTPForbidden, status.HTTP_403),
|
||||
(falcon.HTTPConflict, status.HTTP_409),
|
||||
(falcon.HTTPLengthRequired, status.HTTP_411),
|
||||
(falcon.HTTPPreconditionFailed, status.HTTP_412),
|
||||
(falcon.HTTPRequestEntityTooLarge, status.HTTP_413),
|
||||
(falcon.HTTPUriTooLong, status.HTTP_414),
|
||||
(falcon.HTTPUnprocessableEntity, status.HTTP_422),
|
||||
(falcon.HTTPLocked, status.HTTP_423),
|
||||
(falcon.HTTPFailedDependency, status.HTTP_424),
|
||||
(falcon.HTTPPreconditionRequired, status.HTTP_428),
|
||||
(falcon.HTTPTooManyRequests, status.HTTP_429),
|
||||
(falcon.HTTPRequestHeaderFieldsTooLarge, status.HTTP_431),
|
||||
(falcon.HTTPUnavailableForLegalReasons, status.HTTP_451),
|
||||
(falcon.HTTPInternalServerError, status.HTTP_500),
|
||||
(falcon.HTTPBadGateway, status.HTTP_502),
|
||||
(falcon.HTTPServiceUnavailable, status.HTTP_503),
|
||||
(falcon.HTTPInsufficientStorage, status.HTTP_507),
|
||||
(falcon.HTTPLoopDetected, status.HTTP_508),
|
||||
(falcon.HTTPNetworkAuthenticationRequired, status.HTTP_511),
|
||||
])
|
||||
def test_with_default_title_and_desc(err, title):
|
||||
with pytest.raises(err) as e:
|
||||
raise err()
|
||||
|
||||
def test_http_bad_request_with_title_and_desc(self):
|
||||
try:
|
||||
raise falcon.HTTPBadRequest(title='Test', description='Testdescription')
|
||||
except falcon.HTTPBadRequest as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
assert e.value.title == title
|
||||
assert e.value.description is None
|
||||
|
||||
def test_http_unauthorized_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnauthorized()
|
||||
except falcon.HTTPUnauthorized as e:
|
||||
assert status.HTTP_401 == e.title, \
|
||||
'The title should be ' + status.HTTP_401 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
assert 'WWW-Authenticate' not in e.headers, \
|
||||
'Challenges should not be found in headers'
|
||||
if e.value.headers:
|
||||
assert 'Retry-After' not in e.value.headers
|
||||
|
||||
def test_http_unauthorized_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnauthorized(title='Test', description='Testdescription',
|
||||
challenges=['Testch'])
|
||||
except falcon.HTTPUnauthorized as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
assert 'Testch' == e.headers['WWW-Authenticate'], \
|
||||
'Challenges should be None'
|
||||
|
||||
def test_http_forbidden_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPForbidden()
|
||||
except falcon.HTTPForbidden as e:
|
||||
assert status.HTTP_403 == e.title, \
|
||||
'The title should be ' + status.HTTP_403 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
@pytest.mark.parametrize('err', [
|
||||
falcon.HTTPBadRequest,
|
||||
falcon.HTTPForbidden,
|
||||
falcon.HTTPConflict,
|
||||
falcon.HTTPLengthRequired,
|
||||
falcon.HTTPPreconditionFailed,
|
||||
falcon.HTTPPreconditionRequired,
|
||||
falcon.HTTPUriTooLong,
|
||||
falcon.HTTPUnprocessableEntity,
|
||||
falcon.HTTPLocked,
|
||||
falcon.HTTPFailedDependency,
|
||||
falcon.HTTPRequestHeaderFieldsTooLarge,
|
||||
falcon.HTTPInternalServerError,
|
||||
falcon.HTTPUnavailableForLegalReasons,
|
||||
falcon.HTTPBadGateway,
|
||||
falcon.HTTPInsufficientStorage,
|
||||
falcon.HTTPLoopDetected,
|
||||
falcon.HTTPNetworkAuthenticationRequired,
|
||||
])
|
||||
def test_with_title_and_desc(err):
|
||||
title = 'trace'
|
||||
desc = 'boom'
|
||||
|
||||
def test_http_forbidden_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPForbidden(title='Test', description='Testdescription')
|
||||
except falcon.HTTPForbidden as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
with pytest.raises(err) as e:
|
||||
raise err(title=title, description=desc)
|
||||
|
||||
def test_http_not_acceptable_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPNotAcceptable()
|
||||
except falcon.HTTPNotAcceptable as e:
|
||||
assert e.description is None, 'The description should be None'
|
||||
assert e.value.title == title
|
||||
assert e.value.description == desc
|
||||
|
||||
def test_http_not_acceptable_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPNotAcceptable(description='Testdescription')
|
||||
except falcon.HTTPNotAcceptable as e:
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
|
||||
def test_http_conflict_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPConflict()
|
||||
except falcon.HTTPConflict as e:
|
||||
assert status.HTTP_409 == e.title, \
|
||||
'The title should be ' + status.HTTP_409 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
@pytest.mark.parametrize('err', [
|
||||
falcon.HTTPServiceUnavailable,
|
||||
falcon.HTTPTooManyRequests,
|
||||
falcon.HTTPRequestEntityTooLarge,
|
||||
])
|
||||
def test_with_retry_after(err):
|
||||
with pytest.raises(err) as e:
|
||||
raise err(retry_after='123')
|
||||
|
||||
def test_http_conflict_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPConflict(title='Test', description='Testdescription')
|
||||
except falcon.HTTPConflict as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
assert e.value.headers['Retry-After'] == '123'
|
||||
|
||||
def test_http_length_required_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPLengthRequired()
|
||||
except falcon.HTTPLengthRequired as e:
|
||||
assert status.HTTP_411 == e.title, \
|
||||
'The title should be ' + status.HTTP_411 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_length_required_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPLengthRequired(title='Test', description='Testdescription')
|
||||
except falcon.HTTPLengthRequired as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
def test_http_unauthorized_no_title_and_desc_and_challenges():
|
||||
try:
|
||||
raise falcon.HTTPUnauthorized()
|
||||
except falcon.HTTPUnauthorized as e:
|
||||
assert status.HTTP_401 == e.title
|
||||
assert e.description is None
|
||||
assert 'WWW-Authenticate' not in e.headers
|
||||
|
||||
def test_http_precondition_failed_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPPreconditionFailed()
|
||||
except falcon.HTTPPreconditionFailed as e:
|
||||
assert status.HTTP_412 == e.title, \
|
||||
'The title should be ' + status.HTTP_412 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_precondition_failed_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPPreconditionFailed(title='Test', description='Testdescription')
|
||||
except falcon.HTTPPreconditionFailed as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
def test_http_unauthorized_with_title_and_desc_and_challenges():
|
||||
try:
|
||||
raise falcon.HTTPUnauthorized(
|
||||
title='Test',
|
||||
description='Testdescription',
|
||||
challenges=['Testch']
|
||||
)
|
||||
except falcon.HTTPUnauthorized as e:
|
||||
assert 'Test' == e.title
|
||||
assert 'Testdescription' == e.description
|
||||
assert 'Testch' == e.headers['WWW-Authenticate']
|
||||
|
||||
def test_http_request_entity_too_large_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPRequestEntityTooLarge()
|
||||
except falcon.HTTPRequestEntityTooLarge as e:
|
||||
assert status.HTTP_413 == e.title, \
|
||||
'The title should be ' + status.HTTP_413 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
assert 'Retry-After' not in e.headers, 'Retry-After should not be in the headers'
|
||||
|
||||
def test_http_request_entity_too_large_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPRequestEntityTooLarge(title='Test', description='Testdescription',
|
||||
retry_after=123)
|
||||
except falcon.HTTPRequestEntityTooLarge as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
assert '123' == e.headers['Retry-After'], \
|
||||
'Retry-After should be 123'
|
||||
def test_http_not_acceptable_no_title_and_desc_and_challenges():
|
||||
try:
|
||||
raise falcon.HTTPNotAcceptable()
|
||||
except falcon.HTTPNotAcceptable as e:
|
||||
assert e.description is None
|
||||
|
||||
def test_http_uri_too_long_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUriTooLong()
|
||||
except falcon.HTTPUriTooLong as e:
|
||||
assert status.HTTP_414 == e.title, \
|
||||
'The title should be ' + status.HTTP_414 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_uri_too_long_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUriTooLong(title='Test', description='Testdescription')
|
||||
except falcon.HTTPUriTooLong as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
def test_http_not_acceptable_with_title_and_desc_and_challenges():
|
||||
try:
|
||||
raise falcon.HTTPNotAcceptable(description='Testdescription')
|
||||
except falcon.HTTPNotAcceptable as e:
|
||||
assert 'Testdescription' == e.description
|
||||
|
||||
def test_http_unsupported_media_type_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnsupportedMediaType()
|
||||
except falcon.HTTPUnsupportedMediaType as e:
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_unsupported_media_type_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnsupportedMediaType(description='Testdescription')
|
||||
except falcon.HTTPUnsupportedMediaType as e:
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
def test_http_unsupported_media_type_no_title_and_desc_and_challenges():
|
||||
try:
|
||||
raise falcon.HTTPUnsupportedMediaType()
|
||||
except falcon.HTTPUnsupportedMediaType as e:
|
||||
assert e.description is None
|
||||
|
||||
def test_http_unprocessable_entity_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnprocessableEntity()
|
||||
except falcon.HTTPUnprocessableEntity as e:
|
||||
assert status.HTTP_422 == e.title, \
|
||||
'The title should be ' + status.HTTP_422 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_unprocessable_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnprocessableEntity(title='Test', description='Testdescription')
|
||||
except falcon.HTTPUnprocessableEntity as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
def test_http_unsupported_media_type_with_title_and_desc_and_challenges():
|
||||
try:
|
||||
raise falcon.HTTPUnsupportedMediaType(description='boom')
|
||||
except falcon.HTTPUnsupportedMediaType as e:
|
||||
assert e.description == 'boom'
|
||||
|
||||
def test_http_locked_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPLocked()
|
||||
except falcon.HTTPLocked as e:
|
||||
assert status.HTTP_423 == e.title, \
|
||||
'The title should be ' + status.HTTP_423 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_locked_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPLocked(title='Test', description='Testdescription')
|
||||
except falcon.HTTPLocked as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
|
||||
def test_http_failed_dependency_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPFailedDependency()
|
||||
except falcon.HTTPFailedDependency as e:
|
||||
assert status.HTTP_424 == e.title, \
|
||||
'The title should be ' + status.HTTP_424 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_failed_dependency_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPFailedDependency(title='Test', description='Testdescription')
|
||||
except falcon.HTTPFailedDependency as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
|
||||
def test_http_precondition_required_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPPreconditionRequired()
|
||||
except falcon.HTTPPreconditionRequired as e:
|
||||
assert status.HTTP_428 == e.title, \
|
||||
'The title should be ' + status.HTTP_428 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_precondition_required_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPPreconditionRequired(title='Test', description='Testdescription')
|
||||
except falcon.HTTPPreconditionRequired as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
|
||||
def test_http_too_many_requests_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPTooManyRequests()
|
||||
except falcon.HTTPTooManyRequests as e:
|
||||
assert status.HTTP_429 == e.title, \
|
||||
'The title should be ' + status.HTTP_429 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
assert 'Retry-After' not in e.headers, 'Retry-After should not be in the headers'
|
||||
|
||||
def test_http_too_many_requests_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPTooManyRequests(title='Test', description='Testdescription',
|
||||
retry_after=123)
|
||||
except falcon.HTTPTooManyRequests as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
assert '123' == e.headers['Retry-After'], 'Retry-After should be 123'
|
||||
|
||||
def test_http_request_header_fields_too_large_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPRequestHeaderFieldsTooLarge()
|
||||
except falcon.HTTPRequestHeaderFieldsTooLarge as e:
|
||||
assert status.HTTP_431 == e.title, \
|
||||
'The title should be ' + status.HTTP_431 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_request_header_fields_too_large_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPRequestHeaderFieldsTooLarge(title='Test',
|
||||
description='Testdescription')
|
||||
except falcon.HTTPRequestHeaderFieldsTooLarge as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
|
||||
def test_http_unavailable_for_legal_reasons_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnavailableForLegalReasons()
|
||||
except falcon.HTTPUnavailableForLegalReasons as e:
|
||||
assert status.HTTP_451 == e.title, \
|
||||
'The title should be ' + status.HTTP_451 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_unavailable_for_legal_reasons_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPUnavailableForLegalReasons(title='Test',
|
||||
description='Testdescription')
|
||||
except falcon.HTTPUnavailableForLegalReasons as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, \
|
||||
'Description should be "Testdescription"'
|
||||
|
||||
def test_http_internal_server_error_entity_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPInternalServerError()
|
||||
except falcon.HTTPInternalServerError as e:
|
||||
assert status.HTTP_500 == e.title, \
|
||||
'The title should be ' + status.HTTP_500 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_internal_server_error_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPInternalServerError(title='Test', description='Testdescription')
|
||||
except falcon.HTTPInternalServerError as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
|
||||
def test_http_bad_gateway_entity_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPBadGateway()
|
||||
except falcon.HTTPBadGateway as e:
|
||||
assert status.HTTP_502 == e.title, \
|
||||
'The title should be ' + status.HTTP_502 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_bad_gateway_entity_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPBadGateway(title='Test', description='Testdescription')
|
||||
except falcon.HTTPBadGateway as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
|
||||
def test_http_service_unavailable_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPServiceUnavailable()
|
||||
except falcon.HTTPServiceUnavailable as e:
|
||||
assert status.HTTP_503 == e.title, \
|
||||
'The title should be ' + status.HTTP_503 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
assert 'Retry-After' not in e.headers, 'Retry-After should not be in the headers'
|
||||
|
||||
def test_http_service_unavailable_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPServiceUnavailable(title='Test', description='Testdescription',
|
||||
retry_after=123)
|
||||
except falcon.HTTPServiceUnavailable as e:
|
||||
assert 'Test', e.title == 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
assert '123', e.headers['Retry-After'] == 'Retry-After should be 123'
|
||||
|
||||
def test_http_insufficient_storage_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPInsufficientStorage()
|
||||
except falcon.HTTPInsufficientStorage as e:
|
||||
assert status.HTTP_507 == e.title, \
|
||||
'The title should be ' + status.HTTP_507 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_insufficient_storage_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPInsufficientStorage(title='Test', description='Testdescription')
|
||||
except falcon.HTTPInsufficientStorage as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
|
||||
def test_http_loop_detected_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPLoopDetected()
|
||||
except falcon.HTTPLoopDetected as e:
|
||||
assert status.HTTP_508 == e.title, \
|
||||
'The title should be ' + status.HTTP_508 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_loop_detected_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPLoopDetected(title='Test', description='Testdescription')
|
||||
except falcon.HTTPLoopDetected as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
|
||||
def test_http_network_authentication_required_no_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPNetworkAuthenticationRequired()
|
||||
except falcon.HTTPNetworkAuthenticationRequired as e:
|
||||
assert status.HTTP_511 == e.title, \
|
||||
'The title should be ' + status.HTTP_511 + ', but it is: ' + e.title
|
||||
assert e.description is None, 'The description should be None'
|
||||
|
||||
def test_http_network_authentication_required_with_title_and_desc_and_challenges(self):
|
||||
try:
|
||||
raise falcon.HTTPNetworkAuthenticationRequired(title='Test',
|
||||
description='Testdescription')
|
||||
except falcon.HTTPNetworkAuthenticationRequired as e:
|
||||
assert 'Test' == e.title, 'Title should be "Test"'
|
||||
assert 'Testdescription' == e.description, 'Description should be "Testdescription"'
|
||||
|
||||
def test_http_error_repr(self):
|
||||
error = falcon.HTTPBadRequest()
|
||||
_repr = '<%s: %s>' % (error.__class__.__name__, error.status)
|
||||
assert error.__repr__() == _repr
|
||||
def test_http_error_repr():
|
||||
error = falcon.HTTPBadRequest()
|
||||
_repr = '<%s: %s>' % (error.__class__.__name__, error.status)
|
||||
assert error.__repr__() == _repr
|
||||
|
|
Loading…
Reference in New Issue