/
test_admin_course_run.py
132 lines (111 loc) · 4.86 KB
/
test_admin_course_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
Test suite defining the admin pages for the Course model
"""
from datetime import datetime
from django.urls import reverse
from django.utils import timezone
import pytz
from cms.test_utils.testcases import CMSTestCase
from richie.apps.core.factories import UserFactory
from richie.apps.courses.factories import CourseRunFactory
class CourseRunAdminTestCase(CMSTestCase):
"""
Integration test suite to validate the behavior of admin pages for the Course model
"""
def test_admin_course_run_list_view(self):
"""
The admin list view of course runs should display the title of the related page.
"""
user = UserFactory(is_staff=True, is_superuser=True)
self.client.login(username=user.username, password="password")
# Create a course run linked to a page
course_run = CourseRunFactory()
# Get the admin list view
url = reverse("admin:courses_courserun_changelist")
response = self.client.get(url, follow=True)
# Check that the page includes the title
self.assertContains(
response, course_run.extended_object.get_title(), status_code=200
)
def test_admin_course_run_add_view(self):
"""
The admin add view should work for course runs.
"""
user = UserFactory(is_staff=True, is_superuser=True)
self.client.login(username=user.username, password="password")
# Get the admin change view
url = reverse("admin:courses_courserun_add")
response = self.client.get(url, follow=True)
# Check that the page includes all our fields
self.assertContains(response, "id_resource_link")
self.assertContains(response, "id_start_", count=3)
self.assertContains(response, "id_end_", count=3)
self.assertContains(response, "id_enrollment_start_", count=3)
self.assertContains(response, "id_enrollment_end_", count=3)
def test_admin_course_run_change_view_get(self):
"""
The admin change view should include the editable and readonly fields as expected.
In particular, the relation fields should only include options for related objects in
their draft version.
"""
user = UserFactory(is_staff=True, is_superuser=True)
self.client.login(username=user.username, password="password")
# Create a course run
course_run = CourseRunFactory()
# Get the admin change view
url = reverse("admin:courses_courserun_change", args=[course_run.id])
response = self.client.get(url)
# Check that the page includes the page title
self.assertContains(
response, course_run.extended_object.get_title(), status_code=200
)
# Check that the page includes all our fields
self.assertContains(response, "id_resource_link")
self.assertContains(response, "id_start_", count=3)
self.assertContains(response, "id_end_", count=3)
self.assertContains(response, "id_enrollment_start_", count=3)
self.assertContains(response, "id_enrollment_end_", count=3)
def test_admin_course_run_change_view_post(self):
"""
Validate that the course run can be updated via the admin.
"""
user = UserFactory(is_staff=True, is_superuser=True)
self.client.login(username=user.username, password="password")
# Create a course run
course_run = CourseRunFactory()
# Get the admin change view
url = reverse("admin:courses_courserun_change", args=[course_run.id])
data = {
"languages": ["fr", "en"],
"resource_link": "https://example.com/my-resource-link",
"start_0": "2015-01-15",
"start_1": "07:06:15",
"end_0": "2015-01-30",
"end_1": "23:52:34",
"enrollment_start_0": "2015-01-02",
"enrollment_start_1": "13:13:07",
"enrollment_end_0": "2015-01-23",
"enrollment_end_1": "09:07:11",
}
with timezone.override(pytz.utc):
response = self.client.post(url, data)
self.assertEqual(response.status_code, 302)
# Check that the course run was updated as expected
course_run.refresh_from_db()
self.assertEqual(course_run.languages, ["fr", "en"])
self.assertEqual(
course_run.resource_link, "https://example.com/my-resource-link"
)
self.assertEqual(
course_run.start, datetime(2015, 1, 15, 7, 6, 15, tzinfo=pytz.utc)
)
self.assertEqual(
course_run.end, datetime(2015, 1, 30, 23, 52, 34, tzinfo=pytz.utc)
)
self.assertEqual(
course_run.enrollment_start,
datetime(2015, 1, 2, 13, 13, 7, tzinfo=pytz.utc),
)
self.assertEqual(
course_run.enrollment_end, datetime(2015, 1, 23, 9, 7, 11, tzinfo=pytz.utc)
)