From bc483ebae89532483cd2456192f31571a9c38eb8 Mon Sep 17 00:00:00 2001 From: cahrens Date: Wed, 3 Sep 2014 15:09:14 -0400 Subject: [PATCH] Bok choy test for cohort group label in post. --- common/test/acceptance/fixtures/__init__.py | 5 +- .../test/acceptance/pages/lms/discussion.py | 6 + .../acceptance/tests/discussion/helpers.py | 31 ++++ .../tests/discussion/test_cohorts.py | 157 ++++++++++++++++++ .../tests/discussion/test_discussion.py | 20 +-- 5 files changed, 201 insertions(+), 18 deletions(-) create mode 100644 common/test/acceptance/tests/discussion/helpers.py create mode 100644 common/test/acceptance/tests/discussion/test_cohorts.py diff --git a/common/test/acceptance/fixtures/__init__.py b/common/test/acceptance/fixtures/__init__.py index bd01006219..f4a6d18398 100644 --- a/common/test/acceptance/fixtures/__init__.py +++ b/common/test/acceptance/fixtures/__init__.py @@ -1,8 +1,11 @@ import os -# Get the URL of the instance under test +# Get the URL of the Studio instance under test STUDIO_BASE_URL = os.environ.get('studio_url', 'http://localhost:8031') +# Get the URL of the LMS instance under test +LMS_BASE_URL = os.environ.get('lms_url', 'http://localhost:8003') + # Get the URL of the XQueue stub used in the test XQUEUE_STUB_URL = os.environ.get('xqueue_url', 'http://localhost:8040') diff --git a/common/test/acceptance/pages/lms/discussion.py b/common/test/acceptance/pages/lms/discussion.py index dea713b226..9bdf12d261 100644 --- a/common/test/acceptance/pages/lms/discussion.py +++ b/common/test/acceptance/pages/lms/discussion.py @@ -60,6 +60,12 @@ class DiscussionThreadPage(PageObject, DiscussionPageMixin): "Secondary action menu closed" ).fulfill() + def get_group_visibility_label(self): + """ + Returns the group visibility label shown for the thread. + """ + return self._get_element_text(".group-visibility-label") + def get_response_total_text(self): """Returns the response count text, or None if not present""" return self._get_element_text(".response-count") diff --git a/common/test/acceptance/tests/discussion/helpers.py b/common/test/acceptance/tests/discussion/helpers.py new file mode 100644 index 0000000000..f54f0c0136 --- /dev/null +++ b/common/test/acceptance/tests/discussion/helpers.py @@ -0,0 +1,31 @@ +""" +Helper functions and classes for discussion tests. +""" + +from uuid import uuid4 + +from ...fixtures.discussion import ( + SingleThreadViewFixture, + Thread, + Response, +) + + +class BaseDiscussionMixin(object): + """ + A mixin containing methods common to discussion tests. + """ + def setup_thread(self, num_responses, **thread_kwargs): + """ + Create a test thread with the given number of responses, passing all + keyword arguments through to the Thread fixture, then invoke + setup_thread_page. + """ + thread_id = "test_thread_{}".format(uuid4().hex) + thread_fixture = SingleThreadViewFixture( + Thread(id=thread_id, commentable_id=self.discussion_id, **thread_kwargs) + ) + for i in range(num_responses): + thread_fixture.addResponse(Response(id=str(i), body=str(i))) + thread_fixture.push() + self.setup_thread_page(thread_id) diff --git a/common/test/acceptance/tests/discussion/test_cohorts.py b/common/test/acceptance/tests/discussion/test_cohorts.py new file mode 100644 index 0000000000..60cd25923c --- /dev/null +++ b/common/test/acceptance/tests/discussion/test_cohorts.py @@ -0,0 +1,157 @@ +""" +Tests related to the cohorting feature. +""" +from uuid import uuid4 + +from helpers import BaseDiscussionMixin +from ...pages.lms.auto_auth import AutoAuthPage +from ..helpers import UniqueCourseTest +from ...fixtures.course import (CourseFixture, XBlockFixtureDesc) +from ...fixtures import LMS_BASE_URL + +from ...pages.lms.discussion import (DiscussionTabSingleThreadPage, InlineDiscussionThreadPage, InlineDiscussionPage) +from ...pages.lms.courseware import CoursewarePage + +from nose.plugins.attrib import attr + + +class NonCohortedDiscussionTestMixin(BaseDiscussionMixin): + """ + Mixin for tests of non-cohorted courses. + """ + def setup_cohorts(self): + """ + No cohorts are desired for this mixin. + """ + pass + + def test_non_cohort_visibility_label(self): + self.setup_thread(1) + self.assertEquals(self.thread_page.get_group_visibility_label(), "This post is visible to everyone.") + + +class CohortedDiscussionTestMixin(BaseDiscussionMixin): + """ + Mixin for tests of cohorted courses. + """ + def add_cohort(self, name): + """ + Adds a cohort group by name, returning the ID for the group. + """ + url = LMS_BASE_URL + "/courses/" + self.course_fixture._course_key + '/cohorts/add' + data = {"name": name} + response = self.course_fixture.session.post(url, data=data, headers=self.course_fixture.headers) + self.assertTrue(response.ok, "Failed to create cohort") + return response.json()['cohort']['id'] + + def setup_cohorts(self): + """ + Sets up the course to use cohorting with a single defined cohort group. + """ + self.course_fixture._update_xblock(self.course_fixture._course_location, { + "metadata": { + u"cohort_config": { + "auto_cohort_groups": [], + "auto_cohort": False, + "cohorted_discussions": [], + "cohorted": True + }, + }, + }) + self.cohort_1_name = "Cohort Group 1" + self.cohort_1_id = self.add_cohort(self.cohort_1_name) + + def test_cohort_visibility_label(self): + self.setup_thread(1, group_id=self.cohort_1_id) + self.assertEquals( + self.thread_page.get_group_visibility_label(), + "This post is visible only to {}.".format(self.cohort_1_name) + ) + + +class DiscussionTabSingleThreadTest(UniqueCourseTest): + """ + Tests for the discussion page displaying a single thread. + """ + def setUp(self): + super(DiscussionTabSingleThreadTest, self).setUp() + self.discussion_id = "test_discussion_{}".format(uuid4().hex) + # Create a course to register for + self.course_fixture = CourseFixture(**self.course_info).install() + self.setup_cohorts() + AutoAuthPage(self.browser, course_id=self.course_id).visit() + + def setup_thread_page(self, thread_id): + self.thread_page = DiscussionTabSingleThreadPage(self.browser, self.course_id, thread_id) # pylint:disable=W0201 + self.thread_page.visit() + + +@attr('shard_1') +class CohortedDiscussionTabSingleThreadTest(DiscussionTabSingleThreadTest, CohortedDiscussionTestMixin): + """ + Tests for the discussion page displaying a single cohorted thread. + """ + # Actual test method(s) defined in CohortedDiscussionTestMixin. + pass + + +@attr('shard_1') +class NonCohortedDiscussionTabSingleThreadTest(DiscussionTabSingleThreadTest, NonCohortedDiscussionTestMixin): + """ + Tests for the discussion page displaying a single non-cohorted thread. + """ + # Actual test method(s) defined in NonCohortedDiscussionTestMixin. + pass + + +class InlineDiscussionTest(UniqueCourseTest): + """ + Tests for inline discussions + """ + def setUp(self): + super(InlineDiscussionTest, self).setUp() + self.discussion_id = "test_discussion_{}".format(uuid4().hex) + self.course_fixture = CourseFixture(**self.course_info).add_children( + XBlockFixtureDesc("chapter", "Test Section").add_children( + XBlockFixtureDesc("sequential", "Test Subsection").add_children( + XBlockFixtureDesc("vertical", "Test Unit").add_children( + XBlockFixtureDesc( + "discussion", + "Test Discussion", + metadata={"discussion_id": self.discussion_id} + ) + ) + ) + ) + ).install() + self.setup_cohorts() + + self.user_id = AutoAuthPage(self.browser, course_id=self.course_id).visit().get_user_id() + + self.courseware_page = CoursewarePage(self.browser, self.course_id) + self.courseware_page.visit() + self.discussion_page = InlineDiscussionPage(self.browser, self.discussion_id) + + def setup_thread_page(self, thread_id): + self.discussion_page.expand_discussion() + self.assertEqual(self.discussion_page.get_num_displayed_threads(), 1) + self.thread_page = InlineDiscussionThreadPage(self.browser, thread_id) # pylint:disable=W0201 + self.thread_page.expand() + + +@attr('shard_1') +class CohortedInlineDiscussionTest(InlineDiscussionTest, CohortedDiscussionTestMixin): + """ + Tests for cohorted inline discussions. + """ + # Actual test method(s) defined in CohortedDiscussionTestMixin. + pass + + +@attr('shard_1') +class NonCohortedInlineDiscussionTest(InlineDiscussionTest, NonCohortedDiscussionTestMixin): + """ + Tests for non-cohorted inline discussions. + """ + # Actual test method(s) defined in NonCohortedDiscussionTestMixin. + pass diff --git a/common/test/acceptance/tests/discussion/test_discussion.py b/common/test/acceptance/tests/discussion/test_discussion.py index c2023f8de8..70b2291ddb 100644 --- a/common/test/acceptance/tests/discussion/test_discussion.py +++ b/common/test/acceptance/tests/discussion/test_discussion.py @@ -29,28 +29,14 @@ from ...fixtures.discussion import ( SearchResult, ) +from helpers import BaseDiscussionMixin -class DiscussionResponsePaginationTestMixin(object): + +class DiscussionResponsePaginationTestMixin(BaseDiscussionMixin): """ A mixin containing tests for response pagination for use by both inline discussion and the discussion tab """ - - def setup_thread(self, num_responses, **thread_kwargs): - """ - Create a test thread with the given number of responses, passing all - keyword arguments through to the Thread fixture, then invoke - setup_thread_page. - """ - thread_id = "test_thread_{}".format(uuid4().hex) - thread_fixture = SingleThreadViewFixture( - Thread(id=thread_id, commentable_id=self.discussion_id, **thread_kwargs) - ) - for i in range(num_responses): - thread_fixture.addResponse(Response(id=str(i), body=str(i))) - thread_fixture.push() - self.setup_thread_page(thread_id) - def assert_response_display_correct(self, response_total, displayed_responses): """ Assert that various aspects of the display of responses are all correct: