fix is_authenticated mocks
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user