Skip to content

Commit

Permalink
fix: handle dupe user case for mgmt cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
varshamenon4 committed Apr 19, 2024
1 parent 171f316 commit f8a7f29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]'
lines = [f'{username},{email},{self.course_role},{self.course_id}\n',
f'{username},{email},{self.course_role},{self.course_id}\n']
course_id_2 = 'course-v1:edx+test+f21'

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)

0 comments on commit f8a7f29

Please sign in to comment.