Skip to content

Commit

Permalink
test: add test for num queries
Browse files Browse the repository at this point in the history
  • Loading branch information
varshamenon4 committed Mar 28, 2024
1 parent 9a8ddf9 commit 7307b91
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ 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,[email protected],staff,course-v1:edx+test+f20\n',
'sam,[email protected],staff,course-v1:edx+test+f20\n']
with NamedTemporaryFile() as csv:
csv = self._write_test_csv(csv, lines)
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,[email protected],staff,course-v1:edx+test+f20\n',
'sam,[email protected],staff,course-v1:edx+test+f20\n']
with NamedTemporaryFile() as csv:
Expand All @@ -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,[email protected],staff,course-v1:edx+test+f20\n',
'sam,[email protected],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}')

0 comments on commit 7307b91

Please sign in to comment.