refactor: reuse services and wrappers between XBlocks (fixed)

This re-applies commit 36cc415 with handling an invalid context_key in the
`PartitionService`. It can happen when rendering a `LibraryContentBlock` in
Studio because this service is initialized by the modulestore when validating
an XBlock to gather its error messages in the `studio_xblock_wrapper`.
This commit is contained in:
Agrendalath
2023-07-13 19:22:06 +02:00
committed by Piotr Surowiec
parent d79625ee72
commit 92b684004e
20 changed files with 256 additions and 248 deletions

View File

@@ -212,17 +212,17 @@ class VerticalBlockTestCase(BaseVerticalBlockTest):
"""
Test the rendering of the student and public view.
"""
self.course.runtime._runtime_services['bookmarks'] = Mock()
self.course.runtime._services['bookmarks'] = Mock()
now = datetime.now(pytz.UTC)
self.vertical.due = now + timedelta(days=days)
if view == STUDENT_VIEW:
self.course.runtime._runtime_services['user'] = StubUserService(user=Mock(username=self.username))
self.course.runtime._runtime_services['completion'] = StubCompletionService(
self.course.runtime._services['user'] = StubUserService(user=Mock(username=self.username))
self.course.runtime._services['completion'] = StubCompletionService(
enabled=True,
completion_value=completion_value
)
elif view == PUBLIC_VIEW:
self.course.runtime._runtime_services['user'] = StubUserService(user=AnonymousUser())
self.course.runtime._services['user'] = StubUserService(user=AnonymousUser())
html = self.course.runtime.render(
self.vertical, view, self.default_context if context is None else context