diff --git a/src/illumidesk/grades/handlers.py b/src/illumidesk/grades/handlers.py index e9d0db55..6c96fb3a 100644 --- a/src/illumidesk/grades/handlers.py +++ b/src/illumidesk/grades/handlers.py @@ -15,10 +15,6 @@ class SendGradesHandler(BaseHandler): Defines a POST method to process grades submission for a specific assignment within a course """ - @property - def authenticator_class(self): - return self.settings.get('authenticator_class', None) - async def post(self, course_id: str, assignment_name: str) -> None: """ Receives a request with the course name and the assignment name as path parameters @@ -41,7 +37,7 @@ async def post(self, course_id: str, assignment_name: str) -> None: lti_grade_sender = None # check lti version by the authenticator setting - if self.authenticator_class == LTI11Authenticator: + if isinstance(self.authenticator, LTI11Authenticator) or self.authenticator is LTI11Authenticator: lti_grade_sender = LTIGradeSender(course_id, assignment_name) else: auth_state = await self.current_user.get_auth_state() diff --git a/src/tests/illumidesk/grades/test_lms_grades_handler.py b/src/tests/illumidesk/grades/test_lms_grades_handler.py index fe29b094..7c05021e 100644 --- a/src/tests/illumidesk/grades/test_lms_grades_handler.py +++ b/src/tests/illumidesk/grades/test_lms_grades_handler.py @@ -5,7 +5,6 @@ from unittest.mock import AsyncMock from unittest.mock import Mock from unittest.mock import patch -from unittest.mock import PropertyMock from illumidesk.authenticators.authenticator import LTI11Authenticator from illumidesk.authenticators.authenticator import LTI13Authenticator @@ -15,7 +14,7 @@ @pytest.fixture() def send_grades_handler_lti11(make_mock_request_handler): - jhub_settings = {'authenticator_class': LTI11Authenticator} + jhub_settings = {'authenticator': LTI11Authenticator} request_handler = make_mock_request_handler(RequestHandler, **jhub_settings) send_grades_handler = SendGradesHandler(request_handler.application, request_handler.request) return send_grades_handler @@ -23,7 +22,7 @@ def send_grades_handler_lti11(make_mock_request_handler): @pytest.fixture() def send_grades_handler_lti13(make_mock_request_handler): - jhub_settings = {'authenticator_class': LTI13Authenticator} + jhub_settings = {'authenticator': LTI13Authenticator} async def user_auth_state(): return [] @@ -43,7 +42,6 @@ def mock_user(): @pytest.mark.asyncio -@patch('illumidesk.grades.senders.LTI13GradeSender.send_grades') @patch('tornado.web.RequestHandler.write') async def test_SendGradesHandler_calls_authenticator_class_property( mock_write, send_grades_handler_lti13, send_grades_handler_lti11 @@ -54,18 +52,14 @@ async def test_SendGradesHandler_calls_authenticator_class_property( with patch('illumidesk.grades.handlers.LTI13GradeSender') as mock_sender: instance = mock_sender.return_value instance.send_grades = AsyncMock() - mock_authenticator_class = PropertyMock(return_value=LTI13Authenticator) - mock_sender.authenticator_class = mock_authenticator_class await send_grades_handler_lti13.post('course_example', 'assignment_test') - mock_authenticator_class.called + assert mock_sender.called - with patch('illumidesk.grades.handlers.LTIGradeSender') as mock_sender: - instance = mock_sender.return_value - instance.send_grades = AsyncMock() - mock_authenticator_class = PropertyMock(return_value=LTI13Authenticator) - mock_sender.authenticator_class = mock_authenticator_class - await send_grades_handler_lti11.post('course_example', 'assignment_test') - mock_authenticator_class.called + with patch('illumidesk.grades.handlers.LTIGradeSender') as mocklti11_sender: + instance = mocklti11_sender.return_value + instance.send_grades = AsyncMock() + await send_grades_handler_lti11.post('course_example', 'assignment_test') + mocklti11_sender.called @pytest.mark.asyncio @@ -76,8 +70,8 @@ async def test_SendGradesHandler_authenticator_class_gets_its_value_from_setting """ Does the SendGradesHandler.authenticator_class property gets its value from jhub settings? """ - assert send_grades_handler_lti11.authenticator_class == LTI11Authenticator - assert send_grades_handler_lti13.authenticator_class == LTI13Authenticator + assert send_grades_handler_lti11.authenticator == LTI11Authenticator + assert send_grades_handler_lti13.authenticator == LTI13Authenticator @pytest.mark.asyncio