Commit 8e787b4f by cahrens Committed by Andy Armstrong

New bok choy tests for content group linking.

parent b77e65cd
...@@ -6,6 +6,7 @@ Instructor (2) dashboard page. ...@@ -6,6 +6,7 @@ Instructor (2) dashboard page.
from bok_choy.page_object import PageObject from bok_choy.page_object import PageObject
from .course_page import CoursePage from .course_page import CoursePage
import os import os
from bok_choy.promise import EmptyPromise
class InstructorDashboardPage(CoursePage): class InstructorDashboardPage(CoursePage):
...@@ -87,6 +88,8 @@ class MembershipPageCohortManagementSection(PageObject): ...@@ -87,6 +88,8 @@ class MembershipPageCohortManagementSection(PageObject):
url = None url = None
csv_browse_button_selector = '.csv-upload #file-upload-form-file' csv_browse_button_selector = '.csv-upload #file-upload-form-file'
csv_upload_button_selector = '.csv-upload #file-upload-form-submit' 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'
def is_browser_on_page(self): def is_browser_on_page(self):
return self.q(css='.cohort-management.membership-section').present return self.q(css='.cohort-management.membership-section').present
...@@ -144,17 +147,24 @@ class MembershipPageCohortManagementSection(PageObject): ...@@ -144,17 +147,24 @@ class MembershipPageCohortManagementSection(PageObject):
""" """
Selects the given cohort in the drop-down. Selects the given cohort in the drop-down.
""" """
EmptyPromise(
lambda: cohort_name in self.get_cohorts(),
"Waiting for cohort selector to populate"
).fulfill()
self.q(css=self._bounded_selector("#cohort-select option")).filter( self.q(css=self._bounded_selector("#cohort-select option")).filter(
lambda el: self._cohort_name(el.text) == cohort_name lambda el: self._cohort_name(el.text) == cohort_name
).first.click() ).first.click()
def add_cohort(self, cohort_name): def add_cohort(self, cohort_name, content_group=None):
""" """
Adds a new manual cohort with the specified name. Adds a new manual cohort with the specified name.
If a content group should also be associated, the name of the content group should be specified.
""" """
self.q(css=self._bounded_selector("div.cohort-management-nav .action-create")).first.click() self.q(css=self._bounded_selector("div.cohort-management-nav .action-create")).first.click()
textinput = self.q(css=self._bounded_selector("#cohort-name")).results[0] textinput = self.q(css=self._bounded_selector("#cohort-name")).results[0]
textinput.send_keys(cohort_name) textinput.send_keys(cohort_name)
if content_group:
self._select_associated_content_group(content_group)
self.q(css=self._bounded_selector("div.form-actions .action-save")).first.click() self.q(css=self._bounded_selector("div.form-actions .action-save")).first.click()
def get_cohort_group_setup(self): def get_cohort_group_setup(self):
...@@ -184,6 +194,68 @@ class MembershipPageCohortManagementSection(PageObject): ...@@ -184,6 +194,68 @@ class MembershipPageCohortManagementSection(PageObject):
css=self._bounded_selector("#cohort-management-group-add-students") css=self._bounded_selector("#cohort-management-group-add-students")
).results[0].get_attribute("value") ).results[0].get_attribute("value")
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 != "Choose a content group to associate":
groups.append(option.text)
return groups
def get_cohort_associated_content_group(self):
"""
Returns the content group associated with the cohort currently being edited.
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]
if radio_button.get_attribute("checked") == "true":
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
def set_cohort_associated_content_group(self, content_group=None, select_settings=True):
"""
Sets the content group associated with the cohort currently being edited.
If content_group is None, un-links the cohort group from any content group.
Presses Save to update the cohort's settings.
"""
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()
else:
self._select_associated_content_group(content_group)
self.q(css=self._bounded_selector("div.form-actions .action-save")).first.click()
def _select_associated_content_group(self, content_group):
"""
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()
def select_cohort_settings(self):
"""
Selects the settings tab for the cohort currently being edited.
"""
self.q(css=self._bounded_selector(".cohort-management-settings li.tab-settings>a")).first.click()
def get_cohort_settings_messages(self, type="confirmation", wait_for_messages=True):
"""
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"
return self._get_messages(title_css, detail_css, wait_for_messages=wait_for_messages)
def _get_cohort_messages(self, type): def _get_cohort_messages(self, type):
""" """
Returns array of messages related to manipulating cohorts directly through the UI for the given type. Returns array of messages related to manipulating cohorts directly through the UI for the given type.
...@@ -201,10 +273,15 @@ class MembershipPageCohortManagementSection(PageObject): ...@@ -201,10 +273,15 @@ class MembershipPageCohortManagementSection(PageObject):
detail_css = ".csv-upload .summary-item" detail_css = ".csv-upload .summary-item"
return self._get_messages(title_css, detail_css) return self._get_messages(title_css, detail_css)
def _get_messages(self, title_css, details_css): def _get_messages(self, title_css, details_css, wait_for_messages=False):
""" """
Helper method to get messages given title and details CSS. Helper method to get messages given title and details CSS.
""" """
if wait_for_messages:
EmptyPromise(
lambda: self.q(css=self._bounded_selector(title_css)).results != 0,
"Waiting for messages to appear"
).fulfill()
message_title = self.q(css=self._bounded_selector(title_css)) message_title = self.q(css=self._bounded_selector(title_css))
if len(message_title.results) == 0: if len(message_title.results) == 0:
return [] return []
...@@ -228,6 +305,16 @@ class MembershipPageCohortManagementSection(PageObject): ...@@ -228,6 +305,16 @@ class MembershipPageCohortManagementSection(PageObject):
""" """
return self._get_cohort_messages("errors") return self._get_cohort_messages("errors")
def get_cohort_related_content_group_message(self):
"""
Gets the error message shown next to the content group selector for the currently selected cohort.
If no message, returns None.
"""
message = self.q(css=self._bounded_selector(".input-group-other .copy-error"))
if not message:
return None
return message.results[0].text
def select_data_download(self): def select_data_download(self):
""" """
Click on the link to the Data Download Page. Click on the link to the Data Download Page.
......
...@@ -10,7 +10,8 @@ from pymongo import MongoClient ...@@ -10,7 +10,8 @@ from pymongo import MongoClient
from pytz import UTC, utc from pytz import UTC, utc
from bok_choy.promise import EmptyPromise from bok_choy.promise import EmptyPromise
from .helpers import CohortTestMixin from .helpers import CohortTestMixin
from ..helpers import UniqueCourseTest from ..helpers import UniqueCourseTest, create_user_partition_json
from xmodule.partitions.partitions import Group
from ...fixtures.course import CourseFixture from ...fixtures.course import CourseFixture
from ...pages.lms.auto_auth import AutoAuthPage from ...pages.lms.auto_auth import AutoAuthPage
from ...pages.lms.instructor_dashboard import InstructorDashboardPage, DataDownloadPage from ...pages.lms.instructor_dashboard import InstructorDashboardPage, DataDownloadPage
...@@ -82,7 +83,7 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -82,7 +83,7 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
Given I have a course with a manual cohort and an automatic cohort defined Given I have a course with a manual cohort and an automatic cohort defined
When I view the manual cohort in the instructor dashboard When I view the manual cohort in the instructor dashboard
There is text specifying that students are only added to the cohort manually There is text specifying that students are only added to the cohort manually
And when I vew the automatic cohort in the instructor dashboard And when I view the automatic cohort in the instructor dashboard
There is text specifying that students are automatically added to the cohort There is text specifying that students are automatically added to the cohort
""" """
self.verify_cohort_description( self.verify_cohort_description(
...@@ -94,6 +95,27 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -94,6 +95,27 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
'Students are added to this group automatically', 'Students are added to this group automatically',
) )
def test_no_content_groups(self):
"""
Scenario: if the course has no content groups defined (user_partitions of type cohort),
the settings in the cohort management tab reflect this
Given I have a course with a cohort defined but no content groups
When I view the cohort in the instructor dashboard and select settings
Then the cohort group is not linked to a content group
And there is text stating that no content groups are defined
And I cannot select the radio button to enable content group association
And there is a link I can select to open Group settings in Studio
"""
self.cohort_management_page.select_cohort(self.manual_cohort_name)
self.assertIsNone(self.cohort_management_page.get_cohort_associated_content_group())
self.assertEqual(
"You haven't configured any content groups yet. You need to create a content group before you can create assignments. 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
def test_link_to_studio(self): def test_link_to_studio(self):
""" """
Scenario: a link is present from the cohort configuration in the instructor dashboard Scenario: a link is present from the cohort configuration in the instructor dashboard
...@@ -133,9 +155,13 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -133,9 +155,13 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
lambda: 2 == self.cohort_management_page.get_selected_cohort_count(), 'Waiting for added students' lambda: 2 == self.cohort_management_page.get_selected_cohort_count(), 'Waiting for added students'
).fulfill() ).fulfill()
confirmation_messages = self.cohort_management_page.get_cohort_confirmation_messages() confirmation_messages = self.cohort_management_page.get_cohort_confirmation_messages()
self.assertEqual(2, len(confirmation_messages)) self.assertEqual(
self.assertEqual("2 students have been added to this cohort group", confirmation_messages[0]) [
self.assertEqual("1 student was removed from " + self.manual_cohort_name, confirmation_messages[1]) "2 students have been added to this cohort group",
"1 student was removed from " + self.manual_cohort_name
],
confirmation_messages
)
self.assertEqual("", self.cohort_management_page.get_cohort_student_input_field_value()) self.assertEqual("", self.cohort_management_page.get_cohort_student_input_field_value())
self.assertEqual( self.assertEqual(
self.event_collection.find({ self.event_collection.find({
...@@ -197,15 +223,21 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -197,15 +223,21 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
).fulfill() ).fulfill()
self.assertEqual(1, self.cohort_management_page.get_selected_cohort_count()) self.assertEqual(1, self.cohort_management_page.get_selected_cohort_count())
confirmation_messages = self.cohort_management_page.get_cohort_confirmation_messages() self.assertEqual(
self.assertEqual(2, len(confirmation_messages)) [
self.assertEqual("0 students have been added to this cohort group", confirmation_messages[0]) "0 students have been added to this cohort group",
self.assertEqual("1 student was already in the cohort group", confirmation_messages[1]) "1 student was already in the cohort group"
],
error_messages = self.cohort_management_page.get_cohort_error_messages() self.cohort_management_page.get_cohort_confirmation_messages()
self.assertEqual(2, len(error_messages)) )
self.assertEqual("There was an error when trying to add students:", error_messages[0])
self.assertEqual("Unknown user: unknown_user", error_messages[1]) self.assertEqual(
[
"There was an error when trying to add students:",
"Unknown user: unknown_user"
],
self.cohort_management_page.get_cohort_error_messages()
)
self.assertEqual( self.assertEqual(
self.student_name + ",unknown_user,", self.student_name + ",unknown_user,",
self.cohort_management_page.get_cohort_student_input_field_value() self.cohort_management_page.get_cohort_student_input_field_value()
...@@ -421,3 +453,194 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin): ...@@ -421,3 +453,194 @@ class CohortConfigurationTest(UniqueCourseTest, CohortTestMixin):
).fulfill() ).fulfill()
messages = self.cohort_management_page.get_csv_messages() messages = self.cohort_management_page.get_csv_messages()
self.assertEquals(expected_message, messages[0]) self.assertEquals(expected_message, messages[0])
class CohortContentGroupAssociationTest(UniqueCourseTest, CohortTestMixin):
"""
Tests for linking between content groups and cohort groups in the instructor dashboard.
"""
def setUp(self):
"""
Set up a cohorted course with a user_partition of scheme "cohort".
"""
super(CohortContentGroupAssociationTest, self).setUp()
# create course with single cohort and two content groups (user_partition of type "cohort")
self.cohort_name = "OnlyCohort"
self.course_fixture = CourseFixture(**self.course_info).install()
self.setup_cohort_config(self.course_fixture)
self.cohort_id = self.add_manual_cohort(self.course_fixture, self.cohort_name)
self.course_fixture._update_xblock(self.course_fixture._course_location, {
"metadata": {
u"user_partitions": [
create_user_partition_json(
0,
'Apples, Bananas',
'Content Group Partition',
[Group("0", 'Apples'), Group("1", 'Bananas')],
scheme="cohort"
)
],
},
})
# login as an instructor
self.instructor_name = "instructor_user"
self.instructor_id = AutoAuthPage(
self.browser, username=self.instructor_name, email="instructor_user@example.com",
course_id=self.course_id, staff=True
).visit().get_user_id()
# go to the membership page on the instructor dashboard
self.instructor_dashboard_page = InstructorDashboardPage(self.browser, self.course_id)
self.instructor_dashboard_page.visit()
membership_page = self.instructor_dashboard_page.select_membership()
self.cohort_management_page = membership_page.select_cohort_management_section()
def test_no_content_group_linked(self):
"""
Scenario: In a course with content groups, cohorts are initially not linked to a content group
Given I have a course with a cohort defined and content groups defined
When I view the cohort in the instructor dashboard and select settings
Then the cohort group is not linked to a content group
And there is no text stating that content groups are undefined
And the content groups are listed in the selector
"""
self.cohort_management_page.select_cohort(self.cohort_name)
self.assertIsNone(self.cohort_management_page.get_cohort_associated_content_group())
self.assertIsNone(self.cohort_management_page.get_cohort_related_content_group_message())
self.assertEquals(["Apples", "Bananas"], self.cohort_management_page.get_all_content_groups())
def test_link_to_content_group(self):
"""
Scenario: In a course with content groups, cohorts can be linked to content groups
Given I have a course with a cohort defined and content groups defined
When I view the cohort in the instructor dashboard and select settings
And I link the cohort to one of the content groups and save
Then there is a notification that my cohort has been saved
And when I reload the page
And I view the cohort in the instructor dashboard and select settings
Then the cohort is still linked to the content group
"""
self._link_cohort_to_content_group(self.cohort_name, "Bananas")
self.assertEqual("Bananas", self.cohort_management_page.get_cohort_associated_content_group())
def test_unlink_from_content_group(self):
"""
Scenario: In a course with content groups, cohorts can be unlinked from content groups
Given I have a course with a cohort defined and content groups defined
When I view the cohort in the instructor dashboard and select settings
And I link the cohort to one of the content groups and save
Then there is a notification that my cohort has been saved
And I reload the page
And I view the cohort in the instructor dashboard and select settings
And I unlink the cohort from any content group and save
Then there is a notification that my cohort has been saved
And when I reload the page
And I view the cohort in the instructor dashboard and select settings
Then the cohort is not linked to any content group
"""
self._link_cohort_to_content_group(self.cohort_name, "Bananas")
self.cohort_management_page.set_cohort_associated_content_group(None)
self._verify_settings_saved_and_reload(self.cohort_name)
self.assertEqual(None, self.cohort_management_page.get_cohort_associated_content_group())
def test_create_new_cohort_linked_to_content_group(self):
"""
Scenario: In a course with content groups, a new cohort can be linked to a content group
at time of creation.
Given I have a course with a cohort defined and content groups defined
When I create a new cohort and link it to a content group
Then when I select settings I see that the cohort is linked to the content group
And when I reload the page
And I view the cohort in the instructor dashboard and select settings
Then the cohort is still linked to the content group
"""
new_cohort = "correctly linked cohort"
self._create_new_cohort_linked_to_content_group(new_cohort, "Apples")
self.browser.refresh()
self.cohort_management_page.wait_for_page()
self.cohort_management_page.select_cohort(new_cohort)
self.assertEqual("Apples", self.cohort_management_page.get_cohort_associated_content_group())
def test_missing_content_group(self):
"""
Scenario: In a course with content groups, if a cohort is associated with a content group that no longer
exists, a warning message is shown
Given I have a course with a cohort defined and content groups defined
When I create a new cohort and link it to a content group
And I delete that content group from the course
And I reload the page
And I view the cohort in the instructor dashboard and select settings
Then the settings display a message that the content group no longer exists
And when I select a different content group and save
Then the error message goes away
"""
new_cohort = "linked to missing content group"
self._create_new_cohort_linked_to_content_group(new_cohort, "Apples")
self.course_fixture._update_xblock(self.course_fixture._course_location, {
"metadata": {
u"user_partitions": [
create_user_partition_json(
0,
'Apples, Bananas',
'Content Group Partition',
[Group("2", 'Pears'), Group("1", 'Bananas')],
scheme="cohort"
)
],
},
})
self.browser.refresh()
self.cohort_management_page.wait_for_page()
self.cohort_management_page.select_cohort(new_cohort)
self.assertEqual("Some content group that's been deleted", 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.assertEqual(
"The selected content group has been deleted, you may wish to reassign this cohort group.",
self.cohort_management_page.get_cohort_related_content_group_message()
)
self.cohort_management_page.set_cohort_associated_content_group("Pears")
confirmation_messages = self.cohort_management_page.get_cohort_settings_messages()
self.assertEqual(["Saved cohort group."], confirmation_messages)
# TODO: uncomment
# self.assertIsNone(self.cohort_management_page.get_cohort_related_content_group_message())
# self.assertEquals(["Bananas", "Pears"], self.cohort_management_page.get_all_content_groups())
def _create_new_cohort_linked_to_content_group(self, new_cohort, cohort_group):
"""
Creates a new cohort linked to a content group.
"""
self.cohort_management_page.add_cohort(new_cohort, content_group=cohort_group)
# After adding the cohort, it should automatically be selected
EmptyPromise(
lambda: new_cohort == self.cohort_management_page.get_selected_cohort(), "Waiting for new cohort to appear"
).fulfill()
self.assertEqual(cohort_group, self.cohort_management_page.get_cohort_associated_content_group())
def _link_cohort_to_content_group(self, cohort_name, content_group):
"""
Links a cohort to a content group. Saves the changes and verifies the cohort updated properly.
Then refreshes the page and selects the cohort.
"""
self.cohort_management_page.select_cohort(cohort_name)
self.cohort_management_page.set_cohort_associated_content_group(content_group)
self._verify_settings_saved_and_reload(cohort_name)
def _verify_settings_saved_and_reload(self, cohort_name):
"""
Verifies the confirmation message indicating that a cohort's settings have been updated.
Then refreshes the page and selects the cohort.
"""
confirmation_messages = self.cohort_management_page.get_cohort_settings_messages()
self.assertEqual(["Saved cohort group."], confirmation_messages)
self.browser.refresh()
self.cohort_management_page.wait_for_page()
self.cohort_management_page.select_cohort(cohort_name)
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