Merge pull request #37569 from mitodl/arslan/fix-validation-api
fix: validation API for certificates
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
Tests for the course import API views
|
||||
"""
|
||||
|
||||
|
||||
import factory
|
||||
from datetime import datetime
|
||||
from django.conf import settings
|
||||
|
||||
import ddt
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
@@ -12,10 +14,13 @@ from rest_framework.test import APITestCase
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
|
||||
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from common.djangoapps.course_modes.tests.factories import CourseModeFactory
|
||||
from common.djangoapps.student.tests.factories import StaffFactory
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@override_settings(PROCTORING_BACKENDS={'DEFAULT': 'proctortrack', 'proctortrack': {}})
|
||||
class CourseValidationViewTest(SharedModuleStoreTestCase, APITestCase):
|
||||
"""
|
||||
@@ -82,39 +87,54 @@ class CourseValidationViewTest(SharedModuleStoreTestCase, APITestCase):
|
||||
resp = self.client.get(self.get_url(self.course_key))
|
||||
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def test_staff_succeeds(self):
|
||||
self.client.login(username=self.staff.username, password=self.password)
|
||||
resp = self.client.get(self.get_url(self.course_key), {'all': 'true'})
|
||||
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
||||
expected_data = {
|
||||
'assignments': {
|
||||
'total_number': 1,
|
||||
'total_visible': 1,
|
||||
'assignments_with_dates_before_start': [],
|
||||
'assignments_with_dates_after_end': [],
|
||||
'assignments_with_ora_dates_after_end': [],
|
||||
'assignments_with_ora_dates_before_start': [],
|
||||
},
|
||||
'dates': {
|
||||
'has_start_date': True,
|
||||
'has_end_date': False,
|
||||
},
|
||||
'updates': {
|
||||
'has_update': True,
|
||||
},
|
||||
'certificates': {
|
||||
'is_enabled': False,
|
||||
'is_activated': False,
|
||||
'has_certificate': False,
|
||||
},
|
||||
'grades': {
|
||||
'has_grading_policy': False,
|
||||
'sum_of_weights': 1.0,
|
||||
},
|
||||
'proctoring': {
|
||||
'needs_proctoring_escalation_email': True,
|
||||
'has_proctoring_escalation_email': True,
|
||||
},
|
||||
'is_self_paced': True,
|
||||
}
|
||||
self.assertDictEqual(resp.data, expected_data)
|
||||
@ddt.data(
|
||||
(False, False),
|
||||
(True, False),
|
||||
(False, True),
|
||||
(True, True),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_staff_succeeds(self, certs_html_view, with_modes):
|
||||
features = dict(settings.FEATURES, CERTIFICATES_HTML_VIEW=certs_html_view)
|
||||
with override_settings(FEATURES=features):
|
||||
if with_modes:
|
||||
CourseModeFactory.create_batch(
|
||||
2,
|
||||
course_id=self.course.id,
|
||||
mode_slug=factory.Iterator([CourseMode.AUDIT, CourseMode.VERIFIED]),
|
||||
)
|
||||
self.client.login(username=self.staff.username, password=self.password)
|
||||
resp = self.client.get(self.get_url(self.course_key), {'all': 'true'})
|
||||
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
||||
expected_data = {
|
||||
'assignments': {
|
||||
'total_number': 1,
|
||||
'total_visible': 1,
|
||||
'assignments_with_dates_before_start': [],
|
||||
'assignments_with_dates_after_end': [],
|
||||
'assignments_with_ora_dates_after_end': [],
|
||||
'assignments_with_ora_dates_before_start': [],
|
||||
},
|
||||
'dates': {
|
||||
'has_start_date': True,
|
||||
'has_end_date': False,
|
||||
},
|
||||
'updates': {
|
||||
'has_update': True,
|
||||
},
|
||||
'certificates': {
|
||||
'is_enabled': with_modes,
|
||||
'is_activated': False,
|
||||
'has_certificate': False,
|
||||
},
|
||||
'grades': {
|
||||
'has_grading_policy': False,
|
||||
'sum_of_weights': 1.0,
|
||||
},
|
||||
'proctoring': {
|
||||
'needs_proctoring_escalation_email': True,
|
||||
'has_proctoring_escalation_email': True,
|
||||
},
|
||||
'is_self_paced': True,
|
||||
}
|
||||
self.assertDictEqual(resp.data, expected_data)
|
||||
|
||||
@@ -121,7 +121,7 @@ class CertificateManager:
|
||||
along with the certificates.
|
||||
"""
|
||||
is_active = False
|
||||
certificates = None
|
||||
certificates = []
|
||||
if settings.FEATURES.get('CERTIFICATES_HTML_VIEW', False):
|
||||
certificates = CertificateManager.get_certificates(course)
|
||||
# we are assuming only one certificate in certificates collection.
|
||||
|
||||
Reference in New Issue
Block a user