def add_user_to_team(self, user_row): """ Creates a CourseTeamMembership entry - i.e: a relationship between a user and a team. user_row is a dictionary where key is column name and value is the row value. {'mode': ' masters','topic_0': '','topic_1': 'team 2','topic_2': None,'user': <user_obj>} andrew,masters,team1,,team3 joe,masters,,team2,team3 """ user = user_row['user'] for teamset_id in self.teamset_ids: team_name = user_row[teamset_id] if not team_name: continue if (team_name, teamset_id) not in self.existing_course_teams: protection_status = user_organization_protection_status( user, self.course.id) team = CourseTeam.create( name=team_name, course_id=self.course.id, description='Import from csv', topic_id=teamset_id, organization_protected=protection_status == OrganizationProtectionStatus.protected) team.save() self.existing_course_teams[(team_name, teamset_id)] = team else: team = self.existing_course_teams[(team_name, teamset_id)] team.add_user(user) emit_team_event( 'edx.team.learner_added', team.course_id, { 'team_id': team.team_id, 'user_id': user.id, 'add_method': 'team_csv_import' })
def test_user_organization_protection_status(self, username, expected_protection_status): user = self.users[username] try: self.assertEqual( expected_protection_status, teams_api.user_organization_protection_status(user, COURSE_KEY1) ) except ValueError: self.assertFalse(CourseEnrollment.is_enrolled(user, COURSE_KEY1))
def test_team_counter_add_team_count(self, username, expected_team_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 topic = {'id': self.topic_id} teams_api.add_team_count(user, [topic], COURSE_KEY1, organization_protection_status) self.assertEqual(expected_team_count, topic.get('team_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())
def test_user_organization_protection_status(self, username, expected_protection_status): user = self.users[username] try: assert expected_protection_status == teams_api.user_organization_protection_status(user, COURSE_KEY1) except ValueError: assert not CourseEnrollment.is_enrolled(user, COURSE_KEY1)