-
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.
- Loading branch information
1 parent
207b5d1
commit 2862bf2
Showing
9 changed files
with
40 additions
and
70 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 |
---|---|---|
@@ -1,21 +1,13 @@ | ||
""" Tests for bulk_add_course_staff management command """ | ||
from tempfile import NamedTemporaryFile | ||
from testfixtures import LogCapture | ||
from unittest.mock import patch | ||
|
||
import ddt | ||
from django.core.management import call_command | ||
from django.test import TestCase | ||
|
||
from edx_exams.apps.core.models import ( | ||
CourseStaffRole, | ||
User, | ||
) | ||
from edx_exams.apps.core.test_utils.factories import CourseStaffRoleFactory, UserFactory | ||
|
||
# todo: is this the correct logger name? | ||
LOGGER_NAME = 'edx_exams.apps.core.management.commands.bulk_add_course_staff' | ||
|
||
from edx_exams.apps.core.test_utils.factories import UserFactory | ||
|
||
class TestBulkAddCourseStaff(TestCase): | ||
""" Test bulk_add_course_staff management command """ | ||
|
@@ -35,7 +27,7 @@ def setUp(self): | |
self.user.save() | ||
|
||
# create course | ||
self.course_id = "course-v1:edx+test+f19" | ||
self.course_id = 'course-v1:edx+test+f19' | ||
|
||
def tearDown(self): | ||
""" | ||
|
@@ -45,7 +37,7 @@ def tearDown(self): | |
|
||
def _write_test_csv(self, csv, lines): | ||
"""Write a test csv file with the lines provided""" | ||
csv.write(b"username,email,role,course_id\n") | ||
csv.write(b'username,email,role,course_id\n') | ||
for line in lines: | ||
csv.write(line.encode()) | ||
csv.seek(0) | ||
|
@@ -55,42 +47,44 @@ def test_empty_csv(self): | |
lines = [] | ||
with NamedTemporaryFile() as csv: | ||
csv = self._write_test_csv(csv, lines) | ||
with LogCapture(LOGGER_NAME) as log: | ||
call_command(self.command, f"--csv_path={csv.name}") | ||
# log.check_present( | ||
# (LOGGER_NAME, 'LOG', self.success_log_message) | ||
# ) | ||
call_command(self.command, f'--csv_path={csv.name}') | ||
# todo: figure out how to check success but not via logs | ||
# todo: assert number of queries is correct | ||
|
||
def test_add_course_staff_with_existing_user(self): | ||
# todo: create course staff with existing user | ||
lines = ["amy,[email protected],staff,course-v1:edx+test+f19\n"] | ||
lines = ['amy,[email protected],staff,course-v1:edx+test+f19\n'] | ||
with NamedTemporaryFile() as csv: | ||
csv = self._write_test_csv(csv, lines) | ||
with LogCapture(LOGGER_NAME) as log: | ||
call_command(self.command, f"--csv_path={csv.name}") | ||
# log.check_present( | ||
# (LOGGER_NAME, 'LOG', self.success_log_message) | ||
# ) | ||
assert CourseStaffRole.objects.filter(user=self.user.id).exists() | ||
# todo: figure out how to check success but not via logs | ||
# todo: assert number of queries is correct | ||
call_command(self.command, f'--csv_path={csv.name}') | ||
assert CourseStaffRole.objects.filter(user=self.user.id).exists() | ||
|
||
def test_add_course_staff_with_new_user(self): | ||
# todo: create course staff with new user | ||
lines = ["pam,[email protected],staff,course-v1:edx+test+f20\n"] | ||
lines = ['pam,[email protected],staff,course-v1:edx+test+f20\n'] | ||
with NamedTemporaryFile() as csv: | ||
csv = self._write_test_csv(csv, lines) | ||
with LogCapture(LOGGER_NAME) as log: | ||
call_command(self.command, f"--csv_path={csv.name}") | ||
# log.check_present( | ||
# (LOGGER_NAME, 'LOG', self.success_log_message) | ||
# ) | ||
assert CourseStaffRole.objects.filter(course_id="course-v1:edx+test+f20").exists() | ||
# todo: figure out how to check success but not via logs | ||
# todo: assert number of queries is correct | ||
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): | ||
# todo: test with setting batch size | ||
# set batch size to 1, add two entries | ||
# assert that bulk create is called twice | ||
return | ||
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) | ||
# todo: figure out how to check success but not via logs | ||
# todo: assert number of queries is correct | ||
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 with setting batch delay | ||
# todo: see bulk unenroll for example of batch unenroll | ||
return |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
|
||
|
||
|
||
# A central location for most common version constraints | ||
# (across edx repos) for pip-installation. | ||
# | ||
|
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
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 |
---|---|---|
|
@@ -14,5 +14,4 @@ mock | |
pytest-cov | ||
pytest-django | ||
responses | ||
testfixtures | ||
tox |
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