From afb311ff51ca5d4c777334206d7f9a049cc056a7 Mon Sep 17 00:00:00 2001 From: Andy Armstrong Date: Mon, 7 Jul 2014 16:40:17 -0400 Subject: [PATCH] Fix user handling bug in split test module STUD-1948 --- cms/djangoapps/contentstore/views/preview.py | 16 ++++++++++++++++ common/lib/xmodule/xmodule/split_test_module.py | 4 +++- common/test/acceptance/pages/xblock/acid.py | 10 +++------- common/test/acceptance/pages/xblock/utils.py | 17 +++++++++++++++++ .../acceptance/tests/test_studio_split_test.py | 16 +++++++++++----- 5 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 common/test/acceptance/pages/xblock/utils.py diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 8401935c3d..6404864587 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -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? diff --git a/common/lib/xmodule/xmodule/split_test_module.py b/common/lib/xmodule/xmodule/split_test_module.py index 35154f7466..40da667840 100644 --- a/common/lib/xmodule/xmodule/split_test_module.py +++ b/common/lib/xmodule/xmodule/split_test_module.py @@ -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: diff --git a/common/test/acceptance/pages/xblock/acid.py b/common/test/acceptance/pages/xblock/acid.py index 9b9218ebe7..3cb073ecc2 100644 --- a/common/test/acceptance/pages/xblock/acid.py +++ b/common/test/acceptance/pages/xblock/acid.py @@ -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): diff --git a/common/test/acceptance/pages/xblock/utils.py b/common/test/acceptance/pages/xblock/utils.py new file mode 100644 index 0000000000..534dabc5f0 --- /dev/null +++ b/common/test/acceptance/pages/xblock/utils.py @@ -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() diff --git a/common/test/acceptance/tests/test_studio_split_test.py b/common/test/acceptance/tests/test_studio_split_test.py index 1edea80928..93a6015b9e 100644 --- a/common/test/acceptance/tests/test_studio_split_test.py +++ b/common/test/acceptance/tests/test_studio_split_test.py @@ -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'])