def get_team_count(self, topic): """Get the number of teams associated with this topic""" # If team_count is already present (possible if topic data was pre-processed for sorting), return it. if 'team_count' in topic: return topic['team_count'] else: return get_teams_accessible_by_user( self.context.get('user'), [topic['id']], self.context['course_id'], self.context.get('organization_protection_status')).count()
def test_team_counter_get_teams_accessible_by_user(self, username, expected_count): user = self.users[username] try: organization_protection_status = teams_api.user_organization_protection_status( user, COURSE_KEY1) except ValueError: self.assertFalse(CourseEnrollment.is_enrolled(user, COURSE_KEY1)) return teams_query_set = teams_api.get_teams_accessible_by_user( user, [self.topic_id], COURSE_KEY1, organization_protection_status) self.assertEqual(expected_count, teams_query_set.count())