Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fix: Determine what authenticator is used to submit grades (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
netoisc authored Jul 28, 2020
1 parent b4bf8b5 commit ff952fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/illumidesk/grades/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
26 changes: 10 additions & 16 deletions src/tests/illumidesk/grades/test_lms_grades_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,15 +14,15 @@

@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


@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 []
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ff952fc

Please sign in to comment.