Parent: [3c3cc5] (diff)

Child: [1aa42d] (diff)

Download this file

test_admin.py    317 lines (292 with data), 13.5 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
import os, allura
import Image, StringIO
from nose.tools import assert_equals, assert_true
from pylons import g, c
from ming.orm.ormsession import ThreadLocalORMSession
try:
import sfx
except ImportError:
sfx = None
from allura.tests import TestController
from allura import model as M
from allura.lib import helpers as h
class TestProjectAdmin(TestController):
def test_admin_controller(self):
self.app.get('/admin/')
self.app.post('/admin/update', params=dict(
name='Test Project',
shortname='test',
short_description=u'\u00bf A Test Project ?'.encode('utf-8'),
description=u'''\u00bf
A long description ?'''.encode('utf-8'),
labels='aaa,bbb'))
r = self.app.get('/admin/overview')
assert 'A Test Project ?' in r
assert 'Test Subproject' not in r
r = self.app.get('/home/')
assert 'A long description ?' in r
# Add a subproject
self.app.post('/admin/update_mounts', params={
'new.install':'install',
'new.ep_name':'',
'new.ordinal':1,
'new.mount_point':'test-subproject',
'new.mount_label':'Test Subproject'})
r = self.app.get('/admin/overview')
assert 'Test Subproject' in r
# Rename a subproject
self.app.post('/admin/update_mounts', params={
'subproject-0.shortname':'test/test-subproject',
'subproject-0.name':'Tst Sbprj',
'subproject-0.ordinal':100,
})
r = self.app.get('/admin/overview')
assert 'Tst Sbprj' in r
# Remove a subproject
self.app.post('/admin/update_mounts', params={
'subproject-0.delete':'on',
'subproject-0.shortname':'test/test-subproject',
'new.ep_name':'',
})
# Add a tool
r = self.app.post('/admin/update_mounts', params={
'new.install':'install',
'new.ep_name':'Wiki',
'new.ordinal':1,
'new.mount_point':'test-tool',
'new.mount_label':'Test Tool'})
assert 'error' not in self.webflash(r)
# check tool in the nav
r = self.app.get('/p/test/test-tool/').follow()
active_link = r.html.findAll('span',{'class':'diamond'})
assert len(active_link) == 1
assert active_link[0].parent['href'] == '/p/test/test-tool/'
r = self.app.post('/admin/update_mounts', params={
'new.install':'install',
'new.ep_name':'Wiki',
'new.ordinal':1,
'new.mount_point':'test-tool2',
'new.mount_label':'Test Tool2'})
assert 'error' not in self.webflash(r)
# check the nav - the similarly named tool should NOT be active
r = self.app.get('/p/test/test-tool/Home/')
active_link = r.html.findAll('span',{'class':'diamond'})
assert len(active_link) == 1
assert active_link[0].parent['href'] == '/p/test/test-tool/'
r = self.app.get('/p/test/test-tool2/Home/')
active_link = r.html.findAll('span',{'class':'diamond'})
assert len(active_link) == 1
assert active_link[0].parent['href'] == '/p/test/test-tool2/'
# check can't create dup tool
r = self.app.post('/admin/update_mounts', params={
'new.install':'install',
'new.ep_name':'Wiki',
'new.ordinal':1,
'new.mount_point':'test-tool',
'new.mount_label':'Test Tool'})
assert 'error' in self.webflash(r)
# Rename a tool
self.app.post('/admin/update_mounts', params={
'tool-0.mount_point':'test-tool',
'tool-0.mount_label':'Tst Tuul',
'tool-0.ordinal':200,
})
r = self.app.get('/admin/overview')
assert 'Tst Tuul' in r
# Remove a tool
self.app.post('/admin/update_mounts', params={
'tool-0.delete':'on',
'tool-0.mount_point':'test-tool',
'new.ep_name':'',
})
# Update ACL
h.set_context('test', 'wiki')
role = M.User.anonymous().project_role()
self.app.post('/admin/update_acl', params={
'permission':'tool',
'new.add':'on',
'new.id':str(role._id)})
self.app.post('/admin/update_acl', params={
'new.id':'',
'permission':'tool',
'role-0.delete':'on',
'role-0.id':str(role._id)})
self.app.post('/admin/update_acl', params={
'permission':'tool',
'new.add':'on',
'new.id':'',
'new.username':'test-user'})
self.app.post('/admin/update_acl', params={
'permission':'tool',
'new.add':'on',
'new.id':'',
'new.username':'no_such_user'})
# Update project roles
self.app.post('/admin/update_roles', params={
'new.add':'on',
'new.name':'test_role'})
role1 = M.ProjectRole.by_name('test_role')
self.app.post('/admin/update_roles', params={
'role-0.id':str(role1._id),
'role-0.new.add':'on',
'role-0.new.id':str(role._id),
'new.name':''})
self.app.post('/admin/update_roles', params={
'role-0.id':str(role1._id),
'role-0.new.id':'',
'role-0.subroles-0.delete':'on',
'role-0.subroles-0.id':str(role._id),
'new.name':''})
self.app.post('/admin/update_roles', params={
'role-0.id':str(role1._id),
'role-0.new.id':'',
'role-0.delete':'on',
'new.name':''})
# Create a role when there are no existing roles
self.app.post('/admin/update_roles', params={
'new.add':'on',
'new.name':'test_role',
'role-0.id':str(role1._id)})
def test_tool_list(self):
r = self.app.get('/admin/tools')
new_ep_opts = r.html.findAll('a',{'class':"install_trig"})
strings = [ ' '.join(opt.find('span').string.strip().split()) for opt in new_ep_opts ]
expected_tools = [
'External Link',
'Git',
'Mercurial',
'SVN',
'Wiki',
'Tickets',
'Discussion',
'Downloads' ]
if sfx:
expected_tools += [
'Mailing List (alpha)',
'VHOST (alpha)',
'MySQL Databases (alpha)',
'Project Web Outgoing Email (alpha)',
'Classic Hosted Apps (alpha)' ]
expected_tools += [
'Chat (alpha)',
'Blog (alpha)',
'Subproject']
assert strings == expected_tools
def test_project_icon(self):
file_name = 'neo-icon-set-454545-256x350.png'
file_path = os.path.join(allura.__path__[0],'public','nf','allura','images',file_name)
file_data = file(file_path).read()
upload = ('icon', file_name, file_data)
self.app.get('/admin/')
self.app.post('/admin/update', params=dict(
name='Test Project',
shortname='test',
short_description='A Test Project',
description='A long description'),
upload_files=[upload])
r = self.app.get('/p/test/icon')
image = Image.open(StringIO.StringIO(r.body))
assert image.size == (48,48)
def test_project_screenshot(self):
file_name = 'neo-icon-set-454545-256x350.png'
file_path = os.path.join(allura.__path__[0],'public','nf','allura','images',file_name)
file_data = file(file_path).read()
upload = ('screenshot', file_name, file_data)
self.app.get('/admin/')
self.app.post('/admin/update', params=dict(
name='Test Project',
shortname='test',
short_description='A Test Project',
description='A long description'),
upload_files=[upload])
project = M.Project.query.find({'shortname':'test'}).first()
filename = project.get_screenshots()[0].filename
r = self.app.get('/p/test/screenshot/'+filename)
uploaded = Image.open(file_path)
screenshot = Image.open(StringIO.StringIO(r.body))
assert uploaded.size == screenshot.size
r = self.app.get('/p/test/screenshot/'+filename+'/thumb')
thumb = Image.open(StringIO.StringIO(r.body))
assert thumb.size == (150,150)
def test_project_delete_undelete(self):
r = self.app.get('/p/test/admin/overview')
assert 'This project has been deleted and is not visible to non-admin users' not in r
assert r.html.find('input',{'value':'Delete Project'})
assert not r.html.find('input',{'value':'Undelete Project'})
self.app.post('/admin/update', params=dict(
name='Test Project',
shortname='test',
short_description='A Test Project',
description='A long description',
delete='on'))
r = self.app.get('/p/test/admin/overview')
assert 'This project has been deleted and is not visible to non-admin users' in r
assert not r.html.find('input',{'value':'Delete Project'})
assert r.html.find('input',{'value':'Undelete Project'})
self.app.post('/admin/update', params=dict(
name='Test Project',
shortname='test',
short_description='A Test Project',
description='A long description',
undelete='on'))
r = self.app.get('/p/test/admin/overview')
assert 'This project has been deleted and is not visible to non-admin users' not in r
assert r.html.find('input',{'value':'Delete Project'})
assert not r.html.find('input',{'value':'Undelete Project'})
def test_project_homepage(self):
r = self.app.get('/admin/homepage')
assert 'Awesome description' not in r
self.app.post('/admin/update_homepage', {'description': 'Awesome description'})
r = self.app.get('/admin/homepage')
assert 'Awesome description' in r
r = self.app.get('/p/test/home/')
assert 'Awesome description' in r, r
def test_project_permissions(self):
r = self.app.get('/admin/permissions/')
assert len(r.html.findAll('input', {'name': 'card-0.value'})) == 1
select = r.html.find('select', {'name': 'card-0.new'})
opt_admin = select.find(text='Admin').parent
opt_developer = select.find(text='Developer').parent
assert opt_admin.name == 'option'
assert opt_developer.name == 'option'
r = self.app.post('/admin/permissions/update', params={
'card-0.new': opt_developer['value'],
'card-0.value': opt_admin['value'],
'card-0.id': 'create'})
r = self.app.get('/admin/permissions/')
assigned_ids = [t['value'] for t in r.html.findAll('input', {'name': 'card-0.value'})]
assert len(assigned_ids) == 2
assert opt_developer['value'] in assigned_ids
assert opt_admin['value'] in assigned_ids
def test_project_groups(self):
r = self.app.get('/admin/groups/')
developer_id = r.html.find('input', {'name': 'card-1.id'})['value']
r = self.app.post('/admin/groups/update', params={
'card-1.id': developer_id,
'card-1.new': 'test-user'})
r = self.app.get('/admin/groups/')
users = [t.previous.strip() for t in r.html.findAll('input', {'name': 'card-1.value'})]
assert 'test-user' in users
# Make sure we can open role page for builtin role
r = self.app.get('/admin/groups/' + developer_id + '/', validate_chunk=True)
def test_new_group(self):
r = self.app.get('/admin/groups/new', validate_chunk=True)
r = self.app.post('/admin/groups/create', params={'name': 'Developer'})
assert 'error' in self.webflash(r)
r = self.app.post('/admin/groups/create', params={'name': 'RoleNew1'})
r = self.app.get('/admin/groups/')
assert 'RoleNew1' in r
role_id = r.html.find(text='RoleNew1').findPrevious('input', {'type': 'hidden'})['value']
r = self.app.get('/admin/groups/' + role_id + '/', validate_chunk=True)
r = self.app.post('/admin/groups/' + str(role_id) + '/update', params={'_id': role_id, 'name': 'Developer'})
assert 'error' in self.webflash(r)
assert 'already exists' in self.webflash(r)
r = self.app.post('/admin/groups/' + str(role_id) + '/update', params={'_id': role_id, 'name': 'rleNew2'}).follow()
assert 'RoleNew1' not in r
assert 'rleNew2' in r
r = self.app.post('/admin/groups/' + str(role_id) + '/update', params={'_id': role_id, 'name': 'rleNew2', 'delete': 'delete'})
assert 'deleted' in self.webflash(r)
r = self.app.get('/admin/groups/')
roles = [t.string for t in r.html.findAll('h3')]
assert 'RoleNew1' not in roles
assert 'rleNew2' not in roles