def test_get_cohort(self): """ Make sure get_cohort() does the right thing when the course is cohorted """ course = modulestore().get_course("edX/toy/2012_Fall") self.assertEqual(course.id, "edX/toy/2012_Fall") self.assertFalse(course.is_cohorted) user = User.objects.create(username="******", email="*****@*****.**") other_user = User.objects.create(username="******", email="*****@*****.**") self.assertIsNone(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(get_cohort(user, course.id), "Course isn't cohorted, so shouldn't have a cohort") # Make the course cohorted... self.config_course_cohorts(course, [], cohorted=True) self.assertEquals(get_cohort(user, course.id).id, cohort.id, "Should find the right cohort") self.assertEquals(get_cohort(other_user, course.id), None, "other_user shouldn't have a cohort")
def test_get_cohort(self): """ Make sure 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(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(get_cohort(user, course.id), "Course isn't cohorted, so shouldn't have a cohort") # Make the course cohorted... self.config_course_cohorts(course, [], cohorted=True) self.assertEquals(get_cohort(user, course.id).id, cohort.id, "Should find the right cohort") self.assertEquals(get_cohort(other_user, course.id), None, "other_user shouldn't have a cohort")
def test_auto_cohorting_randomization(self): """ Make sure get_cohort() randomizes properly. """ course = modulestore().get_course("edX/toy/2012_Fall") self.assertEqual(course.id, "edX/toy/2012_Fall") self.assertFalse(course.is_cohorted) groups = ["group_{0}".format(n) for n in range(5)] self.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)) 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 = get_cohort_by_name(course.id, cohort_name) num_users = cohort.users.count() self.assertGreater(num_users, 1) self.assertLess(num_users, 50)
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" )
def test_auto_cohorting_randomization(self): """ Make sure 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)] self.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)) 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 = get_cohort_by_name(course.id, cohort_name) num_users = cohort.users.count() self.assertGreater(num_users, 1) self.assertLess(num_users, 50)
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")
def test_auto_cohorting(self): """ Make sure get_cohort() does the right thing when the course is auto_cohorted """ course = modulestore().get_course("edX/toy/2012_Fall") self.assertEqual(course.id, "edX/toy/2012_Fall") 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... self.config_course_cohorts(course, [], cohorted=True, auto_cohort=True, auto_cohort_groups=["AutoGroup"]) self.assertEquals( get_cohort(user1, course.id).id, cohort.id, "user1 should stay put") self.assertEquals( get_cohort(user2, course.id).name, "AutoGroup", "user2 should be auto-cohorted") # Now make the group list empty self.config_course_cohorts(course, [], cohorted=True, auto_cohort=True, auto_cohort_groups=[]) self.assertEquals(get_cohort(user3, course.id), None, "No groups->no auto-cohorting") # Now make it different self.config_course_cohorts(course, [], cohorted=True, auto_cohort=True, auto_cohort_groups=["OtherGroup"]) self.assertEquals( get_cohort(user3, course.id).name, "OtherGroup", "New list->new group") self.assertEquals( get_cohort(user2, course.id).name, "AutoGroup", "user2 should still be in originally placed cohort")
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")
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, )
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, )
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" )
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")