Commit ac3373ca by Adam Palay

fix issue where orphaned openassessment blocks cause 500 errors on the…

fix issue where orphaned openassessment blocks cause 500 errors on the instructor dashboard (TNL-6797)
parent 79a9984b
...@@ -336,14 +336,27 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT ...@@ -336,14 +336,27 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT
response = self.client.get(self.url) response = self.client.get(self.url)
self.assertNotIn(ora_section, response.content) self.assertNotIn(ora_section, response.content)
course = ItemFactory.create( ItemFactory.create(parent_location=self.course.location, category="openassessment")
response = self.client.get(self.url)
self.assertIn(ora_section, response.content)
def test_open_response_assessment_page_orphan(self):
"""
Tests that the open responses tab loads if the course contains an
orphaned openassessment block
"""
# create non-orphaned openassessment block
ItemFactory.create(
parent_location=self.course.location, parent_location=self.course.location,
category="course", category="openassessment",
display_name="Test course", )
# create orphan
self.store.create_item(
self.user.id, self.course.id, 'openassessment', "orphan"
) )
ItemFactory.create(parent_location=course.location, category="openassessment")
response = self.client.get(self.url) response = self.client.get(self.url)
self.assertIn(ora_section, response.content) # assert we don't get a 500 error
self.assertEqual(200, response.status_code)
@ddt.ddt @ddt.ddt
......
...@@ -192,7 +192,13 @@ def instructor_dashboard_2(request, course_id): ...@@ -192,7 +192,13 @@ def instructor_dashboard_2(request, course_id):
if certs_enabled and access['admin']: if certs_enabled and access['admin']:
sections.append(_section_certificates(course)) sections.append(_section_certificates(course))
openassessment_blocks = modulestore().get_items(course_key, qualifiers={'category': 'openassessment'}) openassessment_blocks = modulestore().get_items(
course_key, qualifiers={'category': 'openassessment'}
)
# filter out orphaned openassessment blocks
openassessment_blocks = [
block for block in openassessment_blocks if block.parent is not None
]
if len(openassessment_blocks) > 0: if len(openassessment_blocks) > 0:
sections.append(_section_open_response_assessment(request, course, openassessment_blocks, access)) sections.append(_section_open_response_assessment(request, course, openassessment_blocks, access))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment