two csv upload team-creation bugs (#23036)

fix csv-upload bugs
This commit is contained in:
Jansen Kantor
2020-02-13 17:16:00 -05:00
committed by GitHub
parent 61154f5dbc
commit cec654f753
2 changed files with 32 additions and 0 deletions

View File

@@ -292,6 +292,9 @@ class TeamMembershipImportManager(object):
topic_id=teamset_id
)
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',

View File

@@ -1755,6 +1755,10 @@ class TestBulkMembershipManagement(TeamAPITestCase):
201, method='post',
data={'csv': csv_file}, user='staff'
)
self.assertEqual(
CourseTeam.objects.filter(name='team 2', course_id=self.test_course_1.id).count(),
1
)
def test_upload_non_existing_user(self):
csv_content = 'user,mode,topic_0' + '\n'
@@ -1765,3 +1769,28 @@ class TestBulkMembershipManagement(TeamAPITestCase):
400, method='post',
data={'csv': csv_file}, user='staff'
)
def test_upload_only_existing_courses(self):
self.create_and_enroll_student(username='a_user')
self.create_and_enroll_student(username='b_user')
existing_team_1 = CourseTeamFactory.create(course_id=self.test_course_1.id, topic_id='topic_1')
existing_team_2 = CourseTeamFactory.create(course_id=self.test_course_1.id, topic_id='topic_2')
csv_content = 'user,mode,topic_1,topic_2' + '\n'
csv_content += 'a_user, masters,{},{}'.format(
existing_team_1.name,
existing_team_2.name
) + '\n'
csv_content += 'b_user, masters,{},{}'.format(
existing_team_1.name,
existing_team_2.name
) + '\n'
csv_file = SimpleUploadedFile('test_file.csv', csv_content.encode('utf8'), content_type='text/csv')
self.client.login(username=self.users['course_staff'].username, password=self.users['course_staff'].password)
self.make_call(
reverse('team_membership_bulk_management', args=[self.good_course_id]),
201,
method='post',
data={'csv': csv_file},
user='staff'
)