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