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 ac1a57a4..69641922 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 @@ -55,7 +55,7 @@ def test_add_course_staff_with_new_user(self): call_command(self.command, f'--csv_path={csv.name}') assert CourseStaffRole.objects.filter(course_id='course-v1:edx+test+f20').count() == 1 - def test_add_course_staff_with_batch_size(self): + def test_add_course_staff_with_not_default_batch_size(self): lines = ['pam,pam@pond.com,staff,course-v1:edx+test+f20\n', 'sam,sam@pond.com,staff,course-v1:edx+test+f20\n'] with NamedTemporaryFile() as csv: @@ -63,8 +63,7 @@ def test_add_course_staff_with_batch_size(self): call_command(self.command, f'--csv_path={csv.name}', '--batch_size=1') assert CourseStaffRole.objects.filter(course_id='course-v1:edx+test+f20').count() == 2 - def test_add_course_staff_with_batch_delay(self): - # todo: test batch delay + def test_add_course_staff_with_not_default_batch_delay(self): lines = ['pam,pam@pond.com,staff,course-v1:edx+test+f20\n', 'sam,sam@pond.com,staff,course-v1:edx+test+f20\n'] with NamedTemporaryFile() as csv: @@ -73,11 +72,14 @@ def test_add_course_staff_with_batch_delay(self): assert CourseStaffRole.objects.filter(course_id='course-v1:edx+test+f20').count() == 2 def test_num_queries_correct(self): - # todo: test num queries correct - lines = ['pam,pam@pond.com,staff,course-v1:edx+test+f20\n', - 'sam,sam@pond.com,staff,course-v1:edx+test+f20\n'] + """ + Expect the number of queries to be 3 + 3 * number of lines + - 2 for savepoint/release savepoint, 1 for count check below, 1 to get existing usernames + - 3 for each user, assuming not existing (1 to create user, 1 to get user, 1 to add course role) + """ + num_lines = 20 + 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(2): - call_command(self.command, f'--csv_path={csv.name}', '--batch_size=1', '--batch_delay=2') - assert CourseStaffRole.objects.filter(course_id='course-v1:edx+test+f20').count() == 2 + with self.assertNumQueries(3 + 3 * num_lines): + call_command(self.command, f'--csv_path={csv.name}')