Ejemplo n.º 1
0
 def test_get_course_cohorts_noop(self):
     """
     Tests get_course_cohorts returns an empty list when no cohorts exist.
     """
     course = modulestore().get_course(self.toy_course_key)
     config_course_cohorts(course, [], cohorted=True)
     self.assertEqual([], cohorts.get_course_cohorts(course))
Ejemplo n.º 2
0
    def test_auto_cohorts(self):
        """
        Verify that auto cohorts are included in the response.
        """
        config_course_cohorts(self.course, [], cohorted=True, auto_cohort=True,
                              auto_cohort_groups=["AutoGroup1", "AutoGroup2"])

        # Will create cohort1, cohort2, and cohort3. Auto cohorts remain uncreated.
        self._create_cohorts()
        # Get the cohorts from the course, which will cause auto cohorts to be created.
        actual_cohorts = self.request_list_cohorts(self.course)
        # Get references to the created auto cohorts.
        auto_cohort_1 = CourseUserGroup.objects.get(
            course_id=self.course.location.course_key,
            group_type=CourseUserGroup.COHORT,
            name="AutoGroup1"
        )
        auto_cohort_2 = CourseUserGroup.objects.get(
            course_id=self.course.location.course_key,
            group_type=CourseUserGroup.COHORT,
            name="AutoGroup2"
        )
        expected_cohorts = [
            ListCohortsTestCase.create_expected_cohort(self.cohort1, 3),
            ListCohortsTestCase.create_expected_cohort(self.cohort2, 2),
            ListCohortsTestCase.create_expected_cohort(self.cohort3, 2),
            ListCohortsTestCase.create_expected_cohort(auto_cohort_1, 0),
            ListCohortsTestCase.create_expected_cohort(auto_cohort_2, 0),
        ]
        self.verify_lists_expected_cohorts(actual_cohorts, expected_cohorts)
Ejemplo n.º 3
0
    def _verify_course_cohorts(self, auto_cohort, expected_cohort_set):
        """
        Helper method for testing get_course_cohorts with both manual and auto cohorts.
        """
        course = modulestore().get_course(self.toy_course_key)
        config_course_cohorts(
            course, [], cohorted=True, auto_cohort=auto_cohort,
            auto_cohort_groups=["AutoGroup1", "AutoGroup2"]
        )

        # add manual cohorts to course 1
        CourseUserGroup.objects.create(
            name="ManualCohort",
            course_id=course.location.course_key,
            group_type=CourseUserGroup.COHORT
        )

        CourseUserGroup.objects.create(
            name="ManualCohort2",
            course_id=course.location.course_key,
            group_type=CourseUserGroup.COHORT
        )

        cohort_set = {c.name for c in cohorts.get_course_cohorts(course)}
        self.assertEqual(cohort_set, expected_cohort_set)
Ejemplo n.º 4
0
    def test_auto_cohorting_randomization(self):
        """
        Make sure cohorts.get_cohort() randomizes properly.
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        groups = ["group_{0}".format(n) for n in range(5)]
        config_course_cohorts(
            course, discussions=[], cohorted=True, auto_cohort_groups=groups
        )

        # Assign 100 users to cohorts
        for i in range(100):
            user = UserFactory(
                username="******".format(i),
                email="a@b{0}.com".format(i)
            )
            cohorts.get_cohort(user, course.id)

        # Now make sure that the assignment was at least vaguely random:
        # each cohort should have at least 1, and fewer than 50 students.
        # (with 5 groups, probability of 0 users in any group is about
        # .8**100= 2.0e-10)
        for cohort_name in groups:
            cohort = cohorts.get_cohort_by_name(course.id, cohort_name)
            num_users = cohort.users.count()
            self.assertGreater(num_users, 1)
            self.assertLess(num_users, 50)
Ejemplo n.º 5
0
    def test_get_cohort(self):
        """
        Make sure cohorts.get_cohort() does the right thing when the course is cohorted
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertEqual(course.id, self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user = User.objects.create(username="******", email="*****@*****.**")
        other_user = User.objects.create(username="******", email="*****@*****.**")

        self.assertIsNone(cohorts.get_cohort(user, course.id),
                          "No cohort created yet")

        cohort = CourseUserGroup.objects.create(
            name="TestCohort",
            course_id=course.id,
            group_type=CourseUserGroup.COHORT)

        cohort.users.add(user)

        self.assertIsNone(cohorts.get_cohort(user, course.id),
                          "Course isn't cohorted, so shouldn't have a cohort")

        # Make the course cohorted...
        config_course_cohorts(course, [], cohorted=True)

        self.assertEquals(
            cohorts.get_cohort(user, course.id).id, cohort.id,
            "Should find the right cohort")

        self.assertEquals(cohorts.get_cohort(other_user, course.id), None,
                          "other_user shouldn't have a cohort")
Ejemplo n.º 6
0
    def test_get_cohort(self):
        """
        Make sure cohorts.get_cohort() does the right thing when the course is cohorted
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertEqual(course.id, self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user = UserFactory(username="******", email="*****@*****.**")
        other_user = UserFactory(username="******", email="*****@*****.**")

        self.assertIsNone(cohorts.get_cohort(user, course.id),
                          "No cohort created yet")

        cohort = CohortFactory(course_id=course.id, name="TestCohort")
        cohort.users.add(user)

        self.assertIsNone(cohorts.get_cohort(user, course.id),
                          "Course isn't cohorted, so shouldn't have a cohort")

        # Make the course cohorted...
        config_course_cohorts(course, discussions=[], cohorted=True)

        self.assertEquals(
            cohorts.get_cohort(user, course.id).id, cohort.id,
            "user should be assigned to the correct cohort")
        self.assertEquals(
            cohorts.get_cohort(other_user, course.id).id,
            cohorts.get_cohort_by_name(course.id,
                                       cohorts.DEFAULT_COHORT_NAME).id,
            "other_user should be assigned to the default cohort")
Ejemplo n.º 7
0
 def test_get_course_cohorts_noop(self):
     """
     Tests get_course_cohorts returns an empty list when no cohorts exist.
     """
     course = modulestore().get_course(self.toy_course_key)
     config_course_cohorts(course, [], cohorted=True)
     self.assertEqual([], cohorts.get_course_cohorts(course))
Ejemplo n.º 8
0
    def test_get_cohort(self):
        """
        Make sure cohorts.get_cohort() does the right thing when the course is cohorted
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertEqual(course.id, self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user = User.objects.create(username="******", email="*****@*****.**")
        other_user = User.objects.create(username="******", email="*****@*****.**")

        self.assertIsNone(cohorts.get_cohort(user, course.id), "No cohort created yet")

        cohort = CourseUserGroup.objects.create(name="TestCohort",
                                                course_id=course.id,
                                                group_type=CourseUserGroup.COHORT)

        cohort.users.add(user)

        self.assertIsNone(cohorts.get_cohort(user, course.id),
                          "Course isn't cohorted, so shouldn't have a cohort")

        # Make the course cohorted...
        config_course_cohorts(course, [], cohorted=True)

        self.assertEquals(cohorts.get_cohort(user, course.id).id, cohort.id,
                          "Should find the right cohort")

        self.assertEquals(cohorts.get_cohort(other_user, course.id), None,
                          "other_user shouldn't have a cohort")
Ejemplo n.º 9
0
    def test_auto_cohorts(self):
        """
        Verify that auto cohorts are included in the response.
        """
        config_course_cohorts(self.course, [],
                              cohorted=True,
                              auto_cohort=True,
                              auto_cohort_groups=["AutoGroup1", "AutoGroup2"])

        # Will create cohort1, cohort2, and cohort3. Auto cohorts remain uncreated.
        self._create_cohorts()
        # Get the cohorts from the course, which will cause auto cohorts to be created.
        actual_cohorts = self.request_list_cohorts(self.course)
        # Get references to the created auto cohorts.
        auto_cohort_1 = CourseUserGroup.objects.get(
            course_id=self.course.location.course_key,
            group_type=CourseUserGroup.COHORT,
            name="AutoGroup1")
        auto_cohort_2 = CourseUserGroup.objects.get(
            course_id=self.course.location.course_key,
            group_type=CourseUserGroup.COHORT,
            name="AutoGroup2")
        expected_cohorts = [
            ListCohortsTestCase.create_expected_cohort(self.cohort1, 3),
            ListCohortsTestCase.create_expected_cohort(self.cohort2, 2),
            ListCohortsTestCase.create_expected_cohort(self.cohort3, 2),
            ListCohortsTestCase.create_expected_cohort(auto_cohort_1, 0),
            ListCohortsTestCase.create_expected_cohort(auto_cohort_2, 0),
        ]
        self.verify_lists_expected_cohorts(actual_cohorts, expected_cohorts)
Ejemplo n.º 10
0
    def test_auto_cohorting_randomization(self):
        """
        Make sure cohorts.get_cohort() randomizes properly.
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        groups = ["group_{0}".format(n) for n in range(5)]
        config_course_cohorts(course, [],
                              cohorted=True,
                              auto_cohort=True,
                              auto_cohort_groups=groups)

        # Assign 100 users to cohorts
        for i in range(100):
            user = User.objects.create(username="******".format(i),
                                       email="a@b{0}.com".format(i))
            cohorts.get_cohort(user, course.id)

        # Now make sure that the assignment was at least vaguely random:
        # each cohort should have at least 1, and fewer than 50 students.
        # (with 5 groups, probability of 0 users in any group is about
        # .8**100= 2.0e-10)
        for cohort_name in groups:
            cohort = cohorts.get_cohort_by_name(course.id, cohort_name)
            num_users = cohort.users.count()
            self.assertGreater(num_users, 1)
            self.assertLess(num_users, 50)
Ejemplo n.º 11
0
    def test_auto_cohorts(self):
        """
        Verify that auto cohorts are included in the response.
        """
        config_course_cohorts(self.course, [],
                              cohorted=True,
                              auto_cohort_groups=["AutoGroup1", "AutoGroup2"])

        # Will create cohort1, cohort2, and cohort3. Auto cohorts remain uncreated.
        self._create_cohorts()
        # Get the cohorts from the course, which will cause auto cohorts to be created.
        actual_cohorts = self.request_list_cohorts(self.course)
        # Get references to the created auto cohorts.
        auto_cohort_1 = get_cohort_by_name(self.course.id, "AutoGroup1")
        auto_cohort_2 = get_cohort_by_name(self.course.id, "AutoGroup2")
        expected_cohorts = [
            ListCohortsTestCase.create_expected_cohort(
                self.cohort1, 3, CohortAssignmentType.NONE),
            ListCohortsTestCase.create_expected_cohort(
                self.cohort2, 2, CohortAssignmentType.NONE),
            ListCohortsTestCase.create_expected_cohort(
                self.cohort3, 2, CohortAssignmentType.NONE),
            ListCohortsTestCase.create_expected_cohort(
                auto_cohort_1, 0, CohortAssignmentType.RANDOM),
            ListCohortsTestCase.create_expected_cohort(
                auto_cohort_2, 0, CohortAssignmentType.RANDOM),
        ]
        self.verify_lists_expected_cohorts(expected_cohorts, actual_cohorts)
Ejemplo n.º 12
0
    def test_get_cohort(self):
        """
        Make sure cohorts.get_cohort() does the right thing when the course is cohorted
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertEqual(course.id, self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user = UserFactory(username="******", email="*****@*****.**")
        other_user = UserFactory(username="******", email="*****@*****.**")

        self.assertIsNone(cohorts.get_cohort(user, course.id), "No cohort created yet")

        cohort = CohortFactory(course_id=course.id, name="TestCohort")
        cohort.users.add(user)

        self.assertIsNone(
            cohorts.get_cohort(user, course.id),
            "Course isn't cohorted, so shouldn't have a cohort"
        )

        # Make the course cohorted...
        config_course_cohorts(course, discussions=[], cohorted=True)

        self.assertEquals(
            cohorts.get_cohort(user, course.id).id,
            cohort.id,
            "user should be assigned to the correct cohort"
        )
        self.assertEquals(
            cohorts.get_cohort(other_user, course.id).id,
            cohorts.get_cohort_by_name(course.id, cohorts.DEFAULT_COHORT_NAME).id,
            "other_user should be assigned to the default cohort"
        )
Ejemplo n.º 13
0
    def test_default_cohort(self):
        """
        Verify that the default cohort is not created and included in the response until students are assigned to it.
        """
        # verify the default cohort is not created when the course is not cohorted
        self.verify_lists_expected_cohorts([])

        # create a cohorted course without any auto_cohort_groups
        config_course_cohorts(self.course, [], cohorted=True)

        # verify the default cohort is not yet created until a user is assigned
        self.verify_lists_expected_cohorts([])

        # create enrolled users
        users = [UserFactory() for _ in range(3)]
        self._enroll_users(users, self.course.id)

        # mimic users accessing the discussion forum
        for user in users:
            get_cohort(user, self.course.id)

        # verify the default cohort is automatically created
        default_cohort = get_cohort_by_name(self.course.id,
                                            DEFAULT_COHORT_NAME)
        actual_cohorts = self.request_list_cohorts(self.course)
        self.verify_lists_expected_cohorts(
            [
                ListCohortsTestCase.create_expected_cohort(
                    default_cohort, len(users), CohortAssignmentType.RANDOM)
            ],
            actual_cohorts,
        )

        # set auto_cohort_groups and verify the default cohort is no longer listed as RANDOM
        config_course_cohorts(self.course, [],
                              cohorted=True,
                              auto_cohort_groups=["AutoGroup"])
        actual_cohorts = self.request_list_cohorts(self.course)
        auto_cohort = get_cohort_by_name(self.course.id, "AutoGroup")
        self.verify_lists_expected_cohorts(
            [
                ListCohortsTestCase.create_expected_cohort(
                    default_cohort, len(users), CohortAssignmentType.NONE),
                ListCohortsTestCase.create_expected_cohort(
                    auto_cohort, 0, CohortAssignmentType.RANDOM),
            ],
            actual_cohorts,
        )
Ejemplo n.º 14
0
    def test_get_course_cohorts(self):
        """
        Tests that get_course_cohorts returns all cohorts, including auto cohorts.
        """
        course = modulestore().get_course(self.toy_course_key)
        config_course_cohorts(
            course, [], cohorted=True,
            auto_cohort_groups=["AutoGroup1", "AutoGroup2"]
        )

        # add manual cohorts to course 1
        CohortFactory(course_id=course.id, name="ManualCohort")
        CohortFactory(course_id=course.id, name="ManualCohort2")

        cohort_set = {c.name for c in cohorts.get_course_cohorts(course)}
        self.assertEqual(cohort_set, {"AutoGroup1", "AutoGroup2", "ManualCohort", "ManualCohort2"})
Ejemplo n.º 15
0
    def test_is_course_cohorted(self):
        """
        Make sure cohorts.is_course_cohorted() correctly reports if a course is cohorted or not.
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)
        self.assertFalse(cohorts.is_course_cohorted(course.id))

        config_course_cohorts(course, [], cohorted=True)

        self.assertTrue(course.is_cohorted)
        self.assertTrue(cohorts.is_course_cohorted(course.id))

        # Make sure we get a Http404 if there's no course
        fake_key = SlashSeparatedCourseKey('a', 'b', 'c')
        self.assertRaises(Http404, lambda: cohorts.is_course_cohorted(fake_key))
Ejemplo n.º 16
0
    def test_get_course_cohorts(self):
        """
        Tests that get_course_cohorts returns all cohorts, including auto cohorts.
        """
        course = modulestore().get_course(self.toy_course_key)
        config_course_cohorts(course, [],
                              cohorted=True,
                              auto_cohort_groups=["AutoGroup1", "AutoGroup2"])

        # add manual cohorts to course 1
        CohortFactory(course_id=course.id, name="ManualCohort")
        CohortFactory(course_id=course.id, name="ManualCohort2")

        cohort_set = {c.name for c in cohorts.get_course_cohorts(course)}
        self.assertEqual(
            cohort_set,
            {"AutoGroup1", "AutoGroup2", "ManualCohort", "ManualCohort2"})
Ejemplo n.º 17
0
    def test_is_course_cohorted(self):
        """
        Make sure cohorts.is_course_cohorted() correctly reports if a course is cohorted or not.
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)
        self.assertFalse(cohorts.is_course_cohorted(course.id))

        config_course_cohorts(course, [], cohorted=True)

        self.assertTrue(course.is_cohorted)
        self.assertTrue(cohorts.is_course_cohorted(course.id))

        # Make sure we get a Http404 if there's no course
        fake_key = SlashSeparatedCourseKey('a', 'b', 'c')
        self.assertRaises(Http404,
                          lambda: cohorts.is_course_cohorted(fake_key))
Ejemplo n.º 18
0
    def test_get_cohort_id(self):
        """
        Make sure that cohorts.get_cohort_id() correctly returns the cohort id, or raises a ValueError when given an
        invalid course key.
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user = UserFactory(username="******", email="*****@*****.**")
        self.assertIsNone(cohorts.get_cohort_id(user, course.id))

        config_course_cohorts(course, discussions=[], cohorted=True)
        cohort = CohortFactory(course_id=course.id, name="TestCohort")
        cohort.users.add(user)
        self.assertEqual(cohorts.get_cohort_id(user, course.id), cohort.id)

        self.assertRaises(
            ValueError, lambda: cohorts.get_cohort_id(
                user, SlashSeparatedCourseKey("course", "does_not", "exist")))
Ejemplo n.º 19
0
    def test_get_cohort_id(self):
        """
        Make sure that cohorts.get_cohort_id() correctly returns the cohort id, or raises a ValueError when given an
        invalid course key.
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user = UserFactory(username="******", email="*****@*****.**")
        self.assertIsNone(cohorts.get_cohort_id(user, course.id))

        config_course_cohorts(course, discussions=[], cohorted=True)
        cohort = CohortFactory(course_id=course.id, name="TestCohort")
        cohort.users.add(user)
        self.assertEqual(cohorts.get_cohort_id(user, course.id), cohort.id)

        self.assertRaises(
            ValueError,
            lambda: cohorts.get_cohort_id(user, SlashSeparatedCourseKey("course", "does_not", "exist"))
        )
Ejemplo n.º 20
0
    def _verify_course_cohorts(self, auto_cohort, expected_cohort_set):
        """
        Helper method for testing get_course_cohorts with both manual and auto cohorts.
        """
        course = modulestore().get_course(self.toy_course_key)
        config_course_cohorts(course, [],
                              cohorted=True,
                              auto_cohort=auto_cohort,
                              auto_cohort_groups=["AutoGroup1", "AutoGroup2"])

        # add manual cohorts to course 1
        CourseUserGroup.objects.create(name="ManualCohort",
                                       course_id=course.location.course_key,
                                       group_type=CourseUserGroup.COHORT)

        CourseUserGroup.objects.create(name="ManualCohort2",
                                       course_id=course.location.course_key,
                                       group_type=CourseUserGroup.COHORT)

        cohort_set = {c.name for c in cohorts.get_course_cohorts(course)}
        self.assertEqual(cohort_set, expected_cohort_set)
Ejemplo n.º 21
0
    def test_get_cohorted_commentables(self):
        """
        Make sure cohorts.get_cohorted_commentables() correctly returns a list of strings representing cohorted
        commentables.  Also verify that we can't get the cohorted commentables from a course which does not exist.
        """
        course = modulestore().get_course(self.toy_course_key)

        self.assertEqual(cohorts.get_cohorted_commentables(course.id), set())

        config_course_cohorts(course, [], cohorted=True)
        self.assertEqual(cohorts.get_cohorted_commentables(course.id), set())

        config_course_cohorts(course, ["General", "Feedback"],
                              cohorted=True,
                              cohorted_discussions=["Feedback"])
        self.assertItemsEqual(cohorts.get_cohorted_commentables(course.id),
                              set([topic_name_to_id(course, "Feedback")]))

        config_course_cohorts(course, ["General", "Feedback"],
                              cohorted=True,
                              cohorted_discussions=["General", "Feedback"])
        self.assertItemsEqual(
            cohorts.get_cohorted_commentables(course.id),
            set([
                topic_name_to_id(course, "General"),
                topic_name_to_id(course, "Feedback")
            ]))
        self.assertRaises(
            Http404, lambda: cohorts.get_cohorted_commentables(
                SlashSeparatedCourseKey("course", "does_not", "exist")))
Ejemplo n.º 22
0
    def test_default_cohort(self):
        """
        Verify that the default cohort is not created and included in the response until students are assigned to it.
        """
        # verify the default cohort is not created when the course is not cohorted
        self.verify_lists_expected_cohorts([])

        # create a cohorted course without any auto_cohort_groups
        config_course_cohorts(self.course, [], cohorted=True)

        # verify the default cohort is not yet created until a user is assigned
        self.verify_lists_expected_cohorts([])

        # create enrolled users
        users = [UserFactory() for _ in range(3)]
        self._enroll_users(users, self.course.id)

        # mimic users accessing the discussion forum
        for user in users:
            get_cohort(user, self.course.id)

        # verify the default cohort is automatically created
        default_cohort = get_cohort_by_name(self.course.id, DEFAULT_COHORT_NAME)
        actual_cohorts = self.request_list_cohorts(self.course)
        self.verify_lists_expected_cohorts(
            [ListCohortsTestCase.create_expected_cohort(default_cohort, len(users), CohortAssignmentType.RANDOM)],
            actual_cohorts,
        )

        # set auto_cohort_groups and verify the default cohort is no longer listed as RANDOM
        config_course_cohorts(self.course, [], cohorted=True, auto_cohort_groups=["AutoGroup"])
        actual_cohorts = self.request_list_cohorts(self.course)
        auto_cohort = get_cohort_by_name(self.course.id, "AutoGroup")
        self.verify_lists_expected_cohorts(
            [
                ListCohortsTestCase.create_expected_cohort(default_cohort, len(users), CohortAssignmentType.NONE),
                ListCohortsTestCase.create_expected_cohort(auto_cohort, 0, CohortAssignmentType.RANDOM),
            ],
            actual_cohorts,
        )
Ejemplo n.º 23
0
    def test_get_cohorted_commentables(self):
        """
        Make sure cohorts.get_cohorted_commentables() correctly returns a list of strings representing cohorted
        commentables.  Also verify that we can't get the cohorted commentables from a course which does not exist.
        """
        course = modulestore().get_course(self.toy_course_key)

        self.assertEqual(cohorts.get_cohorted_commentables(course.id), set())

        config_course_cohorts(course, [], cohorted=True)
        self.assertEqual(cohorts.get_cohorted_commentables(course.id), set())

        config_course_cohorts(
            course, ["General", "Feedback"],
            cohorted=True,
            cohorted_discussions=["Feedback"]
        )
        self.assertItemsEqual(
            cohorts.get_cohorted_commentables(course.id),
            set([topic_name_to_id(course, "Feedback")])
        )

        config_course_cohorts(
            course, ["General", "Feedback"],
            cohorted=True,
            cohorted_discussions=["General", "Feedback"]
        )
        self.assertItemsEqual(
            cohorts.get_cohorted_commentables(course.id),
            set([topic_name_to_id(course, "General"), topic_name_to_id(course, "Feedback")])
        )
        self.assertRaises(
            Http404,
            lambda: cohorts.get_cohorted_commentables(SlashSeparatedCourseKey("course", "does_not", "exist"))
        )
Ejemplo n.º 24
0
    def test_auto_cohorts(self):
        """
        Verify that auto cohorts are included in the response.
        """
        config_course_cohorts(self.course, [], cohorted=True,
                              auto_cohort_groups=["AutoGroup1", "AutoGroup2"])

        # Will create cohort1, cohort2, and cohort3. Auto cohorts remain uncreated.
        self._create_cohorts()
        # Get the cohorts from the course, which will cause auto cohorts to be created.
        actual_cohorts = self.request_list_cohorts(self.course)
        # Get references to the created auto cohorts.
        auto_cohort_1 = get_cohort_by_name(self.course.id, "AutoGroup1")
        auto_cohort_2 = get_cohort_by_name(self.course.id, "AutoGroup2")
        expected_cohorts = [
            ListCohortsTestCase.create_expected_cohort(self.cohort1, 3, CohortAssignmentType.NONE),
            ListCohortsTestCase.create_expected_cohort(self.cohort2, 2, CohortAssignmentType.NONE),
            ListCohortsTestCase.create_expected_cohort(self.cohort3, 2, CohortAssignmentType.NONE),
            ListCohortsTestCase.create_expected_cohort(auto_cohort_1, 0, CohortAssignmentType.RANDOM),
            ListCohortsTestCase.create_expected_cohort(auto_cohort_2, 0, CohortAssignmentType.RANDOM),
        ]
        self.verify_lists_expected_cohorts(expected_cohorts, actual_cohorts)
Ejemplo n.º 25
0
    def test_auto_cohorting(self):
        """
        Make sure cohorts.get_cohort() does the right thing when the course is auto_cohorted
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user1 = User.objects.create(username="******", email="*****@*****.**")
        user2 = User.objects.create(username="******", email="*****@*****.**")
        user3 = User.objects.create(username="******", email="*****@*****.**")

        cohort = CourseUserGroup.objects.create(
            name="TestCohort",
            course_id=course.id,
            group_type=CourseUserGroup.COHORT)

        # user1 manually added to a cohort
        cohort.users.add(user1)

        # Make the course auto cohorted...
        config_course_cohorts(course, [],
                              cohorted=True,
                              auto_cohort=True,
                              auto_cohort_groups=["AutoGroup"])

        self.assertEquals(
            cohorts.get_cohort(user1, course.id).id, cohort.id,
            "user1 should stay put")

        self.assertEquals(
            cohorts.get_cohort(user2, course.id).name, "AutoGroup",
            "user2 should be auto-cohorted")

        # Now make the group list empty
        config_course_cohorts(course, [],
                              cohorted=True,
                              auto_cohort=True,
                              auto_cohort_groups=[])

        self.assertEquals(cohorts.get_cohort(user3, course.id), None,
                          "No groups->no auto-cohorting")

        # Now make it different
        config_course_cohorts(course, [],
                              cohorted=True,
                              auto_cohort=True,
                              auto_cohort_groups=["OtherGroup"])

        self.assertEquals(
            cohorts.get_cohort(user3, course.id).name, "OtherGroup",
            "New list->new group")
        self.assertEquals(
            cohorts.get_cohort(user2, course.id).name, "AutoGroup",
            "user2 should still be in originally placed cohort")
Ejemplo n.º 26
0
    def test_auto_cohorting(self):
        """
        Make sure cohorts.get_cohort() does the right thing when the course is auto_cohorted
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user1 = User.objects.create(username="******", email="*****@*****.**")
        user2 = User.objects.create(username="******", email="*****@*****.**")
        user3 = User.objects.create(username="******", email="*****@*****.**")

        cohort = CourseUserGroup.objects.create(name="TestCohort",
                                                course_id=course.id,
                                                group_type=CourseUserGroup.COHORT)

        # user1 manually added to a cohort
        cohort.users.add(user1)

        # Make the course auto cohorted...
        config_course_cohorts(
            course, [], cohorted=True,
            auto_cohort=True,
            auto_cohort_groups=["AutoGroup"]
        )

        self.assertEquals(cohorts.get_cohort(user1, course.id).id, cohort.id,
                          "user1 should stay put")

        self.assertEquals(cohorts.get_cohort(user2, course.id).name, "AutoGroup",
                          "user2 should be auto-cohorted")

        # Now make the group list empty
        config_course_cohorts(
            course, [], cohorted=True,
            auto_cohort=True,
            auto_cohort_groups=[]
        )

        self.assertEquals(cohorts.get_cohort(user3, course.id), None,
                          "No groups->no auto-cohorting")

        # Now make it different
        config_course_cohorts(
            course, [], cohorted=True,
            auto_cohort=True,
            auto_cohort_groups=["OtherGroup"]
        )

        self.assertEquals(cohorts.get_cohort(user3, course.id).name, "OtherGroup",
                          "New list->new group")
        self.assertEquals(cohorts.get_cohort(user2, course.id).name, "AutoGroup",
                          "user2 should still be in originally placed cohort")
Ejemplo n.º 27
0
    def test_is_commentable_cohorted(self):
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        def to_id(name):
            return topic_name_to_id(course, name)

        # no topics
        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course doesn't even have a 'General' topic"
        )

        # not cohorted
        config_course_cohorts(course, ["General", "Feedback"], cohorted=False)

        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course isn't cohorted"
        )

        # cohorted, but top level topics aren't
        config_course_cohorts(course, ["General", "Feedback"], cohorted=True)

        self.assertTrue(course.is_cohorted)
        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course is cohorted, but 'General' isn't."
        )
        self.assertTrue(
            cohorts.is_commentable_cohorted(course.id, to_id("random")),
            "Non-top-level discussion is always cohorted in cohorted courses."
        )

        # cohorted, including "Feedback" top-level topics aren't
        config_course_cohorts(
            course, ["General", "Feedback"],
            cohorted=True,
            cohorted_discussions=["Feedback"]
        )

        self.assertTrue(course.is_cohorted)
        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course is cohorted, but 'General' isn't."
        )
        self.assertTrue(
            cohorts.is_commentable_cohorted(course.id, to_id("Feedback")),
            "Feedback was listed as cohorted.  Should be."
        )
Ejemplo n.º 28
0
    def test_is_commentable_cohorted(self):
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        def to_id(name):
            return topic_name_to_id(course, name)

        # no topics
        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course doesn't even have a 'General' topic")

        # not cohorted
        config_course_cohorts(course, ["General", "Feedback"], cohorted=False)

        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course isn't cohorted")

        # cohorted, but top level topics aren't
        config_course_cohorts(course, ["General", "Feedback"], cohorted=True)

        self.assertTrue(course.is_cohorted)
        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course is cohorted, but 'General' isn't.")

        self.assertTrue(
            cohorts.is_commentable_cohorted(course.id, to_id("random")),
            "Non-top-level discussion is always cohorted in cohorted courses.")

        # cohorted, including "Feedback" top-level topics aren't
        config_course_cohorts(course, ["General", "Feedback"],
                              cohorted=True,
                              cohorted_discussions=["Feedback"])

        self.assertTrue(course.is_cohorted)
        self.assertFalse(
            cohorts.is_commentable_cohorted(course.id, to_id("General")),
            "Course is cohorted, but 'General' isn't.")

        self.assertTrue(
            cohorts.is_commentable_cohorted(course.id, to_id("Feedback")),
            "Feedback was listed as cohorted.  Should be.")
Ejemplo n.º 29
0
    def test_auto_cohorting(self):
        """
        Make sure cohorts.get_cohort() does the right thing with auto_cohort_groups
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user1 = UserFactory(username="******", email="*****@*****.**")
        user2 = UserFactory(username="******", email="*****@*****.**")
        user3 = UserFactory(username="******", email="*****@*****.**")
        user4 = UserFactory(username="******", email="*****@*****.**")

        cohort = CohortFactory(course_id=course.id, name="TestCohort")

        # user1 manually added to a cohort
        cohort.users.add(user1)

        # Add an auto_cohort_group to the course...
        config_course_cohorts(course,
                              discussions=[],
                              cohorted=True,
                              auto_cohort_groups=["AutoGroup"])

        self.assertEquals(
            cohorts.get_cohort(user1, course.id).id, cohort.id,
            "user1 should stay put")

        self.assertEquals(
            cohorts.get_cohort(user2, course.id).name, "AutoGroup",
            "user2 should be auto-cohorted")

        # Now make the auto_cohort_group list empty
        config_course_cohorts(course,
                              discussions=[],
                              cohorted=True,
                              auto_cohort_groups=[])

        self.assertEquals(
            cohorts.get_cohort(user3, course.id).id,
            cohorts.get_cohort_by_name(course.id,
                                       cohorts.DEFAULT_COHORT_NAME).id,
            "No groups->default cohort")

        # Now set the auto_cohort_group to something different
        config_course_cohorts(course,
                              discussions=[],
                              cohorted=True,
                              auto_cohort_groups=["OtherGroup"])

        self.assertEquals(
            cohorts.get_cohort(user4, course.id).name, "OtherGroup",
            "New list->new group")
        self.assertEquals(
            cohorts.get_cohort(user1, course.id).name, "TestCohort",
            "user1 should still be in originally placed cohort")
        self.assertEquals(
            cohorts.get_cohort(user2, course.id).name, "AutoGroup",
            "user2 should still be in originally placed cohort")
        self.assertEquals(
            cohorts.get_cohort(user3, course.id).name,
            cohorts.get_cohort_by_name(course.id,
                                       cohorts.DEFAULT_COHORT_NAME).name,
            "user3 should still be in the default cohort")
Ejemplo n.º 30
0
    def test_auto_cohorting(self):
        """
        Make sure cohorts.get_cohort() does the right thing with auto_cohort_groups
        """
        course = modulestore().get_course(self.toy_course_key)
        self.assertFalse(course.is_cohorted)

        user1 = UserFactory(username="******", email="*****@*****.**")
        user2 = UserFactory(username="******", email="*****@*****.**")
        user3 = UserFactory(username="******", email="*****@*****.**")
        user4 = UserFactory(username="******", email="*****@*****.**")

        cohort = CohortFactory(course_id=course.id, name="TestCohort")

        # user1 manually added to a cohort
        cohort.users.add(user1)

        # Add an auto_cohort_group to the course...
        config_course_cohorts(
            course,
            discussions=[],
            cohorted=True,
            auto_cohort_groups=["AutoGroup"]
        )

        self.assertEquals(cohorts.get_cohort(user1, course.id).id, cohort.id, "user1 should stay put")

        self.assertEquals(cohorts.get_cohort(user2, course.id).name, "AutoGroup", "user2 should be auto-cohorted")

        # Now make the auto_cohort_group list empty
        config_course_cohorts(
            course,
            discussions=[],
            cohorted=True,
            auto_cohort_groups=[]
        )

        self.assertEquals(
            cohorts.get_cohort(user3, course.id).id,
            cohorts.get_cohort_by_name(course.id, cohorts.DEFAULT_COHORT_NAME).id,
            "No groups->default cohort"
        )

        # Now set the auto_cohort_group to something different
        config_course_cohorts(
            course,
            discussions=[],
            cohorted=True,
            auto_cohort_groups=["OtherGroup"]
        )

        self.assertEquals(
            cohorts.get_cohort(user4, course.id).name, "OtherGroup", "New list->new group"
        )
        self.assertEquals(
            cohorts.get_cohort(user1, course.id).name, "TestCohort", "user1 should still be in originally placed cohort"
        )
        self.assertEquals(
            cohorts.get_cohort(user2, course.id).name, "AutoGroup", "user2 should still be in originally placed cohort"
        )
        self.assertEquals(
            cohorts.get_cohort(user3, course.id).name,
            cohorts.get_cohort_by_name(course.id, cohorts.DEFAULT_COHORT_NAME).name,
            "user3 should still be in the default cohort"
        )