test: Use allowlist factory (#27490)

MICROBA-1021
This commit is contained in:
Christie Rice
2021-05-03 12:53:36 -04:00
committed by GitHub
parent 12e9763446
commit 82bf0411ca
9 changed files with 62 additions and 48 deletions

View File

@@ -7,7 +7,7 @@ from django.core.management import call_command
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from lms.djangoapps.certificates.models import CertificateWhitelist
from lms.djangoapps.certificates.tests.factories import CertificateWhitelistFactory
from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
@@ -71,7 +71,7 @@ class CertAllowlistManagementCommandTests(ModuleStoreTestCase):
"""
Verify an allowlist entry can be removed using the management command.
"""
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
call_command(
"cert_whitelist",

View File

@@ -34,7 +34,23 @@ class GeneratedCertificateFactory(DjangoModelFactory):
class CertificateWhitelistFactory(DjangoModelFactory):
"""
CertificateWhitelist factory
CertificateWhitelist factory.
This will be removed once the underlying model is renamed. It is suggested that CertificateAllowlistFactory be used
instead of this factory.
"""
class Meta:
model = CertificateWhitelist
course_id = None
whitelist = True
notes = 'Test Notes'
class CertificateAllowlistFactory(DjangoModelFactory):
"""
Certificate allowlist factory
"""
class Meta:

View File

@@ -16,7 +16,6 @@ from django.test import RequestFactory, TestCase
from django.test.utils import override_settings
from django.urls import reverse
from django.utils import timezone
from edx_toggles.toggles.testutils import override_waffle_flag
from freezegun import freeze_time
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import CourseLocator
@@ -66,7 +65,7 @@ from lms.djangoapps.certificates.models import (
)
from lms.djangoapps.certificates.queue import XQueueAddToQueueError, XQueueCertInterface
from lms.djangoapps.certificates.tests.factories import (
CertificateWhitelistFactory,
CertificateAllowlistFactory,
GeneratedCertificateFactory,
CertificateInvalidationFactory
)
@@ -848,11 +847,11 @@ class AllowlistTests(ModuleStoreTestCase):
)
# Add user to the allowlist
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
# Add user to the allowlist, but set whitelist to false
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user2, whitelist=False)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user2, whitelist=False)
# Add user to the allowlist in the other course
CertificateWhitelistFactory.create(course_id=self.second_course_run_key, user=self.user4)
CertificateAllowlistFactory.create(course_id=self.second_course_run_key, user=self.user4)
def test_get_users_allowlist(self):
"""
@@ -908,7 +907,7 @@ class CertificateAllowlistTests(ModuleStoreTestCase):
"""
Test for removing an allowlist entry for a user in a given course-run.
"""
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
result = remove_allowlist_entry(self.user, self.course_run_key)
assert result
@@ -921,7 +920,7 @@ class CertificateAllowlistTests(ModuleStoreTestCase):
"""
Test for removing an allowlist entry. Verify that we also invalidate the certificate for the student.
"""
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
GeneratedCertificateFactory.create(
user=self.user,
course_id=self.course_run_key,
@@ -950,7 +949,7 @@ class CertificateAllowlistTests(ModuleStoreTestCase):
"""
Test to verify that we can retrieve an allowlist entry for a learner.
"""
allowlist_entry = CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
allowlist_entry = CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
retrieved_entry = get_allowlist_entry(self.user, self.course_run_key)
@@ -979,7 +978,7 @@ class CertificateAllowlistTests(ModuleStoreTestCase):
"""
Test to verify that we return True when an allowlist entry exists.
"""
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
result = is_on_allowlist(self.user, self.course_run_key)
assert result
@@ -995,7 +994,7 @@ class CertificateAllowlistTests(ModuleStoreTestCase):
"""
Test to verify that we will return False when the allowlist entry if it is disabled.
"""
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user, whitelist=False)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user, whitelist=False)
result = is_on_allowlist(self.user, self.course_run_key)
assert not result
@@ -1039,7 +1038,7 @@ class CertificateAllowlistTests(ModuleStoreTestCase):
Test to verify that a learner will be rejected from the allowlist if they currently already appear on the
allowlist.
"""
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
assert not can_be_added_to_allowlist(self.user, self.course_run_key)

View File

@@ -25,8 +25,8 @@ from lms.djangoapps.certificates.generation_handler import (
)
from lms.djangoapps.certificates.models import CertificateStatuses, GeneratedCertificate
from lms.djangoapps.certificates.tests.factories import (
CertificateAllowlistFactory,
CertificateInvalidationFactory,
CertificateWhitelistFactory,
GeneratedCertificateFactory
)
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@@ -64,7 +64,7 @@ class AllowlistTests(ModuleStoreTestCase):
)
# Whitelist user
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=self.user)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=self.user)
def test_is_using_allowlist_true(self):
"""
@@ -89,7 +89,7 @@ class AllowlistTests(ModuleStoreTestCase):
is_active=True,
mode="verified",
)
CertificateWhitelistFactory.create(course_id=self.course_run_key, user=u, whitelist=False)
CertificateAllowlistFactory.create(course_id=self.course_run_key, user=u, whitelist=False)
assert not is_using_certificate_allowlist_and_is_on_allowlist(u, self.course_run_key)
@ddt.data(
@@ -171,7 +171,7 @@ class AllowlistTests(ModuleStoreTestCase):
u = UserFactory()
cr = CourseFactory()
key = cr.id # pylint: disable=no-member
CertificateWhitelistFactory.create(course_id=key, user=u)
CertificateAllowlistFactory.create(course_id=key, user=u)
assert not _can_generate_allowlist_certificate(u, key)
assert _set_allowlist_cert_status(u, key) is None
@@ -188,7 +188,7 @@ class AllowlistTests(ModuleStoreTestCase):
is_active=True,
mode="audit",
)
CertificateWhitelistFactory.create(course_id=key, user=u)
CertificateAllowlistFactory.create(course_id=key, user=u)
assert not _can_generate_allowlist_certificate(u, key)
assert _set_allowlist_cert_status(u, key) is None
@@ -228,7 +228,7 @@ class AllowlistTests(ModuleStoreTestCase):
mode=GeneratedCertificate.MODES.verified,
status=CertificateStatuses.downloadable
)
CertificateWhitelistFactory.create(course_id=key, user=u)
CertificateAllowlistFactory.create(course_id=key, user=u)
CertificateInvalidationFactory.create(
generated_certificate=cert,
invalidated_by=self.user,

View File

@@ -31,7 +31,7 @@ from lms.djangoapps.certificates.models import (
GeneratedCertificate
)
from lms.djangoapps.certificates.queue import LOGGER, XQueueCertInterface
from lms.djangoapps.certificates.tests.factories import CertificateWhitelistFactory, GeneratedCertificateFactory
from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory, GeneratedCertificateFactory
from lms.djangoapps.grades.tests.utils import mock_passing_grade
from lms.djangoapps.verify_student.tests.factories import SoftwareSecurePhotoVerificationFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
@@ -125,7 +125,7 @@ class XQueueCertInterfaceAddCertificateTest(ModuleStoreTestCase):
mode='audit'
)
# Whitelist student
CertificateWhitelistFactory(course_id=self.course.id, user=self.user_2)
CertificateAllowlistFactory(course_id=self.course.id, user=self.user_2)
features = settings.FEATURES
features['DISABLE_AUDIT_CERTIFICATES'] = disable_audit_cert

View File

@@ -2,12 +2,11 @@
Unit Tests for the Certificate service
"""
from edx_toggles.toggles.testutils import override_waffle_flag
from common.djangoapps.student.tests.factories import UserFactory
from lms.djangoapps.certificates.models import CertificateStatuses, GeneratedCertificate
from lms.djangoapps.certificates.services import CertificateService
from lms.djangoapps.certificates.tests.factories import CertificateWhitelistFactory, GeneratedCertificateFactory
from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory, GeneratedCertificateFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
@@ -78,7 +77,7 @@ class CertificateServiceTests(ModuleStoreTestCase):
course_id=course_key,
grade=1.0
)
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=u,
course_id=course_key
)

View File

@@ -20,7 +20,7 @@ from lms.djangoapps.certificates.models import (
)
from lms.djangoapps.certificates.signals import _fire_ungenerated_certificate_task
from lms.djangoapps.certificates.tasks import CERTIFICATE_DELAY_SECONDS
from lms.djangoapps.certificates.tests.factories import CertificateWhitelistFactory, GeneratedCertificateFactory
from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory, GeneratedCertificateFactory
from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory
from lms.djangoapps.grades.tests.utils import mock_passing_grade
from lms.djangoapps.verify_student.models import IDVerificationAttempt, SoftwareSecurePhotoVerification
@@ -88,7 +88,7 @@ class AllowlistGeneratedCertificatesTest(ModuleStoreTestCase):
return_value=None
) as mock_generate_allowlist_task:
with override_waffle_switch(AUTO_CERTIFICATE_GENERATION_SWITCH, active=True):
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=self.user,
course_id=self.ip_course.id,
whitelist=True
@@ -109,7 +109,7 @@ class AllowlistGeneratedCertificatesTest(ModuleStoreTestCase):
return_value=None
) as mock_generate_allowlist_task:
with override_waffle_switch(AUTO_CERTIFICATE_GENERATION_SWITCH, active=False):
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=self.user,
course_id=self.ip_course.id,
whitelist=True
@@ -228,7 +228,7 @@ class PassingGradeCertsTest(ModuleStoreTestCase):
u = UserFactory.create()
c = CourseFactory()
course_key = c.id # pylint: disable=no-member
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=u,
course_id=course_key
)
@@ -365,7 +365,7 @@ class FailingGradeCertsTest(ModuleStoreTestCase):
u = UserFactory.create()
c = CourseFactory()
course_key = c.id # pylint: disable=no-member
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=u,
course_id=course_key
)
@@ -478,7 +478,7 @@ class LearnerTrackChangeCertsTest(ModuleStoreTestCase):
is_active=True,
mode='verified'
)
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=u,
course_id=course_key
)
@@ -550,7 +550,7 @@ class EnrollmentModeChangeCertsTest(ModuleStoreTestCase):
is_active=True,
mode='verified',
)
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=self.user,
course_id=self.verified_course_key
)
@@ -563,7 +563,7 @@ class EnrollmentModeChangeCertsTest(ModuleStoreTestCase):
is_active=True,
mode='audit',
)
CertificateWhitelistFactory(
CertificateAllowlistFactory(
user=self.user,
course_id=self.audit_course_key
)

View File

@@ -32,8 +32,8 @@ from lms.djangoapps.certificates.models import (
GeneratedCertificate
)
from lms.djangoapps.certificates.tests.factories import (
CertificateAllowlistFactory,
CertificateInvalidationFactory,
CertificateWhitelistFactory,
GeneratedCertificateFactory
)
from lms.djangoapps.grades.tests.utils import mock_passing_grade
@@ -495,7 +495,7 @@ class CertificateExceptionViewInstructorApiTest(SharedModuleStoreTestCase):
CourseEnrollment.enroll(self.user2, self.course.id)
self.url = reverse('certificate_exception_view', kwargs={'course_id': str(self.course.id)})
certificate_white_list_item = CertificateWhitelistFactory.create(
certificate_white_list_item = CertificateAllowlistFactory.create(
user=self.user2,
course_id=self.course.id,
)
@@ -797,7 +797,7 @@ class GenerateCertificatesInstructorApiTest(SharedModuleStoreTestCase):
self.instructor = InstructorFactory(course_key=self.course.id)
self.user = UserFactory()
CourseEnrollment.enroll(self.user, self.course.id)
certificate_exception = CertificateWhitelistFactory.create(
certificate_exception = CertificateAllowlistFactory.create(
user=self.user,
course_id=self.course.id,
)
@@ -1321,7 +1321,7 @@ class CertificateInvalidationViewTests(SharedModuleStoreTestCase):
invalidation lists.
"""
# add test learner to the allowlist
CertificateWhitelistFactory.create(user=self.enrolled_user_1, course_id=self.course.id)
CertificateAllowlistFactory.create(user=self.enrolled_user_1, course_id=self.course.id)
# now try and add them to the invalidation list, expect an error
response = self.client.post(

View File

@@ -32,7 +32,7 @@ from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentA
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from lms.djangoapps.certificates.generation_handler import CERTIFICATES_USE_UPDATED
from lms.djangoapps.certificates.models import CertificateStatuses, GeneratedCertificate
from lms.djangoapps.certificates.tests.factories import CertificateWhitelistFactory, GeneratedCertificateFactory
from lms.djangoapps.certificates.tests.factories import CertificateAllowlistFactory, GeneratedCertificateFactory
from lms.djangoapps.courseware.models import StudentModule
from lms.djangoapps.grades.course_data import CourseData
from lms.djangoapps.grades.models import PersistentCourseGrade, PersistentSubsectionGradeOverride
@@ -1923,7 +1923,7 @@ class TestGradeReportEnrollmentAndCertificateInfo(TestReportMixin, InstructorTas
if has_passed:
self.submit_student_answer('u1', 'test_problem', ['choice_1'])
CertificateWhitelistFactory.create(user=user, course_id=self.course.id, whitelist=whitelisted)
CertificateAllowlistFactory.create(user=user, course_id=self.course.id, whitelist=whitelisted)
if user_enroll_mode in CourseMode.VERIFIED_MODES:
SoftwareSecurePhotoVerificationFactory.create(user=user, status=verification_status)
@@ -2010,7 +2010,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
# Allowlist 5 students
for student in students[2:7]:
CertificateWhitelistFactory.create(user=student, course_id=self.course.id, whitelist=True)
CertificateAllowlistFactory.create(user=student, course_id=self.course.id, whitelist=True)
task_input = {'student_set': None}
expected_results = {
@@ -2040,7 +2040,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
# Allowlist 3 students
for student in students[:3]:
CertificateWhitelistFactory.create(
CertificateAllowlistFactory.create(
user=student, course_id=self.course.id, whitelist=True
)
@@ -2090,7 +2090,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
# Allowlist 4 students
for student in students[:4]:
CertificateWhitelistFactory.create(
CertificateAllowlistFactory.create(
user=student, course_id=self.course.id, whitelist=True
)
@@ -2116,7 +2116,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
Tests generating a certificate for a specific student.
"""
student = self.create_student(username="Hamnet", email="ham@ardenforest.co.uk")
CertificateWhitelistFactory.create(user=student, course_id=self.course.id, whitelist=True)
CertificateAllowlistFactory.create(user=student, course_id=self.course.id, whitelist=True)
task_input = {
'student_set': 'specific_student',
'specific_student_id': student.id
@@ -2188,7 +2188,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
# Allowlist 7 students
for student in students[:7]:
CertificateWhitelistFactory.create(user=student, course_id=self.course.id, whitelist=True)
CertificateAllowlistFactory.create(user=student, course_id=self.course.id, whitelist=True)
# Certificates should be regenerated for students having generated certificates with status
# 'downloadable' or 'error' which are total of 5 students in this test case
@@ -2261,7 +2261,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
# Allowlist 7 students
for student in students[:7]:
CertificateWhitelistFactory.create(user=student, course_id=self.course.id, whitelist=True)
CertificateAllowlistFactory.create(user=student, course_id=self.course.id, whitelist=True)
# Regenerated certificates for students having generated certificates with status
# 'deleted' or 'generating'
@@ -2332,7 +2332,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
# Allowlist all students
for student in students[:]:
CertificateWhitelistFactory.create(user=student, course_id=self.course.id, whitelist=True)
CertificateAllowlistFactory.create(user=student, course_id=self.course.id, whitelist=True)
# Regenerated certificates for students having generated certificates with status
# 'downloadable', 'error' or 'generating'
@@ -2403,7 +2403,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
# Allowlist 7 students
for student in students[:7]:
CertificateWhitelistFactory.create(user=student, course_id=self.course.id, whitelist=True)
CertificateAllowlistFactory.create(user=student, course_id=self.course.id, whitelist=True)
# Certificates should be regenerated for students having generated certificates with status
# 'downloadable' or 'error' which are total of 5 students in this test case
@@ -2436,7 +2436,7 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase):
)
# Allowlist a student
CertificateWhitelistFactory.create(user=s1, course_id=self.course.id)
CertificateAllowlistFactory.create(user=s1, course_id=self.course.id)
statuses = [CertificateStatuses.downloadable]
_invalidate_generated_certificates(self.course.id, students, statuses)