Fix issue with multiple responses for a single user returned by generate_report_data

Before this fix if an XBlock's generate_report_data method returned multiple
responses for the same user from a single user state, the report generator would
end up overwriting each response over the previous one such that only the last
response would be preserved.
This commit is contained in:
Kshitij Sobti
2018-12-25 23:18:56 +05:30
parent 0c06bd3c20
commit a76c6dca87
2 changed files with 43 additions and 23 deletions

View File

@@ -558,24 +558,35 @@ class TestProblemResponsesReport(TestReportMixin, InstructorTaskModuleTestCase):
"""
self.define_option_problem(u'Problem1')
self.submit_student_answer(self.student.username, u'Problem1', ['Option 1'])
state = {'some': 'state', 'more': 'state!'}
state1 = {'some': 'state1', 'more': 'state1!'}
state2 = {'some': 'state2', 'more': 'state2!'}
mock_generate_report_data.return_value = iter([
('student', state),
('student', state1),
('student', state2),
])
student_data, _ = ProblemResponses._build_student_data(
user_id=self.instructor.id,
course_key=self.course.id,
usage_key_str=str(self.course.location),
)
self.assertEquals(len(student_data), 1)
self.assertEquals(len(student_data), 2)
self.assertDictContainsSubset({
'username': 'student',
'location': 'test_course > Section > Subsection > Problem1',
'block_key': 'i4x://edx/1.23x/problem/Problem1',
'title': 'Problem1',
'some': 'state',
'more': 'state!',
'some': 'state1',
'more': 'state1!',
}, student_data[0])
self.assertDictContainsSubset({
'username': 'student',
'location': 'test_course > Section > Subsection > Problem1',
'block_key': 'i4x://edx/1.23x/problem/Problem1',
'title': 'Problem1',
'some': 'state2',
'more': 'state2!',
}, student_data[1])
self.assertEquals(student_data[0]['state'], student_data[1]['state'])
def test_build_student_data_for_block_with_real_generate_report_data(self):
"""