def test_score_set_user_conversion(self): """ Ensure that the score_set handler properly calls the user_by_anonymous_id method to convert from an anonymized ID to a user object """ submissions_score_set_handler(None, **SUBMISSION_SET_KWARGS) self.get_user_mock.assert_called_once_with('anonymous_id')
def test_score_set_bad_user(self): """ Ensure that, on receipt of a score_set signal from the Submissions API that has an invalid user ID, the courseware model does not generate a signal. """ self.get_user_mock = self.setup_patch('courseware.models.user_by_anonymous_id', None) submissions_score_set_handler(None, **SUBMISSION_SET_KWARGS) self.signal_mock.assert_not_called()
def test_score_set_bad_user(self): """ Ensure that, on receipt of a score_set signal from the Submissions API that has an invalid user ID, the courseware model does not generate a signal. """ self.get_user_mock = self.setup_patch( 'courseware.models.user_by_anonymous_id', None) submissions_score_set_handler(None, **SUBMISSION_SET_KWARGS) self.signal_mock.assert_not_called()
def test_score_set_missing_kwarg(self): """ Ensure that, on receipt of a score_set signal from the Submissions API that does not have the correct kwargs, the courseware model does not generate a signal. """ for missing in SUBMISSION_SET_KWARGS: kwargs = SUBMISSION_SET_KWARGS.copy() del kwargs[missing] submissions_score_set_handler(None, **kwargs) self.signal_mock.assert_not_called()
def test_score_set_signal_handler(self): """ Ensure that, on receipt of a score_set signal from the Submissions API, the courseware model correctly converts it to a score_changed signal """ submissions_score_set_handler(None, **SUBMISSION_SET_KWARGS) expected_set_kwargs = { 'sender': None, 'points_possible': 10, 'points_earned': 5, 'user_id': 42, 'course_id': 'CourseID', 'usage_id': 'i4x://org/course/usage/123456' } self.signal_mock.assert_called_once_with(**expected_set_kwargs)