-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.py
382 lines (312 loc) · 17.8 KB
/
tests.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
from .meeting_manager import AdobeConnectMeetingManager, AdobeConnectKeyManager,\
AdobeConnectUser
from .adobe_connect import AdobeConnectAPI, generate_random_id
@skip("Only run these tests on-demand due to resource dependencies i.e., Adobe Connect")
class AdobeConnectTests(TestCase):
def test_login_to_adobe_connect(self):
connection = AdobeConnectAPI()
self.assertTrue(connection._is_authenticated)
self.assertIsNotNone(connection._auth_cookie)
def test_get_meetings(self):
connection = AdobeConnectAPI()
meeting = connection.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=None,
end_date=None)
meetings = connection.get_meetings(None, None, None)
self.assertGreater(len(meetings), 0)
meetings_with_sco_id = connection.get_meetings([meeting.sco_id],
None, None)
self.assertGreater(len(meetings_with_sco_id), 0)
def test_create_meeting(self):
connection = AdobeConnectAPI()
meeting = connection.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=None,
end_date=None)
self.assertIsNotNone(meeting.sco_id)
def test_create_account_for_user(self):
connection = AdobeConnectAPI()
email = "create_account_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
user = connection.create_account_for_user(generate_random_id(),
generate_random_id(),
email)
self.assertEqual(user.login, email)
def test_add_participants_to_meeting(self):
connection = AdobeConnectAPI()
host_email = "add_participants_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
host_user = connection.create_account_for_user(generate_random_id(),
generate_random_id(),
host_email)
mini_host_email = \
"add_participants_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
mini_host_user = \
connection.create_account_for_user(generate_random_id(),
generate_random_id(),
mini_host_email)
meeting = connection.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=None,
end_date=None)
connection.add_participant_to_meeting(host_user.principal_id,
meeting.sco_id, "host")
connection.add_participant_to_meeting(mini_host_user.principal_id,
meeting.sco_id, "mini-host")
def test_get_participants_from_meeting(self):
connection = AdobeConnectAPI()
host_email = "add_participants_test.{0}" + generate_random_id() + "@flashnotes.com"
host_user = connection.create_account_for_user(generate_random_id(),
generate_random_id(),
host_email)
mini_host_email = "add_participants_test." + generate_random_id() + "@flashnotes.com"
mini_host_user = \
connection.create_account_for_user(generate_random_id(),
generate_random_id(),
mini_host_email)
meeting = connection.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=None,
end_date=None)
connection.add_participant_to_meeting(host_user.principal_id,
meeting.sco_id, "host")
connection.add_participant_to_meeting(mini_host_user.principal_id,
meeting.sco_id, "mini-host")
self.assertIsNotNone(connection.
get_participants_for_meeting(meeting.sco_id))
def test_get_meeting_url(self):
connection = AdobeConnectAPI()
email = "get_meeting_url_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
user = connection.create_account_for_user(generate_random_id(),
generate_random_id(),
email)
session_cookie = connection.authenticate_participant(user.login,
"Flash!123")
def test_delete_meeting_room(self):
connection = AdobeConnectAPI()
meeting = connection.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=None,
end_date=None)
connection.delete_meeting_room(meeting.sco_id)
def test_authenticate_user(self):
connection = AdobeConnectAPI()
email = "authenticate_user_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
user = connection.create_account_for_user(generate_random_id(),
generate_random_id(),
email)
session_cookie = connection.authenticate_participant(user.login,
"Flash!123")
meeting = connection.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=None,
end_date=None)
connection.add_participant_to_meeting(user.principal_id,
meeting.sco_id, "host")
self.assertIsNotNone(session_cookie)
def test_update_group_for_user(self):
connection = AdobeConnectAPI()
email = "create_account_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
user = connection.create_account_for_user(generate_random_id(),
generate_random_id(),
email)
# Add to group LIVE_ADMINS
connection.update_group_for_user(user.principal_id, "LIVE_ADMINS")
# Remove from group LIVE_ADMINS
connection.update_group_for_user(user.principal_id, "LIVE_ADMINS", True)
def test_get_users_in_group(self):
connection = AdobeConnectAPI()
users = connection.get_users_in_group("LIVE_ADMINS")
self.assertGreater(len(users), 0)
def test_show_user_in_correct_group(self):
connection = AdobeConnectAPI()
host_email = "add_participants_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
host_user = connection.create_account_for_user(generate_random_id(),
generate_random_id(),
host_email)
mini_host_email = \
"add_participants_test.{0}{1}".format(generate_random_id(),
"@flashnotes.com")
mini_host_user = \
connection.create_account_for_user(generate_random_id(),
generate_random_id(),
mini_host_email)
meeting = connection.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=None,
end_date=None)
connection.update_group_for_user(host_user.principal_id, "LIVE_ADMINS")
connection.add_participant_to_meeting(host_user.principal_id,
meeting.sco_id, "host")
connection.add_participant_to_meeting(mini_host_user.principal_id,
meeting.sco_id, "mini-host")
host_session = connection.authenticate_participant(host_user.login,
"Flash!123")
mini_host_session = connection.authenticate_participant(mini_host_user.login,
"Flash!123")
host_url = connection.get_meeting_url(meeting.sco_id, host_session)
pres_url = connection.get_meeting_url(meeting.sco_id, mini_host_session)
@skip("Only run these tests on-demand due to Adobe resource dependency.")
class AdobeConnectUserTests(TestCase):
def setUp(self):
self.host = factories.User.create(email="[email protected]")
self.attendee = factories.User.create(email="[email protected]")
from .models import adobe_connect_api
self._ac_api = adobe_connect_api
def test_exercise_user_workflow(self):
# Register users
self.host_user = AdobeConnectUser()
self.host_user.register(self._ac_api, self.host)
self.host_user._validate_acount()
self.assertEqual(self.host_user.fn_user_email, self.host.email)
self.assertEqual(self.host_user.fn_user.id, self.host.id)
self.assertIsNotNone(self.host_user.pwd)
self.attendee_user = AdobeConnectUser()
self.attendee_user.register(self._ac_api, self.attendee)
self.attendee_user._validate_acount()
self.assertEqual(self.attendee_user.fn_user_email, self.attendee.email)
self.assertEqual(self.attendee_user.fn_user.id, self.attendee.id)
self.assertIsNotNone(self.attendee_user.pwd)
# Add user to room
room = self._ac_api.create_meeting(meeting_description=
"fn-test-meeting-{0}".
format(generate_random_id()),
start_date=datetime.utcnow(),
end_date=None)
# Add participants
# Host
self.host_user.add_to_meeting_room(self._ac_api,
room.sco_id, "host")
# Attendee
self.attendee_user.add_to_meeting_room(self._ac_api,
room.sco_id, "mini-host")
# Authenticate and get URL
# host
host_url = self.host_user.get_url_for_meeting_room(self._ac_api,
room.sco_id)
print host_url
self.assertIn("https://flashnotes.adobeconnect.com", host_url)
# attendee
attendee_url = self.attendee_user.\
get_url_for_meeting_room(self._ac_api, room.sco_id)
print attendee_url
self.assertIn("https://flashnotes.adobeconnect.com", attendee_url)
# This is to clean up resources. If you want to test that the
# host URL will log the user in as HOST you can comment out this line.
self.host_user.remove_from_hosts_group(self._ac_api)
@skip("Only run these tests on-demand due to Adobe resource dependency.")
class AdobeConnectMeetingManagerTests(TestCase):
"""
This test will use a Mock class
"""
class AdobeConnectMeetingManagerMock(AdobeConnectMeetingManager):
def __init__(self):
self._adobe_connect_meeting_room = None
self.host = factories.User.create(email="[email protected]")
self.attendee = factories.User.create(email="[email protected]")
self.scheduled_start_time = pytz.UTC.localize(datetime.utcnow() +
timedelta(minutes=1))
self.some_other_user = factories.User.create(email="[email protected]".
format(generate_random_id(4)))
def get_host(self):
return self.host
def get_meeting_room_template_type(self):
return "TUTORING"
def get_attendees(self):
from django.contrib.auth.models import User
return User.objects.filter(id=self.attendee.id)
def get_adobe_connect_meeting_sco_id(self):
return self._adobe_connect_meeting_room
def set_adobe_connect_meeting_sco_id(self, sco_id, save=True):
self._adobe_connect_meeting_room = sco_id
def get_scheduled_start_time(self):
return self.scheduled_start_time
def test_create_resources_with_adobe_connect_meeting_manager(self):
from .models import adobe_connect_api
ac_mock = self.AdobeConnectMeetingManagerMock()
# Create meeting resources
ac_mock.create_adobe_session_resources()
# Should return gracefully on second call (and do nothing)
ac_mock.create_adobe_session_resources()
self.assertIsNotNone(ac_mock.get_adobe_connect_meeting_sco_id() )
with self.assertRaises(Exception):
ac_mock.authenticate_user_for_adobe_session(self.some_other_user)
host_url = ac_mock.authenticate_user_for_adobe_session(ac_mock.host)
print host_url
self.assertIn("https://flashnotes.adobeconnect.com", host_url)
attendee_url = \
ac_mock.authenticate_user_for_adobe_session(ac_mock.attendee)
print attendee_url
self.assertIn("https://flashnotes.adobeconnect.com", attendee_url)
ac_host_user = AdobeConnectUser.objects.get(fn_user_id=ac_mock.host.id)
self.assertEqual(ac_host_user.last_meeting_room_entered,
ac_mock.get_adobe_connect_meeting_sco_id())
self.assertEqual(ac_host_user.last_meeting_room_role, "host")
self.assertIsNotNone(ac_host_user.last_meeting_room_entrance_datetime)
# If you want to do some experimenting with the URLs created above
# comment out the next two lines.
ac_host_user.remove_from_hosts_group(adobe_connect_api)
ac_mock.destroy_adobe_session_resources()
@skip("Only run these tests on-demand due to Adobe resource dependency.")
class AdobeConnectKeyManagerTests(TestCase):
def test_recycle_keys_1(self):
from .models import adobe_connect_api
host1 = factories.User.create(email="[email protected]")
three_hours_ago = \
pytz.UTC.localize(datetime.utcnow() - timedelta(hours=3))
host1_user = AdobeConnectUser()
host1_user.register(adobe_connect_api, host1)
host1_user.add_to_hosts_group(adobe_connect_api)
# fake some data
host1_user.last_meeting_room_role = "host"
host1_user.last_meeting_room_entered = "TESTROOM"
host1_user.last_meeting_room_entrance_datetime = three_hours_ago
host1_user.save()
AdobeConnectKeyManager().recycle_keys(max_age_threshold_minutes=120)
host1_user = AdobeConnectUser.objects.get(fn_user_id=host1.id)
self.assertEqual(host1_user.last_meeting_room_role, "revoked")
def test_recycle_keys_2(self):
from .models import adobe_connect_api
host1 = factories.User.create(email="[email protected]")
three_hours_ago = \
pytz.UTC.localize(datetime.utcnow() - timedelta(hours=1))
host1_user = AdobeConnectUser()
host1_user.register(adobe_connect_api, host1)
host1_user.add_to_hosts_group(adobe_connect_api)
# fake some data
host1_user.last_meeting_room_role = "host"
host1_user.last_meeting_room_entered = "TESTROOM"
host1_user.last_meeting_room_entrance_datetime = three_hours_ago
host1_user.save()
AdobeConnectKeyManager().recycle_keys(max_age_threshold_minutes=120)
host1_user = AdobeConnectUser.objects.get(fn_user_id=host1.id)
self.assertEqual(host1_user.last_meeting_room_role, "host")
def test_recycle_keys_3(self):
from .models import adobe_connect_api
host1 = factories.User.create(email="[email protected]")
three_hours_ago = \
pytz.UTC.localize(datetime.utcnow() - timedelta(minutes=30))
host1_user = AdobeConnectUser()
host1_user.register(adobe_connect_api, host1)
host1_user.add_to_hosts_group(adobe_connect_api)
# fake some data
host1_user.last_meeting_room_role = "host"
host1_user.last_meeting_room_entered = "TESTROOM"
host1_user.last_meeting_room_entrance_datetime = three_hours_ago
host1_user.save()
AdobeConnectKeyManager().recycle_keys(max_age_threshold_minutes=15)
host1_user = AdobeConnectUser.objects.get(fn_user_id=host1.id)
self.assertEqual(host1_user.last_meeting_room_role, "revoked")