diff --git a/edx_exams/apps/core/management/commands/bulk_add_course_staff.py b/edx_exams/apps/core/management/commands/bulk_add_course_staff.py index c59da559..23204ea0 100644 --- a/edx_exams/apps/core/management/commands/bulk_add_course_staff.py +++ b/edx_exams/apps/core/management/commands/bulk_add_course_staff.py @@ -68,6 +68,7 @@ def add_course_staff_from_csv(self, csv_file, batch_size, batch_delay): for row in reader: if row.get('username') not in users_existing: users_to_create.append(row) + users_existing.add(row.get('username')) # bulk create users for i in range(0, len(users_to_create), batch_size): diff --git a/edx_exams/apps/core/management/commands/test/test_bulk_add_course_staff.py b/edx_exams/apps/core/management/commands/test/test_bulk_add_course_staff.py index aca30f0c..0b6e80e7 100644 --- a/edx_exams/apps/core/management/commands/test/test_bulk_add_course_staff.py +++ b/edx_exams/apps/core/management/commands/test/test_bulk_add_course_staff.py @@ -117,3 +117,16 @@ def test_num_queries_correct(self): csv = self._write_test_csv(csv, lines) with self.assertNumQueries(5 + num_lines): call_command(self.command, f'--csv_path={csv.name}') + + def test_dupe_user_csv(self): + """ Assert that the course staff roles are correctly created given duplicate users in csv """ + username, email = 'pam', 'pam@pond.com' + course_id_2 = 'course-v1:edx+test+f21' + lines = [f'{username},{email},{self.course_role},{self.course_id}\n', + f'{username},{email},{self.course_role},{course_id_2}\n'] + + with NamedTemporaryFile() as csv: + csv = self._write_test_csv(csv, lines) + call_command(self.command, f'--csv_path={csv.name}') + self._assert_user_and_role(username, email, self.course_role, self.course_id) + self._assert_user_and_role(username, email, self.course_role, course_id_2)