Skip to content

Commit 45f94d4

Browse files
authored
Merge pull request #37602 from mitodl/arslan/backport-PR-37569
fix: validation API for certificates (backport - Ulmo)
2 parents 3cf5e34 + b48c4af commit 45f94d4

File tree

2 files changed

+58
-38
lines changed

2 files changed

+58
-38
lines changed

cms/djangoapps/contentstore/api/tests/test_validation.py

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22
Tests for the course import API views
33
"""
44

5-
5+
import factory
66
from datetime import datetime
7+
from django.conf import settings
78

9+
import ddt
810
from django.test.utils import override_settings
911
from django.urls import reverse
1012
from rest_framework import status
1113
from rest_framework.test import APITestCase
1214
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
1315
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
1416

17+
from common.djangoapps.course_modes.models import CourseMode
18+
from common.djangoapps.course_modes.tests.factories import CourseModeFactory
1519
from common.djangoapps.student.tests.factories import StaffFactory
1620
from common.djangoapps.student.tests.factories import UserFactory
1721

1822

23+
@ddt.ddt
1924
@override_settings(PROCTORING_BACKENDS={'DEFAULT': 'proctortrack', 'proctortrack': {}})
2025
class CourseValidationViewTest(SharedModuleStoreTestCase, APITestCase):
2126
"""
@@ -82,39 +87,54 @@ def test_student_fails(self):
8287
resp = self.client.get(self.get_url(self.course_key))
8388
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
8489

85-
def test_staff_succeeds(self):
86-
self.client.login(username=self.staff.username, password=self.password)
87-
resp = self.client.get(self.get_url(self.course_key), {'all': 'true'})
88-
self.assertEqual(resp.status_code, status.HTTP_200_OK)
89-
expected_data = {
90-
'assignments': {
91-
'total_number': 1,
92-
'total_visible': 1,
93-
'assignments_with_dates_before_start': [],
94-
'assignments_with_dates_after_end': [],
95-
'assignments_with_ora_dates_after_end': [],
96-
'assignments_with_ora_dates_before_start': [],
97-
},
98-
'dates': {
99-
'has_start_date': True,
100-
'has_end_date': False,
101-
},
102-
'updates': {
103-
'has_update': True,
104-
},
105-
'certificates': {
106-
'is_enabled': False,
107-
'is_activated': False,
108-
'has_certificate': False,
109-
},
110-
'grades': {
111-
'has_grading_policy': False,
112-
'sum_of_weights': 1.0,
113-
},
114-
'proctoring': {
115-
'needs_proctoring_escalation_email': True,
116-
'has_proctoring_escalation_email': True,
117-
},
118-
'is_self_paced': True,
119-
}
120-
self.assertDictEqual(resp.data, expected_data)
90+
@ddt.data(
91+
(False, False),
92+
(True, False),
93+
(False, True),
94+
(True, True),
95+
)
96+
@ddt.unpack
97+
def test_staff_succeeds(self, certs_html_view, with_modes):
98+
features = dict(settings.FEATURES, CERTIFICATES_HTML_VIEW=certs_html_view)
99+
with override_settings(FEATURES=features):
100+
if with_modes:
101+
CourseModeFactory.create_batch(
102+
2,
103+
course_id=self.course.id,
104+
mode_slug=factory.Iterator([CourseMode.AUDIT, CourseMode.VERIFIED]),
105+
)
106+
self.client.login(username=self.staff.username, password=self.password)
107+
resp = self.client.get(self.get_url(self.course_key), {'all': 'true'})
108+
self.assertEqual(resp.status_code, status.HTTP_200_OK)
109+
expected_data = {
110+
'assignments': {
111+
'total_number': 1,
112+
'total_visible': 1,
113+
'assignments_with_dates_before_start': [],
114+
'assignments_with_dates_after_end': [],
115+
'assignments_with_ora_dates_after_end': [],
116+
'assignments_with_ora_dates_before_start': [],
117+
},
118+
'dates': {
119+
'has_start_date': True,
120+
'has_end_date': False,
121+
},
122+
'updates': {
123+
'has_update': True,
124+
},
125+
'certificates': {
126+
'is_enabled': with_modes,
127+
'is_activated': False,
128+
'has_certificate': False,
129+
},
130+
'grades': {
131+
'has_grading_policy': False,
132+
'sum_of_weights': 1.0,
133+
},
134+
'proctoring': {
135+
'needs_proctoring_escalation_email': True,
136+
'has_proctoring_escalation_email': True,
137+
},
138+
'is_self_paced': True,
139+
}
140+
self.assertDictEqual(resp.data, expected_data)

cms/djangoapps/contentstore/views/certificate_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def is_activated(course):
121121
along with the certificates.
122122
"""
123123
is_active = False
124-
certificates = None
124+
certificates = []
125125
if settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False):
126126
certificates = CertificateManager.get_certificates(course)
127127
# we are assuming only one certificate in certificates collection.

0 commit comments

Comments
 (0)