From 3fd86614b050f678bb062dade6d82bb968264616 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 9 Jan 2017 11:33:51 -0500 Subject: [PATCH] sub_api get_score return value is a dict This access pattern was wrong, and was causing errors in production. I've included an additional happy-path test. --- lms/djangoapps/grades/tasks.py | 2 +- lms/djangoapps/grades/tests/test_tasks.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/grades/tasks.py b/lms/djangoapps/grades/tasks.py index ce6c7e4878..c58647adc4 100644 --- a/lms/djangoapps/grades/tasks.py +++ b/lms/djangoapps/grades/tasks.py @@ -146,7 +146,7 @@ def _has_database_updated_with_new_score( if api_score is None: # Same case as the initial 'if' above, for submissions-specific scores return score_deleted - reported_modified_time = api_score.created_at + reported_modified_time = api_score['created_at'] else: reported_modified_time = score.modified diff --git a/lms/djangoapps/grades/tests/test_tasks.py b/lms/djangoapps/grades/tests/test_tasks.py index a04c2e8a11..2cfde45b3c 100644 --- a/lms/djangoapps/grades/tests/test_tasks.py +++ b/lms/djangoapps/grades/tests/test_tasks.py @@ -235,6 +235,18 @@ class RecalculateSubsectionGradeTest(ModuleStoreTestCase): ) self._assert_retry_called(mock_retry) + @patch('lms.djangoapps.grades.tasks.recalculate_subsection_grade_v2.retry') + def test_retry_subsection_grade_on_update_not_complete_sub(self, mock_retry): + self.set_up_course() + with patch('lms.djangoapps.grades.tasks.sub_api.get_score') as mock_sub_score: + mock_sub_score.return_value = { + 'created_at': datetime.utcnow().replace(tzinfo=pytz.UTC) - timedelta(days=1) + } + self._apply_recalculate_subsection_grade( + mock_score=MagicMock(module_type='openassessment') + ) + self._assert_retry_called(mock_retry) + @patch('lms.djangoapps.grades.tasks.recalculate_subsection_grade_v2.retry') def test_retry_subsection_grade_on_no_score(self, mock_retry): self.set_up_course()