Skip to content

Commit

Permalink
Merge 4c2fcd3 into 72e427c
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaroeder committed Nov 16, 2016
2 parents 72e427c + 4c2fcd3 commit efe0cc6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ python:
- "2.7"
- "2.6"
- "pypy"
- "pypy3"
env:
- RIPOZO="ripozo"
- RIPOZO="git+git://github.com/vertical-knowledge/ripozo.git@master"
Expand All @@ -17,4 +16,4 @@ install:
script:
coverage run --source=flask_ripozo setup.py test
after_success:
coveralls
coveralls
19 changes: 10 additions & 9 deletions flask_ripozo/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def __getitem__(self, key):
def exception_handler(dispatcher, accepted_mimetypes, exc):
"""
Responsible for handling exceptions in the project.
This catches any RestException (from ripozo.exceptions)
and calls the format_exception class method on the adapter
class. It will appropriately set the status_code, response,
and content type for the exception.
This catches **any** Exception and calls the format_exception
class method on the adapter class. It will appropriately set
the status_code, response, and content type for the exception.
If you want an exception to set a status_code other than 500,
ensure that it has a ``status_code`` attribute.
:param FlaskDispatcher dispatcher: A FlaskDispatcher instance
used to format the exception
Expand All @@ -44,11 +46,10 @@ def exception_handler(dispatcher, accepted_mimetypes, exc):
:return: A flask Response object.
:rtype: flask.Response
"""
if isinstance(exc, RestException):
adapter_klass = dispatcher.get_adapter_for_type(accepted_mimetypes)
response, content_type, status_code = adapter_klass.format_exception(exc)
return Response(response=response, content_type=content_type, status=status_code)
raise exc
adapter_klass = dispatcher.get_adapter_for_type(accepted_mimetypes)
response, content_type, status_code = adapter_klass.format_exception(exc)
return Response(response=response, content_type=content_type,
status=status_code)


def get_request_query_body_args(request_obj):
Expand Down
27 changes: 4 additions & 23 deletions flask_ripozo_tests/unit/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ def fake(*args, **kwargs):
self.assertEqual(response.status_code, 600)
self.assertEqual(response.data.decode('utf8'), 'some body')

def test_flask_dispatch_wrapper_fail_restexception(self):
def test_flask_dispatch_wrapper_fail(self):
"""
Tests the response when their is a failure in
dispatching a request. In particular when a RestException
is raised.
Tests the response when there is a failure in
dispatching a request
"""
adapter_class = self.get_mock_adapter_class()

def fake(*args, **kwargs):
raise RestException
raise Exception

d = FlaskDispatcher(self.app)
d.register_adapters(adapter_class)
Expand All @@ -89,24 +88,6 @@ def fake(*args, **kwargs):
self.assertEqual(response.data.decode('utf8'), 'error')
self.assertEqual(response.content_type, 'fake')

def test_flask_dispatch_wrapper_fail(self):
"""
Tests the response when their is a failure in
dispatching a request that is not a RestException
"""
adapter_class = self.get_mock_adapter_class()

def fake(*args, **kwargs):
raise Exception

d = FlaskDispatcher(self.app)
d.register_adapters(adapter_class)
view_func = flask_dispatch_wrapper(d, fake)
self.assertEqual(view_func.__name__, fake.__name__)

with self.app.test_request_context('/myresource'):
self.assertRaises(Exception, view_func)

def test_base_url(self):
"""
Tests that the base_url always returns the
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules'
],
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist=py{26,27,33,34,py,py3}-ripozo{release,git}
# py3 removed due to flask 0.11 incompatibility
envlist=py{26,27,33,34,35,py}-ripozo{release,git}

[testenv]
deps=
Expand Down

0 comments on commit efe0cc6

Please sign in to comment.