forked from treeio/treeio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
434 lines (352 loc) · 18.7 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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# encoding: utf-8
# Copyright 2011 Tree.io Limited
# This file is part of Treeio.
# License www.tree.io/license
"""
Documents: test suites
"""
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User as DjangoUser
from treeio.core.models import User, Group, Perspective, ModuleSetting, Object
from treeio.documents.models import Folder, Document, File, WebLink
class DocumentsModelsTest(TestCase):
"Documents Models Tests"
def test_model_folder(self):
"Test Folder Model"
obj = Folder(name='test')
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
def test_model_document(self):
"Test Document Model"
folder = Folder(name='test')
folder.save()
obj = Document(title='test', folder=folder)
obj.save()
self.assertEquals(folder, obj.folder)
self.assertNotEquals(obj.id, None)
obj.delete()
def test_model_file(self):
"Test File Model"
folder = Folder(name='test')
folder.save()
obj = File(name='test', folder=folder)
obj.save()
self.assertEquals(folder, obj.folder)
self.assertNotEquals(obj.id, None)
obj.delete()
def test_model_weblink(self):
"Test WebLink Model"
folder = Folder(name='test')
folder.save()
obj = WebLink(title='test', folder=folder, url='test')
obj.save()
self.assertEquals(folder, obj.folder)
self.assertNotEquals(obj.id, None)
obj.delete()
class DocumentsViewsTest(TestCase):
"Documents functional tests for views"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
Object.objects.all().delete()
# Create objects
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.folder = Folder(name='test')
self.folder.set_default_user()
self.folder.save()
self.document = Document(title='test_document', folder=self.folder)
self.document.set_default_user()
self.document.save()
self.file = File(name='test_file', folder=self.folder)
self.file.set_default_user()
self.file.save()
self.link = WebLink(title='test', folder=self.folder, url='test')
self.link.set_default_user()
self.link.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_index_login(self):
"Test index page with login at /documents/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('document_index'))
self.assertEquals(response.status_code, 200)
def test_index_documents_login(self):
"Test index page with login at /documents/documents/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('index_documents'))
self.assertEquals(response.status_code, 200)
def test_index_files_login(self):
"Test index page with login at /documents/files/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('index_files'))
self.assertEquals(response.status_code, 200)
def test_index_weblinks_login(self):
"Test index page with login at /documents/weblinks/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('index_weblinks'))
self.assertEquals(response.status_code, 200)
# Folders
def test_folder_add(self):
"Test index page with login at /documents/folder/add/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_folder_add'))
self.assertEquals(response.status_code, 200)
# form
self.assertEqual(Folder.objects.count(), 1)
post_data = {'name': 'test'}
response = self.client.post(reverse('documents_folder_add'), post_data)
self.assertEquals(response.status_code, 302) # redirect somewhere
self.assertEquals(Folder.objects.count(), 2)
def test_folder_view_login(self):
"Test index page with login at /documents/folder/view/<folder_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_folder_view', args=[self.folder.id]))
self.assertEquals(response.status_code, 200)
def test_folder_edit_login(self):
"Test index page with login at /documents/folder/edit/<folder_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_folder_edit', args=[self.folder.id]))
self.assertEquals(response.status_code, 200)
def test_folder_delete_login(self):
"Test index page with login at /documents/folder/delete/<folder_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_folder_delete', args=[self.folder.id]))
self.assertEquals(response.status_code, 200)
# Documents
def test_document_add(self):
"Test index page with login at /documents/add"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_document_add'))
self.assertEquals(response.status_code, 200)
# form
self.assertEqual(Document.objects.count(), 1)
response = self.client.get(reverse('documents_document_add'))
post_data = {'title': 'test',
'folder': self.folder,
}
response = self.client.post(reverse('documents_document_add'), post_data)
#self.assertEqual(Document.objects.count(), 2)
def test_document_add_typed(self):
"Test index page with login at /documents/add/folder/<folder_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_document_add_typed', args=[self.folder.id]))
self.assertEquals(response.status_code, 200)
def test_document_view_login(self):
"Test index page with login at /documents/view/<document_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_document_view', args=[self.document.id]))
self.assertEquals(response.status_code, 200)
def test_document_edit_login(self):
"Test index page with login at /documents/edit/<document_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_document_edit', args=[self.document.id]))
self.assertEquals(response.status_code, 200)
def test_document_delete_login(self):
"Test index page with login at /documents/delete/<document_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_document_delete', args=[self.document.id]))
self.assertEquals(response.status_code, 200)
# Files
def test_file_view_login(self):
"Test index page with login at /file/view/<file_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_file_view', args=[self.file.id]))
self.assertEquals(response.status_code, 200)
def test_file_edit_login(self):
"Test index page with login at /file/edit/<file_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_file_edit', args=[self.file.id]))
self.assertEquals(response.status_code, 200)
def test_file_delete_login(self):
"Test index page with login at /file/view/<file_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_file_delete', args=[self.file.id]))
self.assertEquals(response.status_code, 200)
# Web Links
def test_weblink_add_typed(self):
"Test index page with login at /documents/weblink/add/<folder_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_weblink_add_typed', args=[self.folder.id]))
self.assertEquals(response.status_code, 200)
def test_weblink_add(self):
"Test index page with login at /documents/weblink/add/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_weblink_add'))
self.assertEquals(response.status_code, 200)
# form
self.assertEqual(WebLink.objects.count(), 1)
response = self.client.get(reverse('documents_weblink_add'))
post_data = {'title': 'test',
'folder': self.folder,
'url': 'test',
}
response = self.client.post(reverse('documents_weblink_add'), post_data)
#self.assertEqual(WebLink.objects.count(), 2)
def test_weblink_view_login(self):
"Test index page with login at /documents/view/<weblink_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_weblink_view', args=[self.link.id]))
self.assertEquals(response.status_code, 200)
def test_weblink_edit_login(self):
"Test index page with login at /documents/edit/<weblink_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_weblink_edit', args=[self.link.id]))
self.assertEquals(response.status_code, 200)
def test_weblink_delete_login(self):
"Test index page with login at /documents/delete/<weblink_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('documents_weblink_delete', args=[self.link.id]))
self.assertEquals(response.status_code, 200)
######################################
# Testing views when user is not logged in
######################################
def test_index(self):
"Test index page at /documents/"
response = self.client.get('/documents/')
# Redirects as unauthenticated
self.assertRedirects(response, reverse('user_login'))
def test_index_documents_out(self):
"Testing /documents/documents/"
response = self.client.get(reverse('index_documents'))
self.assertRedirects(response, reverse('user_login'))
def test_index_files_out(self):
"Testing /documents/files/"
response = self.client.get(reverse('index_files'))
self.assertRedirects(response, reverse('user_login'))
def test_index_weblinks_out(self):
"Testing /documents/weblinks/"
response = self.client.get(reverse('index_weblinks'))
self.assertRedirects(response, reverse('user_login'))
# Folders
def test_folder_add_out(self):
"Testing /documents/folder/add/"
response = self.client.get(reverse('documents_folder_add'))
self.assertRedirects(response, reverse('user_login'))
def test_folder_view_out(self):
"Testing /documents/folder/view/<folder_id>"
response = self.client.get(reverse('documents_folder_view', args=[self.folder.id]))
self.assertRedirects(response, reverse('user_login'))
def test_folder_edit_out(self):
"Testing /documents/folder/edit/<folder_id>"
response = self.client.get(reverse('documents_folder_edit', args=[self.folder.id]))
self.assertRedirects(response, reverse('user_login'))
def test_folder_delete_out(self):
"Testing /documents/folder/delete/<folder_id>"
response = self.client.get(reverse('documents_folder_delete', args=[self.folder.id]))
self.assertRedirects(response, reverse('user_login'))
# Documents
def test_document_add_out(self):
"Testing /documents/add"
response = self.client.get(reverse('documents_document_add'))
self.assertRedirects(response, reverse('user_login'))
def test_document_add_typed_out(self):
"Testing /documents/add/folder/<folder_id>"
response = self.client.get(reverse('documents_document_add_typed', args=[self.folder.id]))
self.assertRedirects(response, reverse('user_login'))
def test_document_view_out(self):
"Testing /documents/view/<document_id>"
response = self.client.get(reverse('documents_document_view', args=[self.document.id]))
self.assertRedirects(response, reverse('user_login'))
def test_document_edit_out(self):
"Testing /documents/edit/<document_id>"
response = self.client.get(reverse('documents_document_edit', args=[self.document.id]))
self.assertRedirects(response, reverse('user_login'))
def test_document_delete_out(self):
"Testing /documents/delete/<document_id>"
response = self.client.get(reverse('documents_document_delete', args=[self.document.id]))
self.assertRedirects(response, reverse('user_login'))
# Files
def test_file_view_out(self):
"Testing /file/view/<file_id>"
response = self.client.get(reverse('documents_file_view', args=[self.file.id]))
self.assertRedirects(response, reverse('user_login'))
def test_file_edit_out(self):
"Testing /file/edit/<file_id>"
response = self.client.get(reverse('documents_file_edit', args=[self.file.id]))
self.assertRedirects(response, reverse('user_login'))
def test_file_delete_out(self):
"Testing /file/view/<file_id>"
response = self.client.get(reverse('documents_file_delete', args=[self.file.id]))
self.assertRedirects(response, reverse('user_login'))
# Web Links
def test_weblink_add_typed_out(self):
"Testing /documents/weblink/add/<folder_id>"
response = self.client.get(reverse('documents_weblink_add_typed', args=[self.folder.id]))
self.assertRedirects(response, reverse('user_login'))
def test_weblink_add_out(self):
"Testing /documents/weblink/add/"
response = self.client.get(reverse('documents_weblink_add'))
self.assertRedirects(response, reverse('user_login'))
def test_weblink_view_out(self):
"Testing /documents/view/<weblink_id>"
response = self.client.get(reverse('documents_weblink_view', args=[self.link.id]))
self.assertRedirects(response, reverse('user_login'))
def test_weblink_edit_out(self):
"Testing /documents/edit/<weblink_id>"
response = self.client.get(reverse('documents_weblink_edit', args=[self.link.id]))
self.assertRedirects(response, reverse('user_login'))
def test_weblink_delete_out(self):
"Testing /documents/delete/<weblink_id>"
response = self.client.get(reverse('documents_weblink_delete', args=[self.link.id]))
self.assertRedirects(response, reverse('user_login'))