From cabfa599cbd9adf8939e99c0929485d69b9efdd6 Mon Sep 17 00:00:00 2001 From: Varsha Menon Date: Thu, 28 Mar 2024 08:40:04 -0400 Subject: [PATCH] test: fix tests --- .../test/test_bulk_add_course_staff.py | 44 +++++-------------- 1 file changed, 10 insertions(+), 34 deletions(-) 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 8e086117..183ef946 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 @@ -36,7 +36,7 @@ def _write_test_csv(self, csv, lines): csv.seek(0) return csv - def _assert_user_and_role(self, username, email, course_id, course_role): + def _assert_user_and_role(self, username, email, course_role, course_id): user = User.objects.filter(username=username, email=email) assert user.exists() assert CourseStaffRole.objects.filter( @@ -57,36 +57,21 @@ def test_add_course_staff_with_existing_user(self): 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, self.course_id) - # assert CourseStaffRole.objects.filter( - # user=self.user.id, - # course_id=self.course_id, - # role=self.course_role, - # ).exists() def test_add_course_staff_with_new_user(self): - username = 'pam' - email = 'pam@pond.com' + username, email = 'pam', 'pam@pond.com' lines = [f'{username},{email},{self.course_role},{self.course_id}\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) - # user = User.objects.filter(username=username, email=email) - # assert user.exists() - # assert CourseStaffRole.objects.filter( - # user=user[0].id, - # course_id=self.course_id, - # role=self.course_role, - # ).exists() def test_add_course_staff_multiple(self): """ Assert that the course staff role is correct given multiple lines """ - username = 'pam' - email = 'pam@pond.com' - username2 = 'cam' - email2 = 'cam@pond.com' + username, email = 'pam', 'pam@pond.com' + username2, email2 = 'cam', 'cam@pond.com' lines = [f'{username},{email},{self.course_role},{self.course_id}\n', f'{username2},{email2},{self.course_role},{self.course_id}\n'] with NamedTemporaryFile() as csv: @@ -94,13 +79,6 @@ def test_add_course_staff_multiple(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(username2, email2, self.course_role, self.course_id) - # user = User.objects.filter(username=username, email=email) - # assert user.exists() - # assert CourseStaffRole.objects.filter( - # user=user[0].id, - # course_id=self.course_id, - # role=self.course_role, - # ).exists() def test_add_course_staff_with_not_default_batch_size(self): """ @@ -114,10 +92,8 @@ def test_add_course_staff_with_not_default_batch_size(self): call_command(self.command, f'--csv_path={csv.name}', '--batch_size=1') def test_add_course_staff_with_not_default_batch_delay(self): - username = 'pam' - email = 'pam@pond.com' - username2 = 'cam' - email2 = 'cam@pond.com' + username, email = 'pam', 'pam@pond.com' + username2, email2 = 'cam', 'cam@pond.com' lines = [f'{username},{email},{self.course_role},{self.course_id}\n', f'{username2},{email2},{self.course_role},{self.course_id}\n'] with NamedTemporaryFile() as csv: @@ -128,10 +104,10 @@ def test_add_course_staff_with_not_default_batch_delay(self): def test_num_queries_correct(self): """ - Assert the number of queries to be 5 + 1 * number of lines - - 2 for savepoint/release savepoint, 1 to get existing usernames, - - 1 to bulk create users, 1 to bulk create course role - - 1 for each user (to get user) + Assert the number of queries to be 5 + 1 * number of lines: + 2 for savepoint/release savepoint, 1 to get existing usernames, + 1 to bulk create users, 1 to bulk create course role + 1 for each user (to get user) """ num_lines = 20 lines = [f'pam{i},pam{i}@pond.com,staff,course-v1:edx+test+f20\n' for i in range(num_lines)]