|
2 | 2 | Tests for the course import API views |
3 | 3 | """ |
4 | 4 |
|
5 | | - |
| 5 | +import factory |
6 | 6 | from datetime import datetime |
| 7 | +from django.conf import settings |
7 | 8 |
|
| 9 | +import ddt |
8 | 10 | from django.test.utils import override_settings |
9 | 11 | from django.urls import reverse |
10 | 12 | from rest_framework import status |
11 | 13 | from rest_framework.test import APITestCase |
12 | 14 | from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase |
13 | 15 | from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory |
14 | 16 |
|
| 17 | +from common.djangoapps.course_modes.models import CourseMode |
| 18 | +from common.djangoapps.course_modes.tests.factories import CourseModeFactory |
15 | 19 | from common.djangoapps.student.tests.factories import StaffFactory |
16 | 20 | from common.djangoapps.student.tests.factories import UserFactory |
17 | 21 |
|
18 | 22 |
|
| 23 | +@ddt.ddt |
19 | 24 | @override_settings(PROCTORING_BACKENDS={'DEFAULT': 'proctortrack', 'proctortrack': {}}) |
20 | 25 | class CourseValidationViewTest(SharedModuleStoreTestCase, APITestCase): |
21 | 26 | """ |
@@ -82,39 +87,54 @@ def test_student_fails(self): |
82 | 87 | resp = self.client.get(self.get_url(self.course_key)) |
83 | 88 | self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN) |
84 | 89 |
|
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) |
0 commit comments