class BaseDividedDiscussionTest(UniqueCourseTest, CohortTestMixin):
    """
    Base class for tests related to divided discussions.
    """
    def setUp(self):
        """
        Set up a discussion topic
        """
        super(BaseDividedDiscussionTest, self).setUp()

        self.discussion_id = "test_discussion_{}".format(uuid.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()

        # create course with single cohort and two content groups (user_partition of type "cohort")
        self.cohort_name = "OnlyCohort"
        self.setup_cohort_config(self.course_fixture)
        self.cohort_id = self.add_manual_cohort(self.course_fixture,
                                                self.cohort_name)

        # login as an instructor
        self.instructor_name = "instructor_user"
        self.instructor_id = AutoAuthPage(self.browser,
                                          username=self.instructor_name,
                                          email="*****@*****.**",
                                          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()
        self.discussion_management_page = self.instructor_dashboard_page.select_discussion_management(
        )
        self.discussion_management_page.wait_for_page()

        self.course_wide_key = 'course-wide'
        self.inline_key = 'inline'
        self.scheme_key = 'scheme'

    def check_discussion_topic_visibility(self, visible=True):
        """
        Assert that discussion topics are visible with appropriate content.
        """
        self.assertEqual(
            visible,
            self.discussion_management_page.discussion_topics_visible())

        if visible:
            self.assertEqual(
                "Course-Wide Discussion Topics",
                self.discussion_management_page.
                divided_discussion_heading_is_visible(self.course_wide_key))
            self.assertTrue(
                self.discussion_management_page.is_save_button_disabled(
                    self.course_wide_key))

            self.assertEqual(
                "Content-Specific Discussion Topics",
                self.discussion_management_page.
                divided_discussion_heading_is_visible(self.inline_key))
            self.assertTrue(
                self.discussion_management_page.is_save_button_disabled(
                    self.inline_key))

    def reload_page(self, topics_visible=True):
        """
        Refresh the page, then verify if the discussion topics are visible on the discussion
        management instructor dashboard tab.
        """
        self.browser.refresh()
        self.discussion_management_page.wait_for_page()

        self.instructor_dashboard_page.select_discussion_management()
        self.discussion_management_page.wait_for_page()

        self.check_discussion_topic_visibility(topics_visible)

    def verify_save_confirmation_message(self, key):
        """
        Verify that the save confirmation message for the specified portion of the page is visible.
        """
        confirmation_message = self.discussion_management_page.get_divide_discussions_message(
            key=key)
        self.assertIn("Your changes have been saved.", confirmation_message)
class BaseDividedDiscussionTest(UniqueCourseTest, CohortTestMixin):
    """
    Base class for tests related to divided discussions.
    """
    def setUp(self):
        """
        Set up a discussion topic
        """
        super(BaseDividedDiscussionTest, self).setUp()

        self.discussion_id = "test_discussion_{}".format(uuid.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()

        # create course with single cohort and two content groups (user_partition of type "cohort")
        self.cohort_name = "OnlyCohort"
        self.setup_cohort_config(self.course_fixture)
        self.cohort_id = self.add_manual_cohort(self.course_fixture, self.cohort_name)

        # login as an instructor
        self.instructor_name = "instructor_user"
        self.instructor_id = AutoAuthPage(
            self.browser, username=self.instructor_name, email="*****@*****.**",
            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()
        self.discussion_management_page = self.instructor_dashboard_page.select_discussion_management()
        self.discussion_management_page.wait_for_page()

        self.course_wide_key = 'course-wide'
        self.inline_key = 'inline'
        self.scheme_key = 'scheme'

    def check_discussion_topic_visibility(self, visible=True):
        """
        Assert that discussion topics are visible with appropriate content.
        """
        self.assertEqual(visible, self.discussion_management_page.discussion_topics_visible())

        if visible:
            self.assertEqual(
                "Course-Wide Discussion Topics",
                self.discussion_management_page.divided_discussion_heading_is_visible(self.course_wide_key)
            )
            self.assertTrue(self.discussion_management_page.is_save_button_disabled(self.course_wide_key))

            self.assertEqual(
                "Content-Specific Discussion Topics",
                self.discussion_management_page.divided_discussion_heading_is_visible(self.inline_key)
            )
            self.assertTrue(self.discussion_management_page.is_save_button_disabled(self.inline_key))

    def reload_page(self, topics_visible=True):
        """
        Refresh the page, then verify if the discussion topics are visible on the discussion
        management instructor dashboard tab.
        """
        self.browser.refresh()
        self.discussion_management_page.wait_for_page()

        self.instructor_dashboard_page.select_discussion_management()
        self.discussion_management_page.wait_for_page()

        self.check_discussion_topic_visibility(topics_visible)

    def verify_save_confirmation_message(self, key):
        """
        Verify that the save confirmation message for the specified portion of the page is visible.
        """
        confirmation_message = self.discussion_management_page.get_divide_discussions_message(key=key)
        self.assertIn("Your changes have been saved.", confirmation_message)