-
Notifications
You must be signed in to change notification settings - Fork 169
/
test_content_migration.py
250 lines (194 loc) · 9.63 KB
/
test_content_migration.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
from __future__ import absolute_import, division, print_function, unicode_literals
import unittest
import requests_mock
from canvasapi import Canvas
from canvasapi.account import Account
from canvasapi.content_migration import ContentMigration, MigrationIssue
from canvasapi.course import Course
from canvasapi.group import Group
from canvasapi.progress import Progress
from canvasapi.user import User
from tests import settings
from tests.util import register_uris
@requests_mock.Mocker()
class TestContentMigration(unittest.TestCase):
def setUp(self):
self.canvas = Canvas(settings.BASE_URL, settings.API_KEY)
with requests_mock.Mocker() as m:
requires = {
'course': ['get_by_id', 'get_content_migration_single'],
'group': ['get_by_id', 'get_content_migration_single'],
'account': ['get_by_id', 'get_content_migration_single'],
'user': ['get_by_id', 'get_content_migration_single']
}
register_uris(requires, m)
self.account = self.canvas.get_account(1)
self.course = self.canvas.get_course(1)
self.group = self.canvas.get_group(1)
self.user = self.canvas.get_user(1)
self.content_migration = self.account.get_content_migration(1)
self.content_migration_course = self.course.get_content_migration(1)
self.content_migration_group = self.group.get_content_migration(1)
self.content_migration_user = self.user.get_content_migration(1)
# __str__()
def test__str__(self, m):
string = str(self.content_migration)
self.assertIsInstance(string, str)
# _parent_type
def test_parent_type_account(self, m):
self.assertEqual(self.content_migration._parent_type, 'account')
def test_parent_type_course(self, m):
self.assertEqual(self.content_migration_course._parent_type, 'course')
def test_parent_type_group(self, m):
self.assertEqual(self.content_migration_group._parent_type, 'group')
def test_parent_type_user(self, m):
self.assertEqual(self.content_migration_user._parent_type, 'user')
def test_parent_type_no_type(self, m):
migration = ContentMigration(self.canvas._Canvas__requester, {'id': 1})
with self.assertRaises(ValueError):
migration._parent_type
# _parent_id
def test_parent_id_account(self, m):
self.assertEqual(self.content_migration._parent_id, 1)
def test_parent_id_course(self, m):
self.assertEqual(self.content_migration_course._parent_id, 1)
def test_parent_id_group(self, m):
self.assertEqual(self.content_migration_group._parent_id, 1)
def test_parent_id_user(self, m):
self.assertEqual(self.content_migration_user._parent_id, 1)
def test_parent_id_no_id(self, m):
migration = ContentMigration(self.canvas._Canvas__requester, {'id': 1})
with self.assertRaises(ValueError):
migration._parent_id
# get_migration_issue()
def test_get_migration_issue(self, m):
register_uris({'content_migration': ['get_migration_issue_single']}, m)
issue = self.content_migration.get_migration_issue(1)
self.assertIsInstance(issue, MigrationIssue)
self.assertTrue(hasattr(issue, 'id'))
self.assertEqual(issue.id, 1)
# get_migration_issues()
def test_get_migration_issues(self, m):
register_uris({'content_migration': ['get_migration_issue_multiple']}, m)
issues = self.content_migration.get_migration_issues()
self.assertEqual(len(list(issues)), 2)
self.assertIsInstance(issues[0], MigrationIssue)
self.assertTrue(hasattr(issues[0], 'id'))
self.assertEqual(issues[0].id, 1)
self.assertIsInstance(issues[1], MigrationIssue)
self.assertTrue(hasattr(issues[1], 'id'))
self.assertEqual(issues[1].id, 2)
# get_parent()
def test_get_parent_account(self, m):
register_uris({'content_migration': ['get_parent_account']}, m)
account = self.content_migration.get_parent()
self.assertIsInstance(account, Account)
self.assertTrue(hasattr(account, 'id'))
self.assertEqual(account.id, 1)
def test_get_parent_course(self, m):
register_uris({'content_migration': ['get_parent_course']}, m)
course = self.content_migration_course.get_parent()
self.assertIsInstance(course, Course)
self.assertTrue(hasattr(course, 'id'))
self.assertEqual(course.id, 1)
def test_get_parent_group(self, m):
register_uris({'content_migration': ['get_parent_group']}, m)
group = self.content_migration_group.get_parent()
self.assertIsInstance(group, Group)
self.assertTrue(hasattr(group, 'id'))
self.assertEqual(group.id, 1)
def test_get_parent_user(self, m):
register_uris({'content_migration': ['get_parent_user']}, m)
user = self.content_migration_user.get_parent()
self.assertIsInstance(user, User)
self.assertTrue(hasattr(user, 'id'))
self.assertEqual(user.id, 1)
# get_progress()
def test_get_progress(self, m):
register_uris({'content_migration': ['get_progress']}, m)
progress = self.content_migration.get_progress()
self.assertIsInstance(progress, Progress)
self.assertTrue(hasattr(progress, 'id'))
self.assertEqual(progress.id, 1)
# update()
def test_update(self, m):
register_uris({'content_migration': ['update']}, m)
worked = self.content_migration.update()
self.assertTrue(worked)
self.assertTrue(hasattr(self.content_migration, 'migration_type'))
self.assertEqual(self.content_migration.migration_type, "dummy_importer")
def test_update_fail(self, m):
register_uris({'content_migration': ['update_fail']}, m)
worked = self.content_migration.update()
self.assertFalse(worked)
@requests_mock.Mocker()
class TestMigrationIssue(unittest.TestCase):
def setUp(self):
self.canvas = Canvas(settings.BASE_URL, settings.API_KEY)
with requests_mock.Mocker() as m:
requires = {
'course': ['get_by_id', 'get_content_migration_single'],
'group': ['get_by_id', 'get_content_migration_single'],
'account': ['get_by_id', 'get_content_migration_single'],
'user': ['get_by_id', 'get_content_migration_single'],
'content_migration': ['get_migration_issue_single',
'get_migration_issue_single_course',
'get_migration_issue_single_group',
'get_migration_issue_single_user']
}
register_uris(requires, m)
self.account = self.canvas.get_account(1)
self.course = self.canvas.get_course(1)
self.group = self.canvas.get_group(1)
self.user = self.canvas.get_user(1)
self.content_migration = self.account.get_content_migration(1)
self.content_migration_course = self.course.get_content_migration(1)
self.content_migration_group = self.group.get_content_migration(1)
self.content_migration_user = self.user.get_content_migration(1)
self.migration_issue = self.content_migration.get_migration_issue(1)
self.migration_issue_course = self.content_migration_course.get_migration_issue(1)
self.migration_issue_group = self.content_migration_group.get_migration_issue(1)
self.migration_issue_user = self.content_migration_user.get_migration_issue(1)
# __str__()
def test__str__(self, m):
string = str(self.migration_issue)
self.assertIsInstance(string, str)
# update()
def test_update(self, m):
register_uris({'content_migration': ['update_issue']}, m)
worked = self.migration_issue.update()
self.assertTrue(worked)
self.assertTrue(hasattr(self.migration_issue, 'id'))
self.assertEqual(self.migration_issue.id, 1)
def test_update_fail(self, m):
register_uris({'content_migration': ['update_issue_fail']}, m)
worked = self.migration_issue.update()
self.assertFalse(worked)
@requests_mock.Mocker()
class TestMigrator(unittest.TestCase):
def setUp(self):
self.canvas = Canvas(settings.BASE_URL, settings.API_KEY)
with requests_mock.Mocker() as m:
requires = {
'course': ['get_by_id', 'get_migration_systems_multiple'],
'group': ['get_by_id', 'get_migration_systems_multiple'],
'account': ['get_by_id', 'get_migration_systems_multiple'],
'user': ['get_by_id', 'get_migration_systems_multiple'],
'content_migration': ['get_migration_issue_single',
'get_migration_issue_single_course',
'get_migration_issue_single_group',
'get_migration_issue_single_user']
}
register_uris(requires, m)
self.account = self.canvas.get_account(1)
self.course = self.canvas.get_course(1)
self.group = self.canvas.get_group(1)
self.user = self.canvas.get_user(1)
self.migrator = self.account.get_migration_systems()[0]
self.migrator_course = self.course.get_migration_systems()[0]
self.migrator_group = self.group.get_migration_systems()[0]
self.migrator_user = self.user.get_migration_systems()[0]
# __str__()
def test__str__(self, m):
string = str(self.migrator)
self.assertIsInstance(string, str)