test_cohorts.py 5.62 KB
Newer Older
1 2 3 4 5
"""
Tests related to the cohorting feature.
"""
from uuid import uuid4

6
from .helpers import BaseDiscussionMixin
7
from .helpers import CohortTestMixin
8
from ..helpers import UniqueCourseTest
9
from ...pages.lms.auto_auth import AutoAuthPage
10 11 12 13 14 15 16 17 18 19
from ...fixtures.course import (CourseFixture, XBlockFixtureDesc)

from ...pages.lms.discussion import (DiscussionTabSingleThreadPage, InlineDiscussionThreadPage, InlineDiscussionPage)
from ...pages.lms.courseware import CoursewarePage

from nose.plugins.attrib import attr


class NonCohortedDiscussionTestMixin(BaseDiscussionMixin):
    """
20
    Mixin for tests of discussion in non-cohorted courses.
21 22 23 24 25 26 27 28 29 30 31 32
    """
    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.")


33
class CohortedDiscussionTestMixin(BaseDiscussionMixin, CohortTestMixin):
34
    """
35
    Mixin for tests of discussion in cohorted courses.
36 37 38
    """
    def setup_cohorts(self):
        """
39
        Sets up the course to use cohorting with a single defined cohort.
40
        """
41
        self.setup_cohort_config(self.course_fixture)
42
        self.cohort_1_name = "Cohort 1"
43
        self.cohort_1_id = self.add_manual_cohort(self.course_fixture, self.cohort_1_name)
44 45

    def test_cohort_visibility_label(self):
46 47
        # Must be moderator to view content in a cohort other than your own
        AutoAuthPage(self.browser, course_id=self.course_id, roles="Moderator").visit()
48
        self.thread_id = self.setup_thread(1, group_id=self.cohort_1_id)
49 50 51 52 53
        self.assertEquals(
            self.thread_page.get_group_visibility_label(),
            "This post is visible only to {}.".format(self.cohort_1_name)
        )

54 55 56 57 58
        # Disable cohorts and verify that the post now shows as visible to everyone.
        self.disable_cohorting(self.course_fixture)
        self.refresh_thread_page(self.thread_id)
        self.assertEquals(self.thread_page.get_group_visibility_label(), "This post is visible to everyone.")

59 60 61 62 63 64 65 66 67 68 69 70 71 72

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):
73
        self.thread_page = DiscussionTabSingleThreadPage(self.browser, self.course_id, thread_id)  # pylint: disable=attribute-defined-outside-init
74 75
        self.thread_page.visit()

76
    # pylint: disable=unused-argument
77 78 79 80
    def refresh_thread_page(self, thread_id):
        self.browser.refresh()
        self.thread_page.wait_for_page()

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

@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()

    def setup_thread_page(self, thread_id):
125
        CoursewarePage(self.browser, self.course_id).visit()
126 127 128
        self.show_thread(thread_id)

    def show_thread(self, thread_id):
129 130 131
        discussion_page = InlineDiscussionPage(self.browser, self.discussion_id)
        discussion_page.expand_discussion()
        self.assertEqual(discussion_page.get_num_displayed_threads(), 1)
132
        self.thread_page = InlineDiscussionThreadPage(self.browser, thread_id)  # pylint: disable=attribute-defined-outside-init
133 134
        self.thread_page.expand()

135 136 137 138
    def refresh_thread_page(self, thread_id):
        self.browser.refresh()
        self.show_thread(thread_id)

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

@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