Пример #1
0
 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:
             team = CourseTeam.create(name=team_name,
                                      course_id=self.course.id,
                                      description='Import from csv',
                                      topic_id=teamset_id)
             team.save()
         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'
             })
         self.number_of_records_added += 1
Пример #2
0
 def create(self, validated_data):
     team = CourseTeam.create(
         name=validated_data.get("name", ''),
         course_id=validated_data.get("course_id"),
         description=validated_data.get("description", ''),
         topic_id=validated_data.get("topic_id", ''),
         country=validated_data.get("country", ''),
         language=validated_data.get("language", ''),
     )
     team.save()
     return team
Пример #3
0
 def create(self, validated_data):
     team = CourseTeam.create(
         name=validated_data.get("name", ''),
         course_id=validated_data.get("course_id"),
         description=validated_data.get("description", ''),
         topic_id=validated_data.get("topic_id", ''),
         country=validated_data.get("country", ''),
         language=validated_data.get("language", ''),
     )
     team.save()
     return team
Пример #4
0
 def test_get_team_multiple_teams(self, mocked_manager):
     """
     This is a test for a use case that is very unlikely to occur.
     Currently users cannot be in multiple teams in a course, but even after we allow multiple
     teams in a course then they should still be limited to one team per topic
     """
     mocked_manager.get.side_effect = CourseTeam.MultipleObjectsReturned()
     expected_result = "This is somehow the first team"
     mock_qs = mock.MagicMock()
     mock_qs.first.return_value = expected_result
     mocked_manager.filter.return_value = mock_qs
     result = teams_api.get_team_for_user_course_topic(self.user1, str(COURSE_KEY1), TOPIC1)
     assert result == expected_result