utils.py 1.92 KB
Newer Older
1 2 3
"""
Utilities for tests within the django_comment_client module.
"""
4
from mock import patch
5

6
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
7 8 9
from django_comment_common.models import Role
from django_comment_common.utils import seed_permissions_roles
from student.tests.factories import CourseEnrollmentFactory, UserFactory
10
from xmodule.modulestore.tests.factories import CourseFactory
11 12
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase

13

14
class CohortedTestCase(ModuleStoreTestCase):
15 16 17 18 19
    """
    Sets up a course with a student, a moderator and their cohorts.
    """
    @patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
    def setUp(self):
20
        super(CohortedTestCase, self).setUp()
21 22 23 24 25 26 27

        self.course = CourseFactory.create(
            cohort_config={
                "cohorted": True,
                "cohorted_discussions": ["cohorted_topic"]
            }
        )
28
        self.student_cohort = CohortFactory.create(
29
            name="student_cohort",
30
            course_id=self.course.id
31
        )
32
        self.moderator_cohort = CohortFactory.create(
33
            name="moderator_cohort",
34
            course_id=self.course.id
35
        )
36 37 38
        self.course.discussion_topics["cohorted topic"] = {"id": "cohorted_topic"}
        self.course.discussion_topics["non-cohorted topic"] = {"id": "non_cohorted_topic"}
        self.store.update_item(self.course, self.user.id)
39 40 41 42 43 44 45 46 47

        seed_permissions_roles(self.course.id)
        self.student = UserFactory.create()
        self.moderator = UserFactory.create()
        CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
        CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)
        self.moderator.roles.add(Role.objects.get(name="Moderator", course_id=self.course.id))
        self.student_cohort.users.add(self.student)
        self.moderator_cohort.users.add(self.moderator)