Merge pull request #4326 from edx/andya/fix-stud-1948
Fix user handling bug in split test module
This commit is contained in:
@@ -95,6 +95,20 @@ class PreviewModuleSystem(ModuleSystem): # pylint: disable=abstract-method
|
||||
return local_resource_url(block, uri)
|
||||
|
||||
|
||||
class StudioUserService(object):
|
||||
"""
|
||||
Provides a Studio implementation of the XBlock user service.
|
||||
"""
|
||||
|
||||
def __init__(self, request):
|
||||
super(StudioUserService, self).__init__()
|
||||
self._request = request
|
||||
|
||||
@property
|
||||
def user_id(self):
|
||||
return self._request.user.id
|
||||
|
||||
|
||||
def _preview_module_system(request, descriptor):
|
||||
"""
|
||||
Returns a ModuleSystem for the specified descriptor that is specialized for
|
||||
@@ -117,6 +131,8 @@ def _preview_module_system(request, descriptor):
|
||||
_studio_wrap_xblock,
|
||||
]
|
||||
|
||||
descriptor.runtime._services['user'] = StudioUserService(request) # pylint: disable=protected-access
|
||||
|
||||
return PreviewModuleSystem(
|
||||
static_url=settings.STATIC_URL,
|
||||
# TODO (cpennington): Do we want to track how instructors are using the preview problems?
|
||||
|
||||
@@ -343,6 +343,7 @@ class SplitTestModule(SplitTestFields, XModule, StudioEditableModule):
|
||||
|
||||
@XBlock.needs('user_tags') # pylint: disable=abstract-method
|
||||
@XBlock.wants('partitions')
|
||||
@XBlock.wants('user')
|
||||
class SplitTestDescriptor(SplitTestFields, SequenceDescriptor, StudioEditableDescriptor):
|
||||
# the editing interface can be the same as for sequences -- just a container
|
||||
module_class = SplitTestModule
|
||||
@@ -553,7 +554,8 @@ class SplitTestDescriptor(SplitTestFields, SequenceDescriptor, StudioEditableDes
|
||||
for group in user_partition.groups:
|
||||
str_group_id = unicode(group.id)
|
||||
if str_group_id not in self.group_id_to_child:
|
||||
self._create_vertical_for_group(group, request.user.id)
|
||||
user_id = self.runtime.service(self, 'user').user_id
|
||||
self._create_vertical_for_group(group, user_id)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
|
||||
@@ -3,7 +3,8 @@ PageObjects related to the AcidBlock
|
||||
"""
|
||||
|
||||
from bok_choy.page_object import PageObject
|
||||
from bok_choy.promise import EmptyPromise, BrokenPromise, Promise
|
||||
from bok_choy.promise import Promise
|
||||
from .utils import wait_for_xblock_initialization
|
||||
|
||||
class AcidView(PageObject):
|
||||
"""
|
||||
@@ -25,16 +26,11 @@ class AcidView(PageObject):
|
||||
|
||||
def is_browser_on_page(self):
|
||||
|
||||
def _is_finished_loading():
|
||||
# Wait for the xblock javascript to finish initializing
|
||||
is_done = self.browser.execute_script("return $({!r}).data('initialized')".format(self.context_selector))
|
||||
return (is_done, is_done)
|
||||
|
||||
# First make sure that an element with the view-container class is present on the page,
|
||||
# and then wait to make sure that the xblock has finished initializing.
|
||||
return (
|
||||
self.q(css='{} .acid-block'.format(self.context_selector)).present and
|
||||
Promise(_is_finished_loading, 'Finished initializing the xblock.').fulfill()
|
||||
wait_for_xblock_initialization(self, self.context_selector)
|
||||
)
|
||||
|
||||
def test_passed(self, test_selector):
|
||||
|
||||
17
common/test/acceptance/pages/xblock/utils.py
Normal file
17
common/test/acceptance/pages/xblock/utils.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Utility methods useful for XBlock page tests.
|
||||
"""
|
||||
from bok_choy.promise import Promise
|
||||
from selenium.webdriver.common.action_chains import ActionChains
|
||||
|
||||
|
||||
def wait_for_xblock_initialization(page, xblock_css):
|
||||
"""
|
||||
Wait for the xblock with the given CSS to finish initializing.
|
||||
"""
|
||||
def _is_finished_loading():
|
||||
# Wait for the xblock javascript to finish initializing
|
||||
is_done = page.browser.execute_script("return $({!r}).data('initialized')".format(xblock_css))
|
||||
return (is_done, is_done)
|
||||
|
||||
return Promise(_is_finished_loading, 'Finished initializing the xblock.').fulfill()
|
||||
@@ -6,19 +6,20 @@ import json
|
||||
import os
|
||||
from unittest import skip, skipUnless
|
||||
|
||||
from ..fixtures.course import CourseFixture, XBlockFixtureDesc
|
||||
from xmodule.partitions.partitions import Group, UserPartition
|
||||
from bok_choy.promise import Promise
|
||||
|
||||
from ..fixtures.course import CourseFixture, XBlockFixtureDesc
|
||||
from ..pages.studio.component_editor import ComponentEditorView
|
||||
from ..pages.studio.settings_advanced import AdvancedSettingsPage
|
||||
from ..pages.studio.settings_group_configurations import GroupConfigurationsPage
|
||||
from ..pages.studio.auto_auth import AutoAuthPage
|
||||
from test_studio_container import ContainerBase
|
||||
from ..pages.studio.utils import add_advanced_component
|
||||
from xmodule.partitions.partitions import Group, UserPartition
|
||||
from bok_choy.promise import Promise
|
||||
|
||||
from ..pages.xblock.utils import wait_for_xblock_initialization
|
||||
from .helpers import UniqueCourseTest
|
||||
|
||||
from test_studio_container import ContainerBase
|
||||
|
||||
|
||||
class SplitTest(ContainerBase):
|
||||
"""
|
||||
@@ -147,6 +148,11 @@ class SplitTest(ContainerBase):
|
||||
The case of a split test with invalid configuration (missing group).
|
||||
"""
|
||||
container = self.create_poorly_configured_split_instance()
|
||||
|
||||
# Wait for the xblock to be fully initialized so that the add button is rendered
|
||||
wait_for_xblock_initialization(self, '.xblock[data-block-type="split_test"]')
|
||||
|
||||
# Click the add button and verify that the groups were added on the page
|
||||
container.add_missing_groups()
|
||||
self.verify_groups(container, ['alpha', 'gamma'], ['beta'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user