Skip to content
Snippets Groups Projects
Unverified Commit 09d58a4e authored by Christie Rice's avatar Christie Rice Committed by GitHub
Browse files

test: Update course certificate tests before enabling v2 of course certificates globally (#27954)

MICROBA-1082
parent 51f1c4cc
No related branches found
Tags release-2021-06-15-13.28
No related merge requests found
......@@ -133,16 +133,24 @@ class CertificateDownloadableStatusTests(WebCertificateTestMixin, ModuleStoreTes
certificate_available_date=datetime.now(pytz.UTC) - timedelta(days=2)
)
GeneratedCertificateFactory.create(
user=self.student,
course_id=self.course.id,
status=CertificateStatuses.downloadable,
mode='verified'
)
self.request_factory = RequestFactory()
def test_cert_status_with_generating(self):
cert_user = UserFactory()
GeneratedCertificateFactory.create(
user=self.student,
user=cert_user,
course_id=self.course.id,
status=CertificateStatuses.generating,
mode='verified'
)
assert certificate_downloadable_status(self.student, self.course.id) ==\
assert certificate_downloadable_status(cert_user, self.course.id) ==\
{'is_downloadable': False,
'is_generating': True,
'is_unverified': False,
......@@ -150,14 +158,15 @@ class CertificateDownloadableStatusTests(WebCertificateTestMixin, ModuleStoreTes
'uuid': None}
def test_cert_status_with_error(self):
cert_user = UserFactory()
GeneratedCertificateFactory.create(
user=self.student,
user=cert_user,
course_id=self.course.id,
status=CertificateStatuses.error,
mode='verified'
)
assert certificate_downloadable_status(self.student, self.course.id) ==\
assert certificate_downloadable_status(cert_user, self.course.id) ==\
{'is_downloadable': False,
'is_generating': True,
'is_unverified': False,
......@@ -177,15 +186,16 @@ class CertificateDownloadableStatusTests(WebCertificateTestMixin, ModuleStoreTes
Verifies certificate_downloadable_status returns the
correct response for PDF certificates.
"""
cert_user = UserFactory()
cert = GeneratedCertificateFactory.create(
user=self.student,
user=cert_user,
course_id=self.course.id,
status=CertificateStatuses.downloadable,
mode='verified',
download_url='www.google.com',
)
assert certificate_downloadable_status(self.student, self.course.id) ==\
assert certificate_downloadable_status(cert_user, self.course.id) ==\
{'is_downloadable': True,
'is_generating': False,
'is_unverified': False,
......
......@@ -319,10 +319,11 @@ class CertificateTests(ModuleStoreTestCase):
"""
Test handling of an invalid user/course run combo
"""
assert not _can_generate_v2_certificate(self.user, self.course_run_key)
assert not can_generate_certificate_task(self.user, self.course_run_key)
assert not generate_certificate_task(self.user, self.course_run_key)
assert not generate_regular_certificate_task(self.user, self.course_run_key)
other_user = UserFactory()
assert not _can_generate_v2_certificate(other_user, self.course_run_key)
assert not can_generate_certificate_task(other_user, self.course_run_key)
assert not generate_certificate_task(other_user, self.course_run_key)
assert not generate_regular_certificate_task(other_user, self.course_run_key)
def test_is_using_updated_true(self):
"""
......
......@@ -4,6 +4,7 @@ Tests for certificate app views used by the support team.
import json
from unittest import mock
from unittest.mock import patch
from uuid import uuid4
......@@ -24,6 +25,7 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import Cou
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
CAN_GENERATE_METHOD = 'lms.djangoapps.certificates.generation_handler._can_generate_v2_certificate'
FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy()
FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True
......@@ -48,7 +50,7 @@ class CertificateSupportTestCase(ModuleStoreTestCase):
CERT_GRADE = 0.89
CERT_STATUS = CertificateStatuses.downloadable
CERT_MODE = "verified"
CERT_DOWNLOAD_URL = "http://www.example.com/cert.pdf"
CERT_DOWNLOAD_URL = "https://www.example.com/cert.pdf"
def setUp(self):
"""
......@@ -349,6 +351,7 @@ class CertificateRegenerateTests(CertificateSupportTestCase):
)
assert response.status_code == 400
@mock.patch(CAN_GENERATE_METHOD, mock.Mock(return_value=True))
def test_regenerate_user_has_no_certificate(self):
# Delete the user's certificate
GeneratedCertificate.eligible_certificates.all().delete()
......@@ -364,12 +367,13 @@ class CertificateRegenerateTests(CertificateSupportTestCase):
num_certs = GeneratedCertificate.eligible_certificates.filter(user=self.student).count()
assert num_certs == 1
@mock.patch(CAN_GENERATE_METHOD, mock.Mock(return_value=True))
def test_regenerate_cert_with_invalidated_record(self):
""" If the certificate is marked as invalid, regenerate the certificate. """
# mark certificate as invalid
self._invalidate_certificate(self.cert)
self.assertInvalidatedCertExists()
self.assertCertInvalidationExists()
# after invalidation certificate status become un-available.
self.assertGeneratedCertExists(
user=self.student, status=CertificateStatuses.unavailable
......@@ -381,7 +385,7 @@ class CertificateRegenerateTests(CertificateSupportTestCase):
username=self.STUDENT_USERNAME
)
assert response.status_code == 200
self.assertInvalidatedCertExists()
self.assertCertInvalidationExists()
# Check that the user's certificate was updated
# Since the student hasn't actually passed the course,
......@@ -414,7 +418,7 @@ class CertificateRegenerateTests(CertificateSupportTestCase):
certificate.invalidate()
assert not certificate.is_valid()
def assertInvalidatedCertExists(self):
def assertCertInvalidationExists(self):
""" Dry method to check certificate invalidated entry exists. """
assert CertificateInvalidation.objects.filter(generated_certificate__user=self.student, active=True).exists()
......@@ -514,6 +518,7 @@ class CertificateGenerateTests(CertificateSupportTestCase):
)
assert response.status_code == 400
@mock.patch(CAN_GENERATE_METHOD, mock.Mock(return_value=True))
def test_generate_user_has_no_certificate(self):
# Delete the user's certificate
GeneratedCertificate.eligible_certificates.all().delete()
......
......@@ -99,7 +99,7 @@ class CommonCertificatesTestCase(ModuleStoreTestCase):
user=self.user,
course_id=self.course_id,
download_uuid=uuid4().hex,
download_url="http://www.example.com/certificates/download",
download_url="https://www.example.com/certificates/download",
grade="0.95",
key='the_key',
distinction=True,
......@@ -458,7 +458,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase)
platform_name='My Platform Site',
SITE_NAME='test_site.localhost',
urls=dict(
ABOUT='http://www.test-site.org/about-us',
ABOUT='https://www.test-site.org/about-us',
),
),
)
......@@ -522,7 +522,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase)
# Test item from badge info
self.assertContains(response, "Add to Mozilla Backpack")
# Test item from site configuration
self.assertContains(response, "http://www.test-site.org/about-us")
self.assertContains(response, "https://www.test-site.org/about-us")
# Test course overrides
self.assertContains(response, "/static/certificates/images/course_override_logo.png")
......@@ -959,7 +959,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase)
self.assertContains(response, "Invalid Certificate")
@override_settings(FEATURES=FEATURES_WITH_CERTS_DISABLED)
def test_request_certificate_without_passing(self):
def test_request_certificate_without_html_certs(self):
self.cert.status = CertificateStatuses.unavailable
self.cert.save()
request_certificate_url = reverse('request_certificate')
......@@ -1590,10 +1590,10 @@ class CertificateEventTests(CommonCertificatesTestCase, EventTrackingTestCase):
assertion = BadgeAssertionFactory.create(
user=self.user, badge_class=badge_class,
backend='DummyBackend',
image_url='http://www.example.com/image.png',
assertion_url='http://www.example.com/assertion.json',
image_url='https://www.example.com/image.png',
assertion_url='https://www.example.com/assertion.json',
data={
'issuer': 'http://www.example.com/issuer.json',
'issuer': 'https://www.example.com/issuer.json',
}
)
response = self.client.get(test_url)
......@@ -1615,10 +1615,10 @@ class CertificateEventTests(CommonCertificatesTestCase, EventTrackingTestCase):
'badge_name': 'refundable course',
'issuing_component': '',
'badge_slug': 'testorgrun1refundable_course_honor_432f164',
'assertion_json_url': 'http://www.example.com/assertion.json',
'assertion_image_url': 'http://www.example.com/image.png',
'assertion_json_url': 'https://www.example.com/assertion.json',
'assertion_image_url': 'https://www.example.com/image.png',
'user_id': self.user.id,
'issuer': 'http://www.example.com/issuer.json',
'issuer': 'https://www.example.com/issuer.json',
'enrollment_mode': 'honor',
},
},
......
......@@ -136,8 +136,6 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
with mock.patch('lms.djangoapps.courseware.access_utils.check_public_access', check_public_access):
if not logged_in:
self.client.logout()
if enrollment_mode:
CourseEnrollment.enroll(self.user, self.course.id, enrollment_mode)
if enrollment_mode == 'verified':
cert = GeneratedCertificateFactory.create(
user=self.user,
......@@ -145,6 +143,8 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
status='downloadable',
mode='verified',
)
if enrollment_mode:
CourseEnrollment.enroll(self.user, self.course.id, enrollment_mode)
response = self.client.get(self.url)
assert response.status_code == 200
......@@ -311,15 +311,15 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
(True, True),
)
@ddt.unpack
def test_special_exams_enabled_for_course(self, is_globaly_enabled, is_waffle_enabled):
def test_special_exams_enabled_for_course(self, is_globally_enabled, is_waffle_enabled):
""" Ensure that special exams flag present in courseware meta data with expected value """
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': is_globaly_enabled}):
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': is_globally_enabled}):
with override_waffle_flag(COURSEWARE_MICROFRONTEND_SPECIAL_EXAMS, active=is_waffle_enabled):
response = self.client.get(self.url)
assert response.status_code == 200
courseware_data = response.json()
assert 'is_mfe_special_exams_enabled' in courseware_data
assert courseware_data['is_mfe_special_exams_enabled'] == (is_globaly_enabled and is_waffle_enabled)
assert courseware_data['is_mfe_special_exams_enabled'] == (is_globally_enabled and is_waffle_enabled)
@ddt.data(
(None, False, False, False),
......@@ -358,15 +358,15 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
(True, True),
)
@ddt.unpack
def test_proctored_exams_enabled_for_course(self, is_globaly_enabled, is_waffle_enabled):
def test_proctored_exams_enabled_for_course(self, is_globally_enabled, is_waffle_enabled):
""" Ensure that proctored exams flag present in courseware meta data with expected value """
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': is_globaly_enabled}):
with mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': is_globally_enabled}):
with override_waffle_flag(COURSEWARE_MICROFRONTEND_PROCTORED_EXAMS, active=is_waffle_enabled):
response = self.client.get(self.url)
assert response.status_code == 200
courseware_data = response.json()
assert 'is_mfe_proctored_exams_enabled' in courseware_data
assert courseware_data['is_mfe_proctored_exams_enabled'] == (is_globaly_enabled and is_waffle_enabled)
assert courseware_data['is_mfe_proctored_exams_enabled'] == (is_globally_enabled and is_waffle_enabled)
class SequenceApiTestViews(BaseCoursewareTests):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment