Two new certificate statuses are introduced, 'audit_passing' and 'audit_notpassing'. These signal that the GeneratedCertificate is not to be displayed as a cert to the user, and that they either passed or did not. This allows us to retain existing grading logic, as well as maintaining correctness in analytics and reporting. Ineligible certificates are hidden by using the `eligible_certificates` manager on GeneratedCertificate. Some places in the coe (largely reporting, analytics, and management commands) use the default `objects` manager, since they need access to all certificates. ECOM-3040 ECOM-3515
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
"""Tests for the create_fake_certs management command. """
|
|
from django.test import TestCase
|
|
from django.core.management.base import CommandError
|
|
from nose.plugins.attrib import attr
|
|
|
|
from opaque_keys.edx.locator import CourseLocator
|
|
from student.tests.factories import UserFactory
|
|
from certificates.management.commands import create_fake_cert
|
|
from certificates.models import GeneratedCertificate
|
|
|
|
|
|
@attr('shard_1')
|
|
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(CreateFakeCertTest, self).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,
|
|
unicode(self.COURSE_KEY),
|
|
cert_mode='verified',
|
|
grade='0.89'
|
|
)
|
|
cert = GeneratedCertificate.eligible_certificates.get(user=self.user, course_id=self.COURSE_KEY)
|
|
self.assertEqual(cert.status, 'downloadable')
|
|
self.assertEqual(cert.mode, 'verified')
|
|
self.assertEqual(cert.grade, '0.89')
|
|
self.assertEqual(cert.download_uuid, 'test')
|
|
self.assertEqual(cert.download_url, 'http://www.example.com')
|
|
|
|
# Cert already exists; modify it
|
|
self._run_command(
|
|
self.USERNAME,
|
|
unicode(self.COURSE_KEY),
|
|
cert_mode='honor'
|
|
)
|
|
cert = GeneratedCertificate.eligible_certificates.get(user=self.user, course_id=self.COURSE_KEY)
|
|
self.assertEqual(cert.mode, 'honor')
|
|
|
|
def test_too_few_args(self):
|
|
with self.assertRaisesRegexp(CommandError, 'Usage'):
|
|
self._run_command(self.USERNAME)
|
|
|
|
def _run_command(self, *args, **kwargs):
|
|
"""Run the management command to generate a fake cert. """
|
|
command = create_fake_cert.Command()
|
|
return command.handle(*args, **kwargs)
|