fix xblock urls for verticals
TNL-5003
This commit is contained in:
@@ -5,6 +5,8 @@ Utility methods for unit tests.
|
||||
import filecmp
|
||||
from path import Path as path
|
||||
|
||||
from xblock.reference.user_service import XBlockUser, UserService
|
||||
|
||||
|
||||
def directories_equal(directory1, directory2):
|
||||
"""
|
||||
@@ -24,3 +26,16 @@ def directories_equal(directory1, directory2):
|
||||
return True
|
||||
|
||||
return compare_dirs(path(directory1), path(directory2))
|
||||
|
||||
|
||||
class StubUserService(UserService):
|
||||
"""
|
||||
Stub UserService for testing the sequence module.
|
||||
"""
|
||||
def get_current_user(self):
|
||||
"""
|
||||
Implements abstract method for getting the current user.
|
||||
"""
|
||||
user = XBlockUser()
|
||||
user.opt_attrs['edx-platform.username'] = 'bilbo'
|
||||
return user
|
||||
|
||||
@@ -7,27 +7,14 @@ import ddt
|
||||
from django.utils.timezone import now
|
||||
from freezegun import freeze_time
|
||||
from mock import Mock
|
||||
from xblock.reference.user_service import XBlockUser, UserService
|
||||
from xmodule.tests import get_test_system
|
||||
from xmodule.tests.helpers import StubUserService
|
||||
from xmodule.tests.xml import XModuleXmlImportTest
|
||||
from xmodule.tests.xml import factories as xml
|
||||
from xmodule.x_module import STUDENT_VIEW
|
||||
from xmodule.seq_module import SequenceModule
|
||||
|
||||
|
||||
class StubUserService(UserService):
|
||||
"""
|
||||
Stub UserService for testing the sequence module.
|
||||
"""
|
||||
def get_current_user(self):
|
||||
"""
|
||||
Implements abstract method for getting the current user.
|
||||
"""
|
||||
user = XBlockUser()
|
||||
user.opt_attrs['edx-platform.username'] = 'test user'
|
||||
return user
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class SequenceBlockTestCase(XModuleXmlImportTest):
|
||||
"""
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
"""
|
||||
Tests for vertical module.
|
||||
"""
|
||||
|
||||
import ddt
|
||||
from mock import Mock
|
||||
from fs.memoryfs import MemoryFS
|
||||
from xmodule.tests import get_test_system
|
||||
from xmodule.tests.helpers import StubUserService
|
||||
from xmodule.tests.xml import XModuleXmlImportTest
|
||||
from xmodule.tests.xml import factories as xml
|
||||
from xmodule.x_module import STUDENT_VIEW, AUTHOR_VIEW
|
||||
@@ -41,6 +43,7 @@ class BaseVerticalBlockTest(XModuleXmlImportTest):
|
||||
self.default_context = {"bookmarked": False, "username": self.username}
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class VerticalBlockTestCase(BaseVerticalBlockTest):
|
||||
"""
|
||||
Tests for the VerticalBlock.
|
||||
@@ -54,11 +57,21 @@ class VerticalBlockTestCase(BaseVerticalBlockTest):
|
||||
self.assertIn('bookmarked', content)
|
||||
self.assertIn('show_bookmark_button', content)
|
||||
|
||||
def test_render_student_view(self):
|
||||
@ddt.unpack
|
||||
@ddt.data(
|
||||
{'context': None},
|
||||
{'context': {}}
|
||||
)
|
||||
def test_render_student_view(self, context):
|
||||
"""
|
||||
Test the rendering of the student view.
|
||||
"""
|
||||
html = self.module_system.render(self.vertical, STUDENT_VIEW, self.default_context).content
|
||||
self.module_system._services['bookmarks'] = Mock() # pylint: disable=protected-access
|
||||
self.module_system._services['user'] = StubUserService() # pylint: disable=protected-access
|
||||
|
||||
html = self.module_system.render(
|
||||
self.vertical, STUDENT_VIEW, self.default_context if context is None else context
|
||||
).content
|
||||
self.assertIn(self.test_html_1, html)
|
||||
self.assertIn(self.test_html_2, html)
|
||||
self.assert_bookmark_info_in(html)
|
||||
|
||||
@@ -20,6 +20,7 @@ log = logging.getLogger(__name__)
|
||||
CLASS_PRIORITY = ['video', 'problem']
|
||||
|
||||
|
||||
@XBlock.needs('user', 'bookmarks')
|
||||
class VerticalBlock(SequenceFields, XModuleFields, StudioEditableBlock, XmlParserMixin, MakoTemplateBlockBase, XBlock):
|
||||
"""
|
||||
Layout XBlock for rendering subblocks vertically.
|
||||
@@ -41,7 +42,14 @@ class VerticalBlock(SequenceFields, XModuleFields, StudioEditableBlock, XmlParse
|
||||
fragment = Fragment()
|
||||
contents = []
|
||||
|
||||
child_context = {} if not context else copy(context)
|
||||
if context:
|
||||
child_context = copy(context)
|
||||
else:
|
||||
child_context = {
|
||||
'bookmarked': self.runtime.service(self, 'bookmarks').is_bookmarked(usage_key=self.location), # pylint: disable=no-member
|
||||
'username': self.runtime.service(self, 'user').get_current_user().opt_attrs['edx-platform.username']
|
||||
}
|
||||
|
||||
child_context['child_of_vertical'] = True
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
Reference in New Issue
Block a user