Commit 21ef60b4 by Albert St. Aubin

Added filter to the cohort user count data to show the counts of only

active users
parent c98fb5b6
...@@ -838,6 +838,7 @@ class AddUsersToCohortTestCase(CohortViewsTestCase): ...@@ -838,6 +838,7 @@ class AddUsersToCohortTestCase(CohortViewsTestCase):
else: else:
response = add_users_to_cohort(request, unicode(course.id), cohort.id) response = add_users_to_cohort(request, unicode(course.id), cohort.id)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
return json.loads(response.content) return json.loads(response.content)
def verify_added_users_to_cohort(self, response_dict, cohort, course, expected_added, expected_changed, def verify_added_users_to_cohort(self, response_dict, cohort, course, expected_added, expected_changed,
...@@ -993,22 +994,37 @@ class AddUsersToCohortTestCase(CohortViewsTestCase): ...@@ -993,22 +994,37 @@ class AddUsersToCohortTestCase(CohortViewsTestCase):
expected_unknown=usernames expected_unknown=usernames
) )
def check_user_count(self, expected_count, cohort):
"""
Check that the expected number of users are present in the user_count returned by the view handler
"""
cohort_listed = False
for c in self.get_handler(self.course)['cohorts']:
if c['name'] == cohort.name:
cohort_listed = True
self.assertEqual(expected_count, c['user_count'])
self.assertTrue(cohort_listed)
def test_all(self): def test_all(self):
""" """
Test all adding conditions together. Test all adding conditions together.
""" """
unknowns = ["unknown_user{}".format(i) for i in range(3)] unknowns = ["unknown_user{}".format(i) for i in range(3)]
new_users = self.cohortless_users + self.cohort1_users + self.cohort2_users + self.cohort3_users
response_dict = self.request_add_users_to_cohort( response_dict = self.request_add_users_to_cohort(
",".join( ",".join(
unknowns + unknowns +
[ [
user.username user.username
for user in self.cohortless_users + self.cohort1_users + self.cohort2_users + self.cohort3_users for user in new_users
] ]
), ),
self.cohort1, self.cohort1,
self.course self.course
) )
self.check_user_count(expected_count=len(new_users), cohort=self.cohort1)
self.verify_added_users_to_cohort( self.verify_added_users_to_cohort(
response_dict, response_dict,
self.cohort1, self.cohort1,
...@@ -1077,14 +1093,19 @@ class AddUsersToCohortTestCase(CohortViewsTestCase): ...@@ -1077,14 +1093,19 @@ class AddUsersToCohortTestCase(CohortViewsTestCase):
""" """
Verify that users can be added to a cohort of a course they're not Verify that users can be added to a cohort of a course they're not
enrolled in. This feature is currently used to pre-cohort users that enrolled in. This feature is currently used to pre-cohort users that
are expected to enroll in a course. are expected to enroll in a course. Also tests that adding unenrolled
users does not alter the number of "active" users in the user_count.
""" """
start_count = self.cohort1.users.count()
unenrolled_usernames = [user.username for user in self.unenrolled_users] unenrolled_usernames = [user.username for user in self.unenrolled_users]
response_dict = self.request_add_users_to_cohort( response_dict = self.request_add_users_to_cohort(
",".join(unenrolled_usernames), ",".join(unenrolled_usernames),
self.cohort1, self.cohort1,
self.course self.course
) )
self.check_user_count(expected_count=start_count, cohort=self.cohort1)
self.verify_added_users_to_cohort( self.verify_added_users_to_cohort(
response_dict, response_dict,
self.cohort1, self.cohort1,
......
...@@ -90,7 +90,8 @@ def _get_cohort_representation(cohort, course): ...@@ -90,7 +90,8 @@ def _get_cohort_representation(cohort, course):
return { return {
'name': cohort.name, 'name': cohort.name,
'id': cohort.id, 'id': cohort.id,
'user_count': cohort.users.count(), 'user_count': cohort.users.filter(courseenrollment__course_id=course.location.course_key,
courseenrollment__is_active=1).count(),
'assignment_type': assignment_type, 'assignment_type': assignment_type,
'user_partition_id': partition_id, 'user_partition_id': partition_id,
'group_id': group_id, 'group_id': group_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment