Skip to content

Commit

Permalink
Merge pull request #490 from traylenator/unittest
Browse files Browse the repository at this point in the history
Use unittest.mock rather than mock
  • Loading branch information
akatsoulas authored Nov 24, 2023
2 parents 71e4af8 + 6529ab2 commit adea094
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
mock==2.0.0
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from mock import Mock, call, patch
from unittest.mock import Mock, call, patch

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, hmac
Expand Down
8 changes: 4 additions & 4 deletions tests/test_contrib_drf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mock
import unittest.mock

from django.core.exceptions import SuspiciousOperation
from django.test import RequestFactory, TestCase, override_settings
Expand All @@ -13,11 +13,11 @@ class TestDRF(TestCase):
@override_settings(OIDC_RP_CLIENT_ID="example_id")
@override_settings(OIDC_RP_CLIENT_SECRET="client_secret")
def setUp(self):
self.auth = OIDCAuthentication(backend=mock.Mock())
self.auth = OIDCAuthentication(backend=unittest.mock.Mock())
self.request = RequestFactory().get("/", HTTP_AUTHORIZATION="Bearer faketoken")

def test_authenticate_returns_none_if_no_access_token(self):
with mock.patch.object(self.auth, "get_access_token", return_value=None):
with unittest.mock.patch.object(self.auth, "get_access_token", return_value=None):
ret = self.auth.authenticate(self.request)
self.assertIsNone(ret)

Expand All @@ -32,7 +32,7 @@ def test_authenticate_raises_authenticationfailed_on_suspiciousoperation(self):
self.auth.authenticate(self.request)

def test_returns_user_and_token_if_backend_returns_user(self):
user = mock.Mock()
user = unittest.mock.Mock()
self.auth.backend.get_or_create_user.return_value = user
ret = self.auth.authenticate(self.request)
self.assertEqual(ret[0], user)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.test import Client, RequestFactory, TestCase, override_settings
from django.test.client import ClientHandler
from django.urls import path
from mock import MagicMock, patch
from unittest.mock import MagicMock, patch

from mozilla_django_oidc.middleware import SessionRefresh
from mozilla_django_oidc.urls import urlpatterns as orig_urlpatterns
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, override_settings
from django.test.client import RequestFactory
from mock import MagicMock
from unittest.mock import MagicMock

from mozilla_django_oidc.utils import (
absolutify,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.core.exceptions import SuspiciousOperation
from django.test import Client, RequestFactory, TestCase, override_settings
from django.urls import reverse
from mock import patch
from unittest.mock import patch

from mozilla_django_oidc import views

Expand Down

0 comments on commit adea094

Please sign in to comment.