forked from treeio/treeio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
382 lines (296 loc) · 16.3 KB
/
tests.py
File metadata and controls
382 lines (296 loc) · 16.3 KB
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
# encoding: utf-8
# Copyright 2011 Tree.io Limited
# This file is part of Treeio.
# License www.tree.io/license
"""
Identities: test suites
"""
from django.test import TestCase
from treeio.identities.models import Contact, ContactType, ContactField
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
class IdentitiesModelsTest(TestCase):
"Identities Model Tests"
def test_model_contacttype(self):
"Test ContactType model"
obj = ContactType(name='Test', slug='test')
obj.save()
self.assertEquals('Test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
def test_model_contact(self):
"Test Contact model"
type = ContactType(name='Test', slug='test')
type.save()
obj = Contact(name='Test', contact_type=type)
obj.save()
self.assertEquals('Test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
def test_model_field(self):
"Test Field model"
obj = ContactField(name='Test', label='test', field_type='text')
obj.save()
self.assertEquals('Test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
class IdentitiesViewsTest(TestCase):
"Identities View tests"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
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.contact_type = ContactType(name='Person')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='Test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.field = ContactField(name='Test', label='test', field_type='text')
self.field.set_default_user()
self.field.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 /contacts/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_index'))
self.assertEquals(response.status_code, 200)
def test_contact_users_login(self):
"Test page with login at /contacts/users/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_index_users'))
self.assertEquals(response.status_code, 200)
def test_contact_groups_login(self):
"Test page with login at /contacts/groups/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_index_groups'))
self.assertEquals(response.status_code, 200)
# Contact types
def test_contact_type_add(self):
"Test page with login at /contacts/types/add/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_type_add'))
self.assertEquals(response.status_code, 200)
def test_contact_type_view(self):
"Test page with login at /contacts/type/view/(?P<type_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_type_view', args=[self.contact_type.id]))
self.assertEquals(response.status_code, 200)
def test_contact_type_edit(self):
"Test page with login at /contacts/type/edit/(?P<type_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_type_edit', args=[self.contact_type.id]))
self.assertEquals(response.status_code, 200)
def test_contact_type_delete(self):
"Test page with login at /contacts/type/delete/(?P<type_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_type_delete', args=[self.contact_type.id]))
self.assertEquals(response.status_code, 200)
# Contact fields
def test_contact_field_add(self):
"Test page with login at /contacts/field/add"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_field_add'))
self.assertEquals(response.status_code, 200)
def test_contact_field_view(self):
"Test page with login at /contacts/field/view/(?P<field_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_field_view', args=[self.field.id]))
self.assertEquals(response.status_code, 200)
def test_contact_field_edit(self):
"Test page with login at /contacts/field/edit/(?P<field_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_field_edit', args=[self.field.id]))
self.assertEquals(response.status_code, 200)
def test_contact_field_delete(self):
"Test page with login at /contacts/field/delete/(?P<field_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_field_delete', args=[self.field.id]))
self.assertEquals(response.status_code, 200)
# Contacts
def test_contact_add(self):
"Test page with login at /contacts/contact/add/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_contact_add'))
self.assertEquals(response.status_code, 200)
def test_contact_add_by_type(self):
"Test page with login at /contacts/contact/add/<type_id>/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_contact_add_typed', args=[self.contact_type.id]))
self.assertEquals(response.status_code, 200)
def test_contact_me(self):
"Test page with login at /contacts/me/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_contact_me'))
self.assertEquals(response.status_code, 200)
def test_contact_view(self):
"Test page with login at /contacts/contact/view/<contact_id>/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_contact_view', args=[self.contact.id]))
self.assertEquals(response.status_code, 200)
def test_contact_edit(self):
"Test page with login at /contacts/contact/edit/<contact_id>/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_contact_edit', args=[self.contact.id]))
self.assertEquals(response.status_code, 200)
def test_contact_delete(self):
"Test page with login at /contacts/contact/delete/<contact_id>/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_contact_delete', args=[self.contact.id]))
self.assertEquals(response.status_code, 200)
# Settings
def test_contact_settings_view(self):
"Test index page with login at /contacts/settings/view/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_settings_view'))
self.assertEquals(response.status_code, 200)
# Integration
def test_contact_integration_index(self):
"Test index page with login at /contacts/integration/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_integration_index'))
self.assertEquals(response.status_code, 200)
######################################
# Testing views when user is not logged in
######################################
def test_index(self):
"Test index page at /contacts/"
response = self.client.get('/contacts/')
# Redirects as unauthenticated
self.assertRedirects(response, reverse('user_login'))
def test_contact_users_out(self):
"Testing /contacts/users/"
response = self.client.get(reverse('identities_index_users'))
self.assertRedirects(response, reverse('user_login'))
def test_contact_groups_out(self):
"Testing /contacts/groups/"
response = self.client.get(reverse('identities_index_groups'))
self.assertRedirects(response, reverse('user_login'))
# Contact types
def test_contact_type_add_out(self):
"Testing /contacts/types/add/"
response = self.client.get(reverse('identities_type_add'))
self.assertRedirects(response, reverse('user_login'))
def test_contact_type_view_out(self):
"Testing /contacts/type/view/(?P<type_id>\d+)"
response = self.client.get(reverse('identities_type_view', args=[self.contact_type.id]))
self.assertRedirects(response, reverse('user_login'))
def test_contact_type_edit_out(self):
"Testing /contacts/type/edit/(?P<type_id>\d+)"
response = self.client.get(reverse('identities_type_edit', args=[self.contact_type.id]))
self.assertRedirects(response, reverse('user_login'))
def test_contact_type_delete_out(self):
"Testing /contacts/type/delete/(?P<type_id>\d+)"
response = self.client.get(reverse('identities_type_delete', args=[self.contact_type.id]))
self.assertRedirects(response, reverse('user_login'))
# Contact fields
def test_contact_field_add_out(self):
"Testing /contacts/field/add"
response = self.client.get(reverse('identities_field_add'))
self.assertRedirects(response, reverse('user_login'))
def test_contact_field_view_out(self):
"Testing /contacts/field/view/(?P<field_id>\d+)"
response = self.client.get(reverse('identities_field_view', args=[self.field.id]))
self.assertRedirects(response, reverse('user_login'))
def test_contact_field_edit_out(self):
"Testing /contacts/field/edit/(?P<field_id>\d+)"
response = self.client.get(reverse('identities_field_edit', args=[self.field.id]))
self.assertRedirects(response, reverse('user_login'))
def test_contact_field_delete_out(self):
"Testing /contacts/field/delete/(?P<field_id>\d+)"
response = self.client.get(reverse('identities_field_delete', args=[self.field.id]))
self.assertRedirects(response, reverse('user_login'))
# Contacts
def test_contact_add_out(self):
"Testing /contacts/contact/add/"
response = self.client.get(reverse('identities_contact_add'))
self.assertRedirects(response, reverse('user_login'))
def test_contact_add_by_type_out(self):
"Testing /contacts/contact/add/<type_id>/"
response = self.client.get(reverse('identities_contact_add_typed', args=[self.contact_type.id]))
self.assertRedirects(response, reverse('user_login'))
def test_contact_me_out(self):
"Testing /contacts/me/"
response = self.client.get(reverse('identities_contact_me'))
self.assertRedirects(response, reverse('user_login'))
def test_contact_view_out(self):
"Testing /contacts/contact/view/<contact_id>/"
response = self.client.get(reverse('identities_contact_view', args=[self.contact.id]))
self.assertRedirects(response, reverse('user_login'))
def test_contact_edit_out(self):
"Testing /contacts/contact/edit/<contact_id>/"
response = self.client.get(reverse('identities_contact_edit', args=[self.contact.id]))
self.assertRedirects(response, reverse('user_login'))
def test_contact_delete_out(self):
"Testing /contacts/contact/delete/<contact_id>/"
response = self.client.get(reverse('identities_contact_delete', args=[self.contact.id]))
self.assertRedirects(response, reverse('user_login'))
# Settings
def test_contact_settings_view_out(self):
"Testing /contacts/settings/view/"
response = self.client.get(reverse('identities_settings_view'))
self.assertRedirects(response, reverse('user_login'))
# Integration
def test_contact_integration_index_out(self):
"Testing /contacts/integration/"
response = self.client.get(reverse('identities_integration_index'))
self.assertRedirects(response, reverse('user_login'))