fix issue where orphaned openassessment blocks cause 500 errors on the instructor dashboard (TNL-6797)

This commit is contained in:
Adam Palay
2017-03-30 14:21:32 -04:00
parent 79a9984bd9
commit ac3373ca77
2 changed files with 26 additions and 7 deletions

View File

@@ -336,15 +336,28 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT
response = self.client.get(self.url)
self.assertNotIn(ora_section, response.content)
course = ItemFactory.create(
parent_location=self.course.location,
category="course",
display_name="Test course",
)
ItemFactory.create(parent_location=course.location, category="openassessment")
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,
category="openassessment",
)
# create orphan
self.store.create_item(
self.user.id, self.course.id, 'openassessment', "orphan"
)
response = self.client.get(self.url)
# assert we don't get a 500 error
self.assertEqual(200, response.status_code)
@ddt.ddt
class TestInstructorDashboardPerformance(ModuleStoreTestCase, LoginEnrollmentTestCase, XssTestMixin):

View File

@@ -192,7 +192,13 @@ def instructor_dashboard_2(request, course_id):
if certs_enabled and access['admin']:
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:
sections.append(_section_open_response_assessment(request, course, openassessment_blocks, access))