-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle dupes course staff mgmt command
- Loading branch information
1 parent
53d4213
commit e558965
Showing
2 changed files
with
41 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from django.test import TestCase | ||
|
||
from edx_exams.apps.core.models import CourseStaffRole, User | ||
from edx_exams.apps.core.test_utils.factories import UserFactory | ||
from edx_exams.apps.core.test_utils.factories import CourseStaffRoleFactory, UserFactory | ||
|
||
|
||
class TestBulkAddCourseStaff(TestCase): | ||
|
@@ -90,7 +90,7 @@ def test_add_course_staff_with_not_default_batch_size(self): | |
'sam,[email protected],staff,course-v1:edx+test+f20\n'] | ||
with NamedTemporaryFile() as csv: | ||
csv = self._write_test_csv(csv, lines) | ||
with self.assertNumQueries(9): | ||
with self.assertNumQueries(8): | ||
call_command(self.command, f'--csv_path={csv.name}', '--batch_size=1') | ||
|
||
def test_add_course_staff_with_not_default_batch_delay(self): | ||
|
@@ -115,7 +115,7 @@ def test_num_queries_correct(self): | |
lines = [f'pam{i},pam{i}@pond.com,staff,course-v1:edx+test+f20\n' for i in range(num_lines)] | ||
with NamedTemporaryFile() as csv: | ||
csv = self._write_test_csv(csv, lines) | ||
with self.assertNumQueries(5 + num_lines): | ||
with self.assertNumQueries(4 + num_lines): | ||
call_command(self.command, f'--csv_path={csv.name}') | ||
|
||
def test_dupe_user_csv(self): | ||
|
@@ -130,3 +130,32 @@ def test_dupe_user_csv(self): | |
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) | ||
|
||
def test_existing_course_staff_csv(self): | ||
""" Assert that the course staff role are correctly created given already existing course staff roles in csv """ | ||
course_existing = 'course-v1:edx+test+f24' | ||
CourseStaffRoleFactory.create( | ||
user=self.user, | ||
course_id=course_existing, | ||
role=self.course_role, | ||
) | ||
lines = [f'{self.user.username},{self.user.email},{self.course_role},{course_existing}\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(self.user.username, self.user.email, self.course_role, course_existing) | ||
|
||
def test_dupe_course_staff_csv(self): | ||
""" Assert that the course staff role are correctly created given dupe course staff roles in csv """ | ||
course_existing = 'course-v1:edx+test+f24' | ||
CourseStaffRoleFactory.create( | ||
user=self.user, | ||
course_id=course_existing, | ||
role=self.course_role, | ||
) | ||
lines = [f'{self.user.username},{self.user.email},{self.course_role},{course_existing}\n', | ||
f'{self.user.username},{self.user.email},{self.course_role},{course_existing}\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(self.user.username, self.user.email, self.course_role, course_existing) |