Commit 79cd3210 by cahrens Committed by Andy Armstrong

Bok choy test improvements.

parent fc5b94ee
......@@ -7,6 +7,7 @@ from bok_choy.page_object import PageObject
from .course_page import CoursePage
import os
from bok_choy.promise import EmptyPromise
from ...tests.helpers import select_option_by_text, get_selected_option_text, get_options
class InstructorDashboardPage(CoursePage):
......@@ -86,10 +87,11 @@ class MembershipPageCohortManagementSection(PageObject):
The cohort management subsection of the Membership section of the Instructor dashboard.
"""
url = None
csv_browse_button_selector = '.csv-upload #file-upload-form-file'
csv_upload_button_selector = '.csv-upload #file-upload-form-submit'
content_group_selector = '.input-group-other option'
no_content_group_button = '.cohort-management-details-association-course input.radio-no'
csv_browse_button_selector_css = '.csv-upload #file-upload-form-file'
csv_upload_button_selector_css = '.csv-upload #file-upload-form-submit'
content_group_selector_css = 'select.input-cohort-group-association'
no_content_group_button_css = '.cohort-management-details-association-course input.radio-no'
select_content_group_button_css = '.cohort-management-details-association-course input.radio-yes'
def is_browser_on_page(self):
return self.q(css='.cohort-management.membership-section').present
......@@ -151,7 +153,8 @@ class MembershipPageCohortManagementSection(PageObject):
lambda: cohort_name in self.get_cohorts(),
"Waiting for cohort selector to populate"
).fulfill()
self.q(css=self._bounded_selector("#cohort-select option")).filter(
# Note: can't use Select to select by text because the count is also included in the displayed text.
self._get_cohort_options().filter(
lambda el: self._cohort_name(el.text) == cohort_name
).first.click()
......@@ -194,17 +197,21 @@ class MembershipPageCohortManagementSection(PageObject):
css=self._bounded_selector("#cohort-management-group-add-students")
).results[0].get_attribute("value")
def select_studio_group_settings(self):
"""
When no content groups have been defined, a messages appears with a link
to go to Studio group settings. This method assumes the link is visible and clicks it.
"""
return self.q(css=self._bounded_selector("a.link-to-group-settings")).first.click()
def get_all_content_groups(self):
"""
Returns all the content groups available for associating with the cohort currently being edited.
"""
select = self.q(css=self._bounded_selector(self.content_group_selector))
groups = []
for option in select:
if option.text != "":
groups.append(option.text)
return groups
selector_query = self.q(css=self._bounded_selector(self.content_group_selector_css))
return [
option.text for option in get_options(selector_query) if option.text != ""
]
def get_cohort_associated_content_group(self):
"""
......@@ -212,11 +219,10 @@ class MembershipPageCohortManagementSection(PageObject):
If no content group is associated, returns None.
"""
self.select_cohort_settings()
radio_button = self.q(css=self._bounded_selector(self.no_content_group_button)).results[0]
radio_button = self.q(css=self._bounded_selector(self.no_content_group_button_css)).results[0]
if radio_button.is_selected():
return None
option_selector = self.q(css=self._bounded_selector(self.content_group_selector))
return option_selector.filter(lambda el: el.is_selected())[0].text
return get_selected_option_text(self.q(css=self._bounded_selector(self.content_group_selector_css)))
def set_cohort_associated_content_group(self, content_group=None, select_settings=True):
"""
......@@ -227,7 +233,7 @@ class MembershipPageCohortManagementSection(PageObject):
if select_settings:
self.select_cohort_settings()
if content_group is None:
self.q(css=self._bounded_selector(self.no_content_group_button)).first.click()
self.q(css=self._bounded_selector(self.no_content_group_button_css)).first.click()
else:
self._select_associated_content_group(content_group)
self.q(css=self._bounded_selector("div.form-actions .action-save")).first.click()
......@@ -236,8 +242,19 @@ class MembershipPageCohortManagementSection(PageObject):
"""
Selects the specified content group from the selector. Assumes that content_group is not None.
"""
option_selector = self.q(css=self._bounded_selector(self.content_group_selector))
option_selector.filter(lambda el: el.text == content_group).first.click()
self.select_content_group_radio_button()
select_option_by_text(
self.q(css=self._bounded_selector(self.content_group_selector_css)), content_group
)
def select_content_group_radio_button(self):
"""
Clicks the radio button for "No Content Group" association.
Returns whether or not the radio button is in the selected state after the click.
"""
radio_button = self.q(css=self._bounded_selector(self.select_content_group_button_css)).results[0]
radio_button.click()
return radio_button.is_selected()
def select_cohort_settings(self):
"""
......@@ -250,7 +267,6 @@ class MembershipPageCohortManagementSection(PageObject):
Returns an array of messages related to modifying cohort settings. If wait_for_messages
is True, will wait for a message to appear.
"""
# Note that the class name should change because it is no longer a "create"
title_css = "div.cohort-management-settings .message-" + type + " .message-title"
detail_css = "div.cohort-management-settings .message-" + type + " .summary-item"
......@@ -330,9 +346,9 @@ class MembershipPageCohortManagementSection(PageObject):
if cvs_upload_toggle:
cvs_upload_toggle.click()
path = InstructorDashboardPage.get_asset_path(filename)
file_input = self.q(css=self._bounded_selector(self.csv_browse_button_selector)).results[0]
file_input = self.q(css=self._bounded_selector(self.csv_browse_button_selector_css)).results[0]
file_input.send_keys(path)
self.q(css=self._bounded_selector(self.csv_upload_button_selector)).first.click()
self.q(css=self._bounded_selector(self.csv_upload_button_selector_css)).first.click()
class MembershipPageAutoEnrollSection(PageObject):
......
......@@ -16,6 +16,7 @@ from ...fixtures.course import CourseFixture
from ...pages.lms.auto_auth import AutoAuthPage
from ...pages.lms.instructor_dashboard import InstructorDashboardPage, DataDownloadPage
from ...pages.studio.settings_advanced import AdvancedSettingsPage
from ...pages.studio.settings_group_configurations import GroupConfigurationsPage
import uuid
......@@ -114,8 +115,15 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
"No content groups exist. Create a content group to associate with cohort groups. Create a content group",
self.cohort_management_page.get_cohort_related_content_group_message()
)
# TODO: test can't select radio button
# TODO: test link to Studio
self.assertFalse(self.cohort_management_page.select_content_group_radio_button())
self.cohort_management_page.select_studio_group_settings()
group_settings_page = GroupConfigurationsPage(
self.browser,
self.course_info['org'],
self.course_info['number'],
self.course_info['run']
)
group_settings_page.wait_for_page()
def test_link_to_studio(self):
"""
......@@ -603,9 +611,12 @@ class CohortContentGroupAssociationTest(UniqueCourseTest, CohortTestMixin):
self.cohort_management_page.wait_for_page()
self.cohort_management_page.select_cohort(new_cohort)
self.assertEqual("Deleted Content Group", self.cohort_management_page.get_cohort_associated_content_group())
self.assertEquals(["Bananas", "Pears", "Some content group that's been deleted"], self.cohort_management_page.get_all_content_groups())
self.assertEquals(
["Bananas", "Pears", "Deleted Content Group"],
self.cohort_management_page.get_all_content_groups()
)
self.assertEqual(
"The selected content group has been deleted, you may wish to reassign this cohort group.",
"The previously selected content group was deleted. Select another content group.",
self.cohort_management_page.get_cohort_related_content_group_message()
)
self.cohort_management_page.set_cohort_associated_content_group("Pears")
......
......@@ -12,6 +12,7 @@ from bok_choy.web_app_test import WebAppTest
from opaque_keys.edx.locator import CourseLocator
from xmodule.partitions.partitions import UserPartition
from xmodule.partitions.tests.test_partitions import MockUserPartitionScheme
from selenium.webdriver.support.select import Select
def skip_if_browser(browser):
......@@ -172,6 +173,29 @@ def enable_css_animations(page):
""")
def select_option_by_text(select_browser_query, option_text):
"""
Chooses an option within a select by text (helper method for Select's select_by_visible_text method).
"""
select = Select(select_browser_query.first.results[0])
select.select_by_visible_text(option_text)
def get_selected_option_text(select_browser_query):
"""
Returns the text value for the first selected option within a select.
"""
select = Select(select_browser_query.first.results[0])
return select.first_selected_option.text
def get_options(select_browser_query):
"""
Returns all the options for the given select.
"""
return Select(select_browser_query.first.results[0]).options
class UniqueCourseTest(WebAppTest):
"""
Test that provides a unique course ID.
......
......@@ -77,7 +77,7 @@
<% } else { // no content groups available %>
<div class="input-group-other">
<div class="msg-inline">
<p class="copy-error"><i class="icon icon-warning-sign"></i><%- gettext("No content groups exist. Create a content group to associate with cohort groups.") %> <a href="<%- studioGroupConfigurationsUrl %>"><%- gettext("Create a content group") %></a></p>
<p class="copy-error"><i class="icon icon-warning-sign"></i><%- gettext("No content groups exist. Create a content group to associate with cohort groups.") %> <a class="link-to-group-settings" href="<%- studioGroupConfigurationsUrl %>"><%- gettext("Create a content group") %></a></p>
</div>
</div>
<% } %>
......
......@@ -387,8 +387,8 @@ class CohortHandlerTestCase(CohortViewsTestCase):
self.course, self.cohort1, data={'name': self.cohort1.name, 'group_id': None}
)
self.assertEqual((None, None), get_group_info_for_cohort(self.cohort1))
self.assertEqual(None, response_dict.get("group_id"))
self.assertEqual(None, response_dict.get("user_partition_id"))
self.assertIsNone(response_dict.get("group_id"))
self.assertIsNone(response_dict.get("user_partition_id"))
def test_change_cohort_group_id(self):
"""
......
......@@ -97,7 +97,6 @@ def cohort_handler(request, course_key_string, cohort_id=None):
_get_cohort_representation(c, course)
for c in cohorts.get_course_cohorts(course)
]
# TODO: change to just directly returning the lists.
return JsonResponse({'cohorts': all_cohorts})
else:
cohort = cohorts.get_cohort_by_id(course_key, cohort_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment