Skip to content

Commit

Permalink
feat: Adding python3.12 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
awais786 committed Feb 29, 2024
1 parent dd9b5f7 commit f0417ef
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lti_consumer/tests/unit/plugin/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tests for LTI 1.3 endpoint views.
"""
import json
from unittest.mock import patch, Mock
from unittest.mock import patch, Mock, MagicMock

import ddt

Expand Down Expand Up @@ -173,7 +173,7 @@ def setUp(self):
compat_patcher = patch("lti_consumer.plugin.views.compat")
self.addCleanup(compat_patcher.stop)
self.compat = compat_patcher.start()
course = Mock(name="course")
course = MagicMagicMagicMock(name="course")
course.display_name_with_default = "course_display_name"
course.display_org_with_default = "course_display_org"
self.compat.get_course_by_id.return_value = course
Expand Down Expand Up @@ -379,7 +379,7 @@ def _setup_deep_linking(self, user_role='staff'):
self.config.save()

self.compat.get_user_role.return_value = user_role
mock_user_service = Mock()
mock_user_service = MagicMock()
mock_user_service.get_external_user_id.return_value = 2
self.xblock.runtime.service.return_value = mock_user_service

Expand Down Expand Up @@ -513,7 +513,7 @@ def test_callback_endpoint_dl_content_launch(self, mock_contentitem_set):
self.assertEqual(response.status_code, 200)
self.assertIn("http://tool.example/launch", content)

@ddt.data(Mock(), None)
@ddt.data(MagicMock(), None)
@patch('lti_consumer.api.get_deep_linking_data')
def test_callback_endpoint_dl_content_launch_database_config(self, dl_value, mock_lti_dl):
self._setup_deep_linking(user_role="staff")
Expand Down Expand Up @@ -667,7 +667,7 @@ def setUp(self):
self.config.save()
self.url = reverse('lti_consumer:lti_consumer.access_token', args=[str(self.config.config_id)])
# Patch settings calls to LMS method
self.mock_client = Mock()
self.mock_client = MagicMagicMock()
get_lti_consumer_patcher = patch(
'lti_consumer.plugin.views.LtiConfiguration.get_lti_consumer',
return_value=self.mock_client
Expand Down Expand Up @@ -801,7 +801,7 @@ def test_missing_required_claim(self):
"""
Check that 400 is returned when required attributes are missing in the request
"""
self.mock_client.access_token = Mock(side_effect=MissingRequiredClaim())
self.mock_client.access_token = MagicMock(side_effect=MissingRequiredClaim())
response = self.client.post(self.url)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {'error': 'invalid_request'})
Expand All @@ -810,12 +810,12 @@ def test_token_errors(self):
"""
Check invalid_grant error is returned when the token is invalid
"""
self.mock_client.access_token = Mock(side_effect=MalformedJwtToken())
self.mock_client.access_token = MagicMock(side_effect=MalformedJwtToken())
response = self.client.post(self.url)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {'error': 'invalid_grant'})

self.mock_client.access_token = Mock(side_effect=TokenSignatureExpired())
self.mock_client.access_token = MagicMock(side_effect=TokenSignatureExpired())
response = self.client.post(self.url)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {'error': 'invalid_grant'})
Expand All @@ -824,12 +824,12 @@ def test_client_credential_errors(self):
"""
Check invalid_client error is returned when the client credentials are wrong
"""
self.mock_client.access_token = Mock(side_effect=NoSuitableKeys())
self.mock_client.access_token = MagicMock(side_effect=NoSuitableKeys())
response = self.client.post(self.url)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {'error': 'invalid_client'})

self.mock_client.access_token = Mock(side_effect=UnknownClientId())
self.mock_client.access_token = MagicMock(side_effect=UnknownClientId())
response = self.client.post(self.url)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {'error': 'invalid_client'})
Expand All @@ -838,7 +838,7 @@ def test_unsupported_grant_error(self):
"""
Check unsupported_grant_type is returned when the grant type is wrong
"""
self.mock_client.access_token = Mock(side_effect=UnsupportedGrantType())
self.mock_client.access_token = MagicMock(side_effect=UnsupportedGrantType())
response = self.client.post(self.url)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {'error': 'unsupported_grant_type'})

0 comments on commit f0417ef

Please sign in to comment.