Skip to content

Commit

Permalink
Merge pull request #381 from cfra/fix/test-assert-is-none
Browse files Browse the repository at this point in the history
tests: Check for None with assertIsNone
  • Loading branch information
akatsoulas committed Mar 21, 2021
2 parents 10476f5 + 23226de commit 378ecb0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setUp(self):

def test_missing_request_arg(self):
"""Test authentication returns `None` when `request` is not provided."""
self.assertEqual(self.backend.authenticate(request=None), None)
self.assertIsNone(self.backend.authenticate(request=None))

@patch('mozilla_django_oidc.auth.OIDCAuthenticationBackend.verify_token')
@patch('mozilla_django_oidc.auth.requests')
Expand All @@ -77,7 +77,7 @@ def test_invalid_token(self, request_mock, token_mock):
'accesss_token': 'access_token'
}
request_mock.post.return_value = post_json_mock
self.assertEqual(self.backend.authenticate(request=auth_request), None)
self.assertIsNone(self.backend.authenticate(request=auth_request))

@override_settings(OIDC_ALLOW_UNSECURED_JWT=True)
def test_allowed_unsecured_token(self):
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_get_user(self):
def test_get_invalid_user(self):
"""Test get_user method with non existing user."""

self.assertEqual(self.backend.get_user(user_id=1), None)
self.assertIsNone(self.backend.get_user(user_id=1))

@override_settings(ROOT_URLCONF='tests.namespaced_urls')
@override_settings(OIDC_AUTHENTICATION_CALLBACK_URL='namespace:oidc_authentication_callback')
Expand Down Expand Up @@ -644,7 +644,7 @@ def test_create_user_disabled(self, request_mock, jws_mock):
'access_token': 'access_granted'
}
request_mock.post.return_value = post_json_mock
self.assertEqual(self.backend.authenticate(request=auth_request), None)
self.assertIsNone(self.backend.authenticate(request=auth_request))

@patch('mozilla_django_oidc.auth.OIDCAuthenticationBackend._verify_jws')
@patch('mozilla_django_oidc.auth.requests')
Expand Down Expand Up @@ -759,7 +759,7 @@ def test_duplicate_emails_exact(self, request_mock, jws_mock):
'access_token': 'access_granted'
}
request_mock.post.return_value = post_json_mock
self.assertEqual(self.backend.authenticate(request=auth_request), None)
self.assertIsNone(self.backend.authenticate(request=auth_request))

@override_settings(OIDC_USE_NONCE=False)
@patch('mozilla_django_oidc.auth.OIDCAuthenticationBackend._verify_jws')
Expand Down Expand Up @@ -787,7 +787,7 @@ def test_duplicate_emails_case_mismatch(self, request_mock, jws_mock):
'access_token': 'access_granted'
}
request_mock.post.return_value = post_json_mock
self.assertEqual(self.backend.authenticate(request=auth_request), None)
self.assertIsNone(self.backend.authenticate(request=auth_request))

@override_settings(OIDC_USE_NONCE=False)
@patch('mozilla_django_oidc.auth.OIDCAuthenticationBackend.update_user')
Expand Down Expand Up @@ -822,7 +822,7 @@ def update_user(user, claims):
'access_token': 'access_granted'
}
request_mock.post.return_value = post_json_mock
self.assertEqual(self.backend.authenticate(request=auth_request), None)
self.assertIsNone(self.backend.authenticate(request=auth_request))

self.assertEqual(User.objects.get().first_name, 'a_username')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_contrib_drf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
def test_authenticate_returns_none_if_no_access_token(self):
with mock.patch.object(self.auth, 'get_access_token', return_value=None):
ret = self.auth.authenticate(self.request)
self.assertEqual(ret, None)
self.assertIsNone(ret)

def test_authenticate_raises_authenticationfailed_if_backend_returns_no_user(self):
self.auth.backend.get_or_create_user.return_value = None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_state_dictionary_without_nonce_format(self):
self.assertTrue(isinstance(self.request.session['oidc_states'][state], dict))

# Test nonce
self.assertEqual(self.request.session['oidc_states'][state]['nonce'], None)
self.assertIsNone(self.request.session['oidc_states'][state]['nonce'])

# Test added_on timestamp
self.assertTrue(isinstance(self.request.session['oidc_states'][state]['added_on'], float))
Expand Down
6 changes: 3 additions & 3 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def build_request(self, next_url):
def test_no_param(self):
req = self.factory.get('/')
next_url = views.get_next_url(req, 'next')
self.assertEqual(next_url, None)
self.assertIsNone(next_url)

def test_non_next_param(self):
req = self.factory.get('/', data={'redirectto': '/foo'})
Expand Down Expand Up @@ -331,7 +331,7 @@ def test_bad_urls(self):
req = self.build_request(next_url=url)
next_url = views.get_next_url(req, 'next')

self.assertEqual(next_url, None)
self.assertIsNone(next_url)

def test_https(self):
# If the request is for HTTPS and the next url is HTTPS, then that
Expand All @@ -353,7 +353,7 @@ def test_https(self):
)
self.assertEqual(req.is_secure(), True)
next_url = views.get_next_url(req, 'next')
self.assertEqual(next_url, None)
self.assertIsNone(next_url)

@override_settings(OIDC_REDIRECT_REQUIRE_HTTPS=False)
def test_redirect_https_not_required(self):
Expand Down

0 comments on commit 378ecb0

Please sign in to comment.