##// END OF EJS Templates
fixed test from failing under different conditions
marcink -
r2741:a89d375c beta
parent child Browse files
Show More
@@ -1,224 +1,224
1 from rhodecode.tests import *
1 from rhodecode.tests import *
2 from rhodecode.model.db import UsersGroup, UsersGroupToPerm, Permission
2 from rhodecode.model.db import UsersGroup, UsersGroupToPerm, Permission
3
3
4 TEST_USERS_GROUP = 'admins_test'
4 TEST_USERS_GROUP = 'admins_test'
5
5
6
6
7 class TestAdminUsersGroupsController(TestController):
7 class TestAdminUsersGroupsController(TestController):
8
8
9 def test_index(self):
9 def test_index(self):
10 response = self.app.get(url('users_groups'))
10 response = self.app.get(url('users_groups'))
11 # Test response...
11 # Test response...
12
12
13 def test_index_as_xml(self):
13 def test_index_as_xml(self):
14 response = self.app.get(url('formatted_users_groups', format='xml'))
14 response = self.app.get(url('formatted_users_groups', format='xml'))
15
15
16 def test_create(self):
16 def test_create(self):
17 self.log_user()
17 self.log_user()
18 users_group_name = TEST_USERS_GROUP
18 users_group_name = TEST_USERS_GROUP
19 response = self.app.post(url('users_groups'),
19 response = self.app.post(url('users_groups'),
20 {'users_group_name': users_group_name,
20 {'users_group_name': users_group_name,
21 'active':True})
21 'active':True})
22 response.follow()
22 response.follow()
23
23
24 self.checkSessionFlash(response,
24 self.checkSessionFlash(response,
25 'created users group %s' % TEST_USERS_GROUP)
25 'created users group %s' % TEST_USERS_GROUP)
26
26
27 def test_new(self):
27 def test_new(self):
28 response = self.app.get(url('new_users_group'))
28 response = self.app.get(url('new_users_group'))
29
29
30 def test_new_as_xml(self):
30 def test_new_as_xml(self):
31 response = self.app.get(url('formatted_new_users_group', format='xml'))
31 response = self.app.get(url('formatted_new_users_group', format='xml'))
32
32
33 def test_update(self):
33 def test_update(self):
34 response = self.app.put(url('users_group', id=1))
34 response = self.app.put(url('users_group', id=1))
35
35
36 def test_update_browser_fakeout(self):
36 def test_update_browser_fakeout(self):
37 response = self.app.post(url('users_group', id=1),
37 response = self.app.post(url('users_group', id=1),
38 params=dict(_method='put'))
38 params=dict(_method='put'))
39
39
40 def test_delete(self):
40 def test_delete(self):
41 self.log_user()
41 self.log_user()
42 users_group_name = TEST_USERS_GROUP + 'another'
42 users_group_name = TEST_USERS_GROUP + 'another'
43 response = self.app.post(url('users_groups'),
43 response = self.app.post(url('users_groups'),
44 {'users_group_name':users_group_name,
44 {'users_group_name':users_group_name,
45 'active':True})
45 'active':True})
46 response.follow()
46 response.follow()
47
47
48 self.checkSessionFlash(response,
48 self.checkSessionFlash(response,
49 'created users group %s' % users_group_name)
49 'created users group %s' % users_group_name)
50
50
51 gr = self.Session.query(UsersGroup)\
51 gr = self.Session.query(UsersGroup)\
52 .filter(UsersGroup.users_group_name ==
52 .filter(UsersGroup.users_group_name ==
53 users_group_name).one()
53 users_group_name).one()
54
54
55 response = self.app.delete(url('users_group', id=gr.users_group_id))
55 response = self.app.delete(url('users_group', id=gr.users_group_id))
56
56
57 gr = self.Session.query(UsersGroup)\
57 gr = self.Session.query(UsersGroup)\
58 .filter(UsersGroup.users_group_name ==
58 .filter(UsersGroup.users_group_name ==
59 users_group_name).scalar()
59 users_group_name).scalar()
60
60
61 self.assertEqual(gr, None)
61 self.assertEqual(gr, None)
62
62
63 def test_enable_repository_read_on_group(self):
63 def test_enable_repository_read_on_group(self):
64 self.log_user()
64 self.log_user()
65 users_group_name = TEST_USERS_GROUP + 'another2'
65 users_group_name = TEST_USERS_GROUP + 'another2'
66 response = self.app.post(url('users_groups'),
66 response = self.app.post(url('users_groups'),
67 {'users_group_name': users_group_name,
67 {'users_group_name': users_group_name,
68 'active': True})
68 'active': True})
69 response.follow()
69 response.follow()
70
70
71 ug = UsersGroup.get_by_group_name(users_group_name)
71 ug = UsersGroup.get_by_group_name(users_group_name)
72 self.checkSessionFlash(response,
72 self.checkSessionFlash(response,
73 'created users group %s' % users_group_name)
73 'created users group %s' % users_group_name)
74 ## ENABLE REPO CREATE ON A GROUP
74 ## ENABLE REPO CREATE ON A GROUP
75 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
75 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
76 {'create_repo_perm': True})
76 {'create_repo_perm': True})
77
77
78 response.follow()
78 response.follow()
79 ug = UsersGroup.get_by_group_name(users_group_name)
79 ug = UsersGroup.get_by_group_name(users_group_name)
80 p = Permission.get_by_key('hg.create.repository')
80 p = Permission.get_by_key('hg.create.repository')
81 p2 = Permission.get_by_key('hg.fork.none')
81 p2 = Permission.get_by_key('hg.fork.none')
82 # check if user has this perms, they should be here since
82 # check if user has this perms, they should be here since
83 # defaults are on
83 # defaults are on
84 perms = UsersGroupToPerm.query()\
84 perms = UsersGroupToPerm.query()\
85 .filter(UsersGroupToPerm.users_group == ug).all()
85 .filter(UsersGroupToPerm.users_group == ug).all()
86
86
87 self.assertEqual(
87 self.assertEqual(
88 [[x.users_group_id, x.permission_id, ] for x in perms],
88 [[x.users_group_id, x.permission_id, ] for x in perms],
89 [[ug.users_group_id, p.permission_id],
89 [[ug.users_group_id, p.permission_id],
90 [ug.users_group_id, p2.permission_id]]
90 [ug.users_group_id, p2.permission_id]]
91 )
91 )
92
92
93 ## DISABLE REPO CREATE ON A GROUP
93 ## DISABLE REPO CREATE ON A GROUP
94 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
94 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
95 {})
95 {})
96
96
97 response.follow()
97 response.follow()
98 ug = UsersGroup.get_by_group_name(users_group_name)
98 ug = UsersGroup.get_by_group_name(users_group_name)
99 p = Permission.get_by_key('hg.create.none')
99 p = Permission.get_by_key('hg.create.none')
100 p2 = Permission.get_by_key('hg.fork.none')
100 p2 = Permission.get_by_key('hg.fork.none')
101 # check if user has this perms, they should be here since
101 # check if user has this perms, they should be here since
102 # defaults are on
102 # defaults are on
103 perms = UsersGroupToPerm.query()\
103 perms = UsersGroupToPerm.query()\
104 .filter(UsersGroupToPerm.users_group == ug).all()
104 .filter(UsersGroupToPerm.users_group == ug).all()
105
105
106 self.assertEqual(
106 self.assertEqual(
107 [[x.users_group_id, x.permission_id, ] for x in perms],
107 sorted([[x.users_group_id, x.permission_id, ] for x in perms]),
108 [[ug.users_group_id, p.permission_id],
108 sorted([[ug.users_group_id, p.permission_id],
109 [ug.users_group_id, p2.permission_id]]
109 [ug.users_group_id, p2.permission_id]])
110 )
110 )
111
111
112 # DELETE !
112 # DELETE !
113 ug = UsersGroup.get_by_group_name(users_group_name)
113 ug = UsersGroup.get_by_group_name(users_group_name)
114 ugid = ug.users_group_id
114 ugid = ug.users_group_id
115 response = self.app.delete(url('users_group', id=ug.users_group_id))
115 response = self.app.delete(url('users_group', id=ug.users_group_id))
116 response = response.follow()
116 response = response.follow()
117 gr = self.Session.query(UsersGroup)\
117 gr = self.Session.query(UsersGroup)\
118 .filter(UsersGroup.users_group_name ==
118 .filter(UsersGroup.users_group_name ==
119 users_group_name).scalar()
119 users_group_name).scalar()
120
120
121 self.assertEqual(gr, None)
121 self.assertEqual(gr, None)
122 p = Permission.get_by_key('hg.create.repository')
122 p = Permission.get_by_key('hg.create.repository')
123 perms = UsersGroupToPerm.query()\
123 perms = UsersGroupToPerm.query()\
124 .filter(UsersGroupToPerm.users_group_id == ugid).all()
124 .filter(UsersGroupToPerm.users_group_id == ugid).all()
125 perms = [[x.users_group_id,
125 perms = [[x.users_group_id,
126 x.permission_id, ] for x in perms]
126 x.permission_id, ] for x in perms]
127 self.assertEqual(
127 self.assertEqual(
128 perms,
128 perms,
129 []
129 []
130 )
130 )
131
131
132 def test_enable_repository_fork_on_group(self):
132 def test_enable_repository_fork_on_group(self):
133 self.log_user()
133 self.log_user()
134 users_group_name = TEST_USERS_GROUP + 'another2'
134 users_group_name = TEST_USERS_GROUP + 'another2'
135 response = self.app.post(url('users_groups'),
135 response = self.app.post(url('users_groups'),
136 {'users_group_name': users_group_name,
136 {'users_group_name': users_group_name,
137 'active': True})
137 'active': True})
138 response.follow()
138 response.follow()
139
139
140 ug = UsersGroup.get_by_group_name(users_group_name)
140 ug = UsersGroup.get_by_group_name(users_group_name)
141 self.checkSessionFlash(response,
141 self.checkSessionFlash(response,
142 'created users group %s' % users_group_name)
142 'created users group %s' % users_group_name)
143 ## ENABLE REPO CREATE ON A GROUP
143 ## ENABLE REPO CREATE ON A GROUP
144 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
144 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
145 {'fork_repo_perm': True})
145 {'fork_repo_perm': True})
146
146
147 response.follow()
147 response.follow()
148 ug = UsersGroup.get_by_group_name(users_group_name)
148 ug = UsersGroup.get_by_group_name(users_group_name)
149 p = Permission.get_by_key('hg.create.none')
149 p = Permission.get_by_key('hg.create.none')
150 p2 = Permission.get_by_key('hg.fork.repository')
150 p2 = Permission.get_by_key('hg.fork.repository')
151 # check if user has this perms, they should be here since
151 # check if user has this perms, they should be here since
152 # defaults are on
152 # defaults are on
153 perms = UsersGroupToPerm.query()\
153 perms = UsersGroupToPerm.query()\
154 .filter(UsersGroupToPerm.users_group == ug).all()
154 .filter(UsersGroupToPerm.users_group == ug).all()
155
155
156 self.assertEqual(
156 self.assertEqual(
157 [[x.users_group_id, x.permission_id, ] for x in perms],
157 [[x.users_group_id, x.permission_id, ] for x in perms],
158 [[ug.users_group_id, p.permission_id],
158 [[ug.users_group_id, p.permission_id],
159 [ug.users_group_id, p2.permission_id]]
159 [ug.users_group_id, p2.permission_id]]
160 )
160 )
161
161
162 ## DISABLE REPO CREATE ON A GROUP
162 ## DISABLE REPO CREATE ON A GROUP
163 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
163 response = self.app.put(url('users_group_perm', id=ug.users_group_id),
164 {})
164 {})
165
165
166 response.follow()
166 response.follow()
167 ug = UsersGroup.get_by_group_name(users_group_name)
167 ug = UsersGroup.get_by_group_name(users_group_name)
168 p = Permission.get_by_key('hg.create.none')
168 p = Permission.get_by_key('hg.create.none')
169 p2 = Permission.get_by_key('hg.fork.none')
169 p2 = Permission.get_by_key('hg.fork.none')
170 # check if user has this perms, they should be here since
170 # check if user has this perms, they should be here since
171 # defaults are on
171 # defaults are on
172 perms = UsersGroupToPerm.query()\
172 perms = UsersGroupToPerm.query()\
173 .filter(UsersGroupToPerm.users_group == ug).all()
173 .filter(UsersGroupToPerm.users_group == ug).all()
174
174
175 self.assertEqual(
175 self.assertEqual(
176 [[x.users_group_id, x.permission_id, ] for x in perms],
176 [[x.users_group_id, x.permission_id, ] for x in perms],
177 [[ug.users_group_id, p.permission_id],
177 [[ug.users_group_id, p.permission_id],
178 [ug.users_group_id, p2.permission_id]]
178 [ug.users_group_id, p2.permission_id]]
179 )
179 )
180
180
181 # DELETE !
181 # DELETE !
182 ug = UsersGroup.get_by_group_name(users_group_name)
182 ug = UsersGroup.get_by_group_name(users_group_name)
183 ugid = ug.users_group_id
183 ugid = ug.users_group_id
184 response = self.app.delete(url('users_group', id=ug.users_group_id))
184 response = self.app.delete(url('users_group', id=ug.users_group_id))
185 response = response.follow()
185 response = response.follow()
186 gr = self.Session.query(UsersGroup)\
186 gr = self.Session.query(UsersGroup)\
187 .filter(UsersGroup.users_group_name ==
187 .filter(UsersGroup.users_group_name ==
188 users_group_name).scalar()
188 users_group_name).scalar()
189
189
190 self.assertEqual(gr, None)
190 self.assertEqual(gr, None)
191 p = Permission.get_by_key('hg.fork.repository')
191 p = Permission.get_by_key('hg.fork.repository')
192 perms = UsersGroupToPerm.query()\
192 perms = UsersGroupToPerm.query()\
193 .filter(UsersGroupToPerm.users_group_id == ugid).all()
193 .filter(UsersGroupToPerm.users_group_id == ugid).all()
194 perms = [[x.users_group_id,
194 perms = [[x.users_group_id,
195 x.permission_id, ] for x in perms]
195 x.permission_id, ] for x in perms]
196 self.assertEqual(
196 self.assertEqual(
197 perms,
197 perms,
198 []
198 []
199 )
199 )
200
200
201 def test_delete_browser_fakeout(self):
201 def test_delete_browser_fakeout(self):
202 response = self.app.post(url('users_group', id=1),
202 response = self.app.post(url('users_group', id=1),
203 params=dict(_method='delete'))
203 params=dict(_method='delete'))
204
204
205 def test_show(self):
205 def test_show(self):
206 response = self.app.get(url('users_group', id=1))
206 response = self.app.get(url('users_group', id=1))
207
207
208 def test_show_as_xml(self):
208 def test_show_as_xml(self):
209 response = self.app.get(url('formatted_users_group', id=1, format='xml'))
209 response = self.app.get(url('formatted_users_group', id=1, format='xml'))
210
210
211 def test_edit(self):
211 def test_edit(self):
212 response = self.app.get(url('edit_users_group', id=1))
212 response = self.app.get(url('edit_users_group', id=1))
213
213
214 def test_edit_as_xml(self):
214 def test_edit_as_xml(self):
215 response = self.app.get(url('formatted_edit_users_group', id=1, format='xml'))
215 response = self.app.get(url('formatted_edit_users_group', id=1, format='xml'))
216
216
217 def test_assign_members(self):
217 def test_assign_members(self):
218 pass
218 pass
219
219
220 def test_add_create_permission(self):
220 def test_add_create_permission(self):
221 pass
221 pass
222
222
223 def test_revoke_members(self):
223 def test_revoke_members(self):
224 pass
224 pass
General Comments 0
You need to be logged in to leave comments. Login now