Merge pull request #14827 from edx/robrap/LEARNER-418
Refactor more tests to use course home page.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
LMS Course Home page object
|
||||
"""
|
||||
|
||||
from collections import OrderedDict
|
||||
from bok_choy.page_object import PageObject
|
||||
|
||||
from .bookmarks import BookmarksPage
|
||||
@@ -81,7 +82,7 @@ class CourseOutlinePage(PageObject):
|
||||
You can use these titles in `go_to_section` to navigate to the section.
|
||||
"""
|
||||
# Dict to store the result
|
||||
outline_dict = dict()
|
||||
outline_dict = OrderedDict()
|
||||
|
||||
section_titles = self._section_titles()
|
||||
|
||||
@@ -89,7 +90,7 @@ class CourseOutlinePage(PageObject):
|
||||
for sec_index, sec_title in enumerate(section_titles):
|
||||
|
||||
if len(section_titles) < 1:
|
||||
self.warning("Could not find subsections for '{0}'".format(sec_title))
|
||||
raise ValueError("Could not find subsections for '{0}'".format(sec_title))
|
||||
else:
|
||||
# Add one to convert list index (starts at 0) to CSS index (starts at 1)
|
||||
outline_dict[sec_title] = self._subsection_titles(sec_index + 1)
|
||||
@@ -123,7 +124,7 @@ class CourseOutlinePage(PageObject):
|
||||
|
||||
def go_to_section(self, section_title, subsection_title):
|
||||
"""
|
||||
Go to the section in the courseware.
|
||||
Go to the section/subsection in the courseware.
|
||||
Every section must have at least one subsection, so specify
|
||||
both the section and subsection title.
|
||||
|
||||
@@ -132,14 +133,14 @@ class CourseOutlinePage(PageObject):
|
||||
"""
|
||||
section_index = self._section_title_to_index(section_title)
|
||||
if section_index is None:
|
||||
return
|
||||
raise ValueError("Could not find section '{0}'".format(section_title))
|
||||
|
||||
try:
|
||||
subsection_index = self._subsection_titles(section_index + 1).index(subsection_title)
|
||||
except ValueError:
|
||||
msg = "Could not find subsection '{0}' in section '{1}'".format(subsection_title, section_title)
|
||||
self.warning(msg)
|
||||
return
|
||||
raise ValueError("Could not find subsection '{0}' in section '{1}'".format(
|
||||
subsection_title, section_title
|
||||
))
|
||||
|
||||
# Convert list indices (start at zero) to CSS indices (start at 1)
|
||||
subsection_css = self.SUBSECTION_SELECTOR.format(section_index + 1, subsection_index + 1)
|
||||
@@ -149,6 +150,30 @@ class CourseOutlinePage(PageObject):
|
||||
|
||||
self._wait_for_course_section(section_title, subsection_title)
|
||||
|
||||
def go_to_section_by_index(self, section_index, subsection_index):
|
||||
"""
|
||||
Go to the section/subsection in the courseware.
|
||||
Every section must have at least one subsection, so specify both the
|
||||
section and subsection indices.
|
||||
|
||||
Arguments:
|
||||
section_index: A 0-based index of the section to navigate to.
|
||||
subsection_index: A 0-based index of the subsection to navigate to.
|
||||
|
||||
"""
|
||||
try:
|
||||
section_title = self._section_titles()[section_index]
|
||||
except IndexError:
|
||||
raise ValueError("Section index '{0}' is out of range.".format(section_index))
|
||||
try:
|
||||
subsection_title = self._subsection_titles(section_index + 1)[subsection_index]
|
||||
except IndexError:
|
||||
raise ValueError("Subsection index '{0}' in section index '{1}' is out of range.".format(
|
||||
subsection_index, section_index
|
||||
))
|
||||
|
||||
self.go_to_section(section_title, subsection_title)
|
||||
|
||||
def _section_title_to_index(self, section_title):
|
||||
"""
|
||||
Get the section title index given the section title.
|
||||
@@ -156,7 +181,7 @@ class CourseOutlinePage(PageObject):
|
||||
try:
|
||||
section_index = self._section_titles().index(section_title)
|
||||
except ValueError:
|
||||
self.warning("Could not find section '{0}'".format(section_title))
|
||||
raise ValueError("Could not find section '{0}'".format(section_title))
|
||||
|
||||
return section_index
|
||||
|
||||
|
||||
@@ -580,7 +580,7 @@ class CourseNavPage(PageObject):
|
||||
"""
|
||||
return self.REMOVE_SPAN_TAG_RE.search(element.get_attribute('innerHTML')).groups()[0].strip()
|
||||
|
||||
# TODO: TNL-6546: Remove from here and move to course_home.py:CourseOutlinePage
|
||||
# TODO: TNL-6546: Remove. This is no longer needed.
|
||||
@property
|
||||
def active_subsection_url(self):
|
||||
"""
|
||||
|
||||
@@ -10,6 +10,7 @@ from common.test.acceptance.tests.helpers import UniqueCourseTest, TestWithSearc
|
||||
from common.test.acceptance.pages.studio.auto_auth import AutoAuthPage
|
||||
from common.test.acceptance.pages.studio.overview import CourseOutlinePage as StudioCourseOutlinePage
|
||||
from common.test.acceptance.pages.studio.library import StudioLibraryContentEditor, StudioLibraryContainerXBlockWrapper
|
||||
from common.test.acceptance.pages.lms.course_home import CourseHomePage
|
||||
from common.test.acceptance.pages.lms.courseware import CoursewarePage
|
||||
from common.test.acceptance.pages.lms.library import LibraryContentXBlockWrapper
|
||||
from common.test.acceptance.pages.common.logout import LogoutPage
|
||||
@@ -128,7 +129,9 @@ class LibraryContentTestBase(UniqueCourseTest):
|
||||
self.courseware_page.visit()
|
||||
paragraphs = self.courseware_page.q(css='.course-content p').results
|
||||
if not paragraphs:
|
||||
self.courseware_page.q(css='.menu-item a').results[0].click()
|
||||
course_home_page = CourseHomePage(self.browser, self.course_id)
|
||||
course_home_page.visit()
|
||||
course_home_page.outline.go_to_section_by_index(0, 0)
|
||||
block_id = block_id if block_id is not None else self.lib_block.locator
|
||||
#pylint: disable=attribute-defined-outside-init
|
||||
self.library_content_page = LibraryContentXBlockWrapper(self.browser, block_id)
|
||||
|
||||
@@ -624,11 +624,10 @@ class CoursewareMultipleVerticalsTest(CoursewareMultipleVerticalsTestBase):
|
||||
self.course_home_page.visit()
|
||||
|
||||
self.course_home_page.outline.go_to_section('Test Section 1', 'Test Subsection 1,1')
|
||||
subsection_url = self.courseware_page.nav.active_subsection_url
|
||||
subsection_url = self.browser.current_url
|
||||
url_part_list = subsection_url.split('/')
|
||||
self.assertEqual(len(url_part_list), 9)
|
||||
|
||||
course_id = url_part_list[4]
|
||||
course_id = url_part_list[-5]
|
||||
chapter_id = url_part_list[-3]
|
||||
subsection_id = url_part_list[-2]
|
||||
problem1_page = CoursewareSequentialTabPage(
|
||||
|
||||
@@ -730,19 +730,21 @@ class StaffLockTest(CourseOutlineTest):
|
||||
Given I have a course with two sections
|
||||
When I enable explicit staff lock on one section
|
||||
And I click the View Live button to switch to staff view
|
||||
Then I see two sections in the sidebar
|
||||
And I visit the course home with the outline
|
||||
Then I see two sections in the outline
|
||||
And when I switch the view mode to student view
|
||||
Then I see one section in the sidebar
|
||||
Then I see one section in the outline
|
||||
"""
|
||||
self.course_outline_page.visit()
|
||||
self.course_outline_page.add_section_from_top_button()
|
||||
self.course_outline_page.section_at(1).set_staff_lock(True)
|
||||
self.course_outline_page.view_live()
|
||||
courseware = CoursewarePage(self.browser, self.course_id)
|
||||
courseware.wait_for_page()
|
||||
self.assertEqual(courseware.num_sections, 2)
|
||||
StaffCoursewarePage(self.browser, self.course_id).set_staff_view_mode('Student')
|
||||
self.assertEqual(courseware.num_sections, 1)
|
||||
|
||||
course_home_page = CourseHomePage(self.browser, self.course_id)
|
||||
course_home_page.visit()
|
||||
self.assertEqual(course_home_page.outline.num_sections, 2)
|
||||
course_home_page.preview.set_staff_view_mode('Student')
|
||||
self.assertEqual(course_home_page.outline.num_sections, 1)
|
||||
|
||||
def test_locked_subsections_do_not_appear_in_lms(self):
|
||||
"""
|
||||
@@ -750,18 +752,20 @@ class StaffLockTest(CourseOutlineTest):
|
||||
Given I have a course with two subsections
|
||||
When I enable explicit staff lock on one subsection
|
||||
And I click the View Live button to switch to staff view
|
||||
Then I see two subsections in the sidebar
|
||||
And I visit the course home with the outline
|
||||
Then I see two subsections in the outline
|
||||
And when I switch the view mode to student view
|
||||
Then I see one section in the sidebar
|
||||
Then I see one subsection in the outline
|
||||
"""
|
||||
self.course_outline_page.visit()
|
||||
self.course_outline_page.section_at(0).subsection_at(1).set_staff_lock(True)
|
||||
self.course_outline_page.view_live()
|
||||
courseware = CoursewarePage(self.browser, self.course_id)
|
||||
courseware.wait_for_page()
|
||||
self.assertEqual(courseware.num_subsections, 2)
|
||||
StaffCoursewarePage(self.browser, self.course_id).set_staff_view_mode('Student')
|
||||
self.assertEqual(courseware.num_subsections, 1)
|
||||
|
||||
course_home_page = CourseHomePage(self.browser, self.course_id)
|
||||
course_home_page.visit()
|
||||
self.assertEqual(course_home_page.outline.num_subsections, 2)
|
||||
course_home_page.preview.set_staff_view_mode('Student')
|
||||
self.assertEqual(course_home_page.outline.num_subsections, 1)
|
||||
|
||||
def test_toggling_staff_lock_on_section_does_not_publish_draft_units(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user