diff --git a/common/djangoapps/student/tests/test_authz.py b/common/djangoapps/student/tests/test_authz.py index 048ec34c5f..03b3f9e3b3 100644 --- a/common/djangoapps/student/tests/test_authz.py +++ b/common/djangoapps/student/tests/test_authz.py @@ -113,7 +113,10 @@ class CreatorGroupTest(TestCase): def test_add_user_to_group_requires_authenticated(self): with self.assertRaises(PermissionDenied): - with mock.patch('django.contrib.auth.models.User.is_authenticated') as mock_is_auth: + with mock.patch( + 'django.contrib.auth.models.User.is_authenticated', + new_callable=mock.PropertyMock + ) as mock_is_auth: mock_is_auth.return_value = False add_users(self.admin, CourseCreatorRole(), self.user) @@ -129,7 +132,10 @@ class CreatorGroupTest(TestCase): def test_remove_user_from_group_requires_authenticated(self): with self.assertRaises(PermissionDenied): - with mock.patch('django.contrib.auth.models.User.is_authenticated') as mock_is_auth: + with mock.patch( + 'django.contrib.auth.models.User.is_authenticated', + new_callable=mock.PropertyMock + ) as mock_is_auth: mock_is_auth.return_value = False remove_users(self.admin, CourseCreatorRole(), self.user) diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 1958491851..594c2e546c 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -512,9 +512,9 @@ class ViewsTestCase(ModuleStoreTestCase): self.assertEqual(EcommerceService().is_enabled(AnonymousUser()), False) def test_user_groups(self): - # depreciated function + # deprecated function mock_user = MagicMock() - mock_user.is_authenticated.return_value = False + type(mock_user).is_authenticated = PropertyMock(return_value=False) self.assertEqual(views.user_groups(mock_user), []) def test_get_redirect_url(self): diff --git a/lms/djangoapps/lti_provider/tests/test_users.py b/lms/djangoapps/lti_provider/tests/test_users.py index e9bf32354d..4461ea9297 100644 --- a/lms/djangoapps/lti_provider/tests/test_users.py +++ b/lms/djangoapps/lti_provider/tests/test_users.py @@ -8,7 +8,7 @@ from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied from django.test import TestCase from django.test.client import RequestFactory -from mock import MagicMock, patch +from mock import MagicMock, patch, PropertyMock import lti_provider.users as users from lti_provider.models import LtiConsumer, LtiUser @@ -124,7 +124,7 @@ class AuthenticateLtiUserTest(TestCase): def test_authentication_with_unauthenticated_user(self, create_user, switch_user): lti_user = self.create_lti_user_model() self.request.user = lti_user.edx_user - with patch('django.contrib.auth.models.User.is_authenticated') as mock_is_auth: + with patch('django.contrib.auth.models.User.is_authenticated', new_callable=PropertyMock) as mock_is_auth: mock_is_auth.return_value = False users.authenticate_lti_user(self.request, self.lti_user_id, self.lti_consumer) self.assertFalse(create_user.called)