Skip to content

Commit

Permalink
Improved assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
mongkok committed Aug 2, 2020
1 parent d743eef commit 28847cd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/test_middleware.py
Expand Up @@ -28,7 +28,7 @@ def test_authenticate(self):

self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
next_mock.assert_called_once_with(None, info_mock)
self.assertEqual(info_mock.context.user, self.user)

@override_jwt_settings(JWT_ALLOW_ANY_HANDLER=lambda *args: False)
Expand All @@ -44,8 +44,8 @@ def test_not_authenticate(self, authenticate_mock):

self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
authenticate_mock.assert_called_with(request=info_mock.context)
next_mock.assert_called_once_with(None, info_mock)
authenticate_mock.assert_called_once_with(request=info_mock.context)
self.assertIsInstance(info_mock.context.user, AnonymousUser)

@override_jwt_settings(JWT_ALLOW_ANY_HANDLER=lambda *args: False)
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_already_authenticated(self, authenticate_mock):

self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
next_mock.assert_called_once_with(None, info_mock)
authenticate_mock.assert_not_called()

@override_jwt_settings(JWT_ALLOW_ANY_HANDLER=lambda *args: True)
Expand All @@ -90,7 +90,7 @@ def test_allow_any(self):

self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
next_mock.assert_called_once_with(None, info_mock)
self.assertIsInstance(info_mock.context.user, AnonymousUser)

def test_authenticate_context(self):
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_authenticate(self):

self.middleware.resolve(next_mock, None, info_mock, **kwargs)

next_mock.assert_called_with(None, info_mock, **kwargs)
next_mock.assert_called_once_with(None, info_mock, **kwargs)
self.assertEqual(info_mock.context.user, self.user)

user = self.middleware.cached_authentication[tuple(info_mock.path)]
Expand All @@ -137,7 +137,7 @@ def test_authenticate_parent(self):
self.middleware.cached_authentication.insert(['0'], self.user)
self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
next_mock.assert_called_once_with(None, info_mock)
self.assertEqual(info_mock.context.user, self.user)

@override_jwt_settings(JWT_ALLOW_ARGUMENT=True)
Expand All @@ -147,7 +147,7 @@ def test_clear_authentication(self):

self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
next_mock.assert_called_once_with(None, info_mock)
self.assertIsInstance(info_mock.context.user, AnonymousUser)

@override_jwt_settings(JWT_ALLOW_ARGUMENT=True)
Expand All @@ -158,7 +158,7 @@ def test_clear_session_authentication(self):

self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
next_mock.assert_called_once_with(None, info_mock)
self.assertIsInstance(info_mock.context.user, AnonymousUser)

@override_jwt_settings(JWT_ALLOW_ARGUMENT=True)
Expand All @@ -168,7 +168,7 @@ def test_context_has_not_attr_user(self):

self.middleware.resolve(next_mock, None, info_mock)

next_mock.assert_called_with(None, info_mock)
next_mock.assert_called_once_with(None, info_mock)
self.assertFalse(hasattr(info_mock.context, 'user'))


Expand Down

0 comments on commit 28847cd

Please sign in to comment.