Skip to content

Commit

Permalink
Fix tests that use abort
Browse files Browse the repository at this point in the history
Get rid of the helper method. Use unittest.mock’s side_effect
instead.
  • Loading branch information
Glutexo committed Jan 15, 2019
1 parent ee3a9fe commit 6f1f9bd
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
from werkzeug.exceptions import Forbidden


def _abort():
raise Forbidden


class ApiOperationTestCase(TestCase):
"""
Test the API operation decorator that increments the request counter with every
Expand Down Expand Up @@ -271,7 +267,7 @@ class AuthRequiresIdentityTestCase(TestCase):
def _dummy_view_func(self):
pass

@patch("app.auth.abort", wraps=_abort)
@patch("app.auth.abort", side_effect=Forbidden)
@patch("app.auth._validate")
@patch("app.auth._pick_identity", side_effect=InvalidIdentityError)
def test_request_is_aborted_with_forbidden_if_identity_pick_fails(
Expand All @@ -281,7 +277,7 @@ def test_request_is_aborted_with_forbidden_if_identity_pick_fails(
self._dummy_view_func()
abort.assert_called_once_with(Forbidden.code)

@patch("app.auth.abort", wraps=_abort)
@patch("app.auth.abort", side_effect=Forbidden)
@patch("app.auth._validate")
@patch("app.auth._pick_identity", side_effect=InvalidIdentityError)
def test_request_context_is_untouched_if_identity_pick_fails(
Expand All @@ -292,7 +288,7 @@ def test_request_context_is_untouched_if_identity_pick_fails(
self._dummy_view_func()
self.assertIs(original_identity, request_ctx_stack.top.identity)

@patch("app.auth.abort", wraps=_abort)
@patch("app.auth.abort", side_effect=Forbidden)
@patch("app.auth._validate", side_effect=InvalidIdentityError)
@patch("app.auth._pick_identity")
def test_request_is_aborted_with_forbidden_if_identity_validation_fails(
Expand All @@ -302,7 +298,7 @@ def test_request_is_aborted_with_forbidden_if_identity_validation_fails(
self._dummy_view_func()
abort.assert_called_once_with(Forbidden.code)

@patch("app.auth.abort", wraps=_abort)
@patch("app.auth.abort", side_effect=Forbidden)
@patch("app.auth._validate", side_effect=InvalidIdentityError)
@patch("app.auth._pick_identity")
def test_request_context_is_untouched_if_identity_validation_fails(
Expand Down

0 comments on commit 6f1f9bd

Please sign in to comment.