Esempio n. 1
0
    def test_delete_empty_cohort(self):
        """
        Make sure that cohorts.delete_empty_cohort() properly removes an empty cohort
        for a given course.
        """
        course = modulestore().get_course(self.toy_course_key)
        user = User.objects.create(username="******", email="*****@*****.**")
        empty_cohort = CourseUserGroup.objects.create(
            name="EmptyCohort",
            course_id=course.id,
            group_type=CourseUserGroup.COHORT)
        nonempty_cohort = CourseUserGroup.objects.create(
            name="NonemptyCohort",
            course_id=course.id,
            group_type=CourseUserGroup.COHORT)
        nonempty_cohort.users.add(user)

        cohorts.delete_empty_cohort(course.id, "EmptyCohort")

        # Make sure we cannot access the deleted cohort
        self.assertRaises(
            CourseUserGroup.DoesNotExist, lambda: CourseUserGroup.objects.get(
                course_id=course.id,
                group_type=CourseUserGroup.COHORT,
                id=empty_cohort.id))
        self.assertRaises(
            ValueError,
            lambda: cohorts.delete_empty_cohort(course.id, "NonemptyCohort"))
        self.assertRaises(
            CourseUserGroup.DoesNotExist, lambda: cohorts.delete_empty_cohort(
                SlashSeparatedCourseKey('course', 'does_not', 'exist'),
                "EmptyCohort"))
        self.assertRaises(
            CourseUserGroup.DoesNotExist, lambda: cohorts.delete_empty_cohort(
                course.id, "NonExistentCohort"))
Esempio n. 2
0
    def test_delete_empty_cohort(self):
        """
        Make sure that cohorts.delete_empty_cohort() properly removes an empty cohort
        for a given course.
        """
        course = modulestore().get_course(self.toy_course_key)
        user = UserFactory(username="******", email="*****@*****.**")
        empty_cohort = CohortFactory(course_id=course.id, name="EmptyCohort")
        nonempty_cohort = CohortFactory(course_id=course.id, name="NonemptyCohort")
        nonempty_cohort.users.add(user)

        cohorts.delete_empty_cohort(course.id, "EmptyCohort")

        # Make sure we cannot access the deleted cohort
        self.assertRaises(
            CourseUserGroup.DoesNotExist,
            lambda: cohorts.get_cohort_by_id(course.id, empty_cohort.id)
        )
        self.assertRaises(
            ValueError,
            lambda: cohorts.delete_empty_cohort(course.id, "NonemptyCohort")
        )
        self.assertRaises(
            CourseUserGroup.DoesNotExist,
            lambda: cohorts.delete_empty_cohort(SlashSeparatedCourseKey('course', 'does_not', 'exist'), "EmptyCohort")
        )
        self.assertRaises(
            CourseUserGroup.DoesNotExist,
            lambda: cohorts.delete_empty_cohort(course.id, "NonExistentCohort")
        )
Esempio n. 3
0
    def test_workgroups_users_post_with_cohort_backfill(self):
        """
        This test asserts a case where a workgroup was created before the existence of a cohorted discussion
        """
        data = {
            'name': self.test_workgroup_name,
            'project': self.test_project.id
        }
        response = self.do_post(self.test_workgroups_uri, data)
        self.assertEqual(response.status_code, 201)
        test_uri = '{}{}/'.format(self.test_workgroups_uri, str(response.data['id']))
        users_uri = '{}users/'.format(test_uri)
        data = {"id": self.test_user.id}
        response = self.do_post(users_uri, data)
        self.assertEqual(response.status_code, 201)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['users'][0]['id'], self.test_user.id)

        cohort_name = Workgroup.cohort_name_for_workgroup(
            self.test_project.id,
            response.data['id'],
            self.test_workgroup_name
        )

        # now let's remove existing cohort users
        cohort = get_cohort_by_name(self.test_course.id, cohort_name, CourseUserGroup.WORKGROUP)
        self.assertTrue(is_user_in_cohort(cohort, self.test_user.id, CourseUserGroup.WORKGROUP))

        remove_user_from_cohort(cohort, self.test_user.username, CourseUserGroup.WORKGROUP)
        self.assertFalse(is_user_in_cohort(cohort, self.test_user.id, CourseUserGroup.WORKGROUP))

        # delete cohort
        delete_empty_cohort(self.test_course.id, cohort_name, CourseUserGroup.WORKGROUP)
        self.assertEqual(0, len(get_course_cohort_names(self.test_course.id, CourseUserGroup.WORKGROUP)))

        # add a 2nd user and make sure a discussion cohort was created and users were backfilled
        test_uri = '{}{}/'.format(self.test_workgroups_uri, str(response.data['id']))
        users_uri = '{}users/'.format(test_uri)
        data = {"id": self.test_user2.id}
        response = self.do_post(users_uri, data)
        self.assertEqual(response.status_code, 201)

        # now inspect cohort and assert that things are as we anticipate (i.e. both users are in there)
        cohort = get_cohort_by_name(self.test_course.id, cohort_name, CourseUserGroup.WORKGROUP)
        self.assertIsNotNone(cohort)
        self.assertTrue(is_user_in_cohort(cohort, self.test_user.id, CourseUserGroup.WORKGROUP))
        self.assertTrue(is_user_in_cohort(cohort, self.test_user2.id, CourseUserGroup.WORKGROUP))