MICROBA-1032 Remove command in favor of using the allowlist (#26786)
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
"""Deprecated import support. Auto-generated by import_shims/generate_shims.sh."""
|
||||
# pylint: disable=redefined-builtin,wrong-import-position,wildcard-import,useless-suppression,line-too-long
|
||||
|
||||
from import_shims.warn import warn_deprecated_import
|
||||
|
||||
warn_deprecated_import('certificates.management.commands.create_fake_cert', 'lms.djangoapps.certificates.management.commands.create_fake_cert')
|
||||
|
||||
from lms.djangoapps.certificates.management.commands.create_fake_cert import *
|
||||
@@ -1,8 +0,0 @@
|
||||
"""Deprecated import support. Auto-generated by import_shims/generate_shims.sh."""
|
||||
# pylint: disable=redefined-builtin,wrong-import-position,wildcard-import,useless-suppression,line-too-long
|
||||
|
||||
from import_shims.warn import warn_deprecated_import
|
||||
|
||||
warn_deprecated_import('certificates.tests.test_create_fake_cert', 'lms.djangoapps.certificates.tests.test_create_fake_cert')
|
||||
|
||||
from lms.djangoapps.certificates.tests.test_create_fake_cert import *
|
||||
@@ -1,120 +0,0 @@
|
||||
"""Utility for testing certificate display.
|
||||
|
||||
This command will create a fake certificate for a user
|
||||
in a course. The certificate will display on the student's
|
||||
dashboard, but no PDF will be generated.
|
||||
|
||||
Example usage:
|
||||
|
||||
$ ./manage.py lms create_fake_cert test_user edX/DemoX/Demo_Course --mode honor --grade 0.89
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import logging
|
||||
from textwrap import dedent
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.management.base import BaseCommand
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from lms.djangoapps.certificates.models import CertificateStatuses, GeneratedCertificate
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""Create a fake certificate for a user in a course. """
|
||||
help = dedent(__doc__).strip()
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'username',
|
||||
metavar='USERNAME',
|
||||
help='Username of the user to create the fake cert for'
|
||||
)
|
||||
parser.add_argument(
|
||||
'course_key',
|
||||
metavar='COURSE_KEY',
|
||||
help='Course key of the course to grant the cert for'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-m', '--mode',
|
||||
metavar='CERT_MODE',
|
||||
dest='cert_mode',
|
||||
default='honor',
|
||||
help='The course mode of the certificate (e.g. "honor", "verified", or "professional")'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-s', '--status',
|
||||
metavar='CERT_STATUS',
|
||||
dest='status',
|
||||
default=CertificateStatuses.downloadable,
|
||||
help='The status of the certificate'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-g', '--grade',
|
||||
metavar='CERT_GRADE',
|
||||
dest='grade',
|
||||
default='',
|
||||
help='The grade for the course, as a decimal (e.g. "0.89" for 89 percent)'
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""Create a fake certificate for a user.
|
||||
|
||||
Arguments:
|
||||
username (unicode): Identifier for the certificate's user.
|
||||
course_key (unicode): Identifier for the certificate's course.
|
||||
|
||||
Keyword Arguments:
|
||||
cert_mode (str): The mode of the certificate (e.g "honor")
|
||||
status (str): The status of the certificate (e.g. "downloadable")
|
||||
grade (str): The grade of the certificate (e.g "0.89" for 89%)
|
||||
|
||||
Raises:
|
||||
CommandError
|
||||
|
||||
"""
|
||||
user = User.objects.get(username=options['username'])
|
||||
course_key = CourseKey.from_string(options['course_key'])
|
||||
cert_mode = options.get('cert_mode', 'honor')
|
||||
status = options.get('status', CertificateStatuses.downloadable)
|
||||
grade = options.get('grade', '')
|
||||
|
||||
cert, created = GeneratedCertificate.eligible_certificates.get_or_create(
|
||||
user=user,
|
||||
course_id=course_key
|
||||
)
|
||||
cert.mode = cert_mode
|
||||
cert.status = status
|
||||
cert.grade = grade
|
||||
|
||||
if status == CertificateStatuses.downloadable:
|
||||
cert.download_uuid = 'test'
|
||||
cert.verify_uuid = 'test'
|
||||
cert.download_url = 'http://www.example.com'
|
||||
|
||||
cert.save()
|
||||
|
||||
if created:
|
||||
LOGGER.info(
|
||||
"Created certificate for user %s in course %s "
|
||||
"with mode %s, status %s, "
|
||||
"and grade %s",
|
||||
user.id, str(course_key),
|
||||
cert_mode, status, grade
|
||||
)
|
||||
|
||||
else:
|
||||
LOGGER.info(
|
||||
"Updated certificate for user %s in course %s "
|
||||
"with mode %s, status %s, "
|
||||
"and grade %s",
|
||||
user.id, str(course_key),
|
||||
cert_mode, status, grade
|
||||
)
|
||||
@@ -1,58 +0,0 @@
|
||||
"""Tests for the create_fake_certs management command. """
|
||||
|
||||
|
||||
import six
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
from django.test import TestCase
|
||||
from opaque_keys.edx.locator import CourseLocator
|
||||
from six import text_type
|
||||
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from lms.djangoapps.certificates.models import GeneratedCertificate
|
||||
|
||||
|
||||
class CreateFakeCertTest(TestCase):
|
||||
"""Tests for the create_fake_certs management command. """
|
||||
USERNAME = "test"
|
||||
COURSE_KEY = CourseLocator(org='edX', course='DemoX', run='Demo_Course')
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.user = UserFactory.create(username=self.USERNAME)
|
||||
|
||||
def test_create_fake_cert(self):
|
||||
# No existing cert, so create it
|
||||
self._run_command(
|
||||
self.USERNAME,
|
||||
text_type(self.COURSE_KEY),
|
||||
cert_mode='verified',
|
||||
grade='0.89'
|
||||
)
|
||||
cert = GeneratedCertificate.eligible_certificates.get(user=self.user, course_id=self.COURSE_KEY)
|
||||
assert cert.status == 'downloadable'
|
||||
assert cert.mode == 'verified'
|
||||
assert cert.grade == '0.89'
|
||||
assert cert.download_uuid == 'test'
|
||||
assert cert.download_url == 'http://www.example.com'
|
||||
|
||||
# Cert already exists; modify it
|
||||
self._run_command(
|
||||
self.USERNAME,
|
||||
text_type(self.COURSE_KEY),
|
||||
cert_mode='honor'
|
||||
)
|
||||
cert = GeneratedCertificate.eligible_certificates.get(user=self.user, course_id=self.COURSE_KEY)
|
||||
assert cert.mode == 'honor'
|
||||
|
||||
def test_too_few_args(self):
|
||||
if six.PY2:
|
||||
errstring = 'Error: too few arguments'
|
||||
else:
|
||||
errstring = 'Error: the following arguments are required: COURSE_KEY'
|
||||
with self.assertRaisesRegex(CommandError, errstring):
|
||||
self._run_command(self.USERNAME)
|
||||
|
||||
def _run_command(self, *args, **kwargs):
|
||||
"""Run the management command to generate a fake cert. """
|
||||
return call_command('create_fake_cert', *args, **kwargs)
|
||||
Reference in New Issue
Block a user