Show More
@@ -1,224 +1,233 b'' | |||||
1 | from rhodecode.tests import * |
|
1 | from rhodecode.tests import * | |
2 | from rhodecode.model.db import UserGroup, UserGroupToPerm, Permission |
|
2 | from rhodecode.model.db import UserGroup, UserGroupToPerm, Permission | |
3 |
|
3 | |||
4 | TEST_USER_GROUP = 'admins_test' |
|
4 | TEST_USER_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_USER_GROUP |
|
18 | users_group_name = TEST_USER_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 user group %s' % TEST_USER_GROUP) |
|
25 | 'Created user group %s' % TEST_USER_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_USER_GROUP + 'another' |
|
42 | users_group_name = TEST_USER_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 user group %s' % users_group_name) |
|
49 | 'Created user group %s' % users_group_name) | |
50 |
|
50 | |||
51 | gr = self.Session.query(UserGroup)\ |
|
51 | gr = self.Session.query(UserGroup)\ | |
52 | .filter(UserGroup.users_group_name == |
|
52 | .filter(UserGroup.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(UserGroup)\ |
|
57 | gr = self.Session.query(UserGroup)\ | |
58 | .filter(UserGroup.users_group_name == |
|
58 | .filter(UserGroup.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_USER_GROUP + 'another2' |
|
65 | users_group_name = TEST_USER_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 = UserGroup.get_by_group_name(users_group_name) |
|
71 | ug = UserGroup.get_by_group_name(users_group_name) | |
72 | self.checkSessionFlash(response, |
|
72 | self.checkSessionFlash(response, | |
73 | 'Created user group %s' % users_group_name) |
|
73 | 'Created user 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 = UserGroup.get_by_group_name(users_group_name) |
|
79 | ug = UserGroup.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. |
|
81 | p2 = Permission.get_by_key('hg.usergroup.create.false') | |
|
82 | p3 = Permission.get_by_key('hg.fork.none') | |||
82 | # check if user has this perms, they should be here since |
|
83 | # check if user has this perms, they should be here since | |
83 | # defaults are on |
|
84 | # defaults are on | |
84 | perms = UserGroupToPerm.query()\ |
|
85 | perms = UserGroupToPerm.query()\ | |
85 | .filter(UserGroupToPerm.users_group == ug).all() |
|
86 | .filter(UserGroupToPerm.users_group == ug).all() | |
86 |
|
87 | |||
87 | self.assertEqual( |
|
88 | self.assertEqual( | |
88 | [[x.users_group_id, x.permission_id, ] for x in perms], |
|
89 | sorted([[x.users_group_id, x.permission_id, ] for x in perms]), | |
89 | [[ug.users_group_id, p.permission_id], |
|
90 | sorted([[ug.users_group_id, p.permission_id], | |
90 |
[ug.users_group_id, p2.permission_id] |
|
91 | [ug.users_group_id, p2.permission_id], | |
|
92 | [ug.users_group_id, p3.permission_id]]) | |||
91 | ) |
|
93 | ) | |
92 |
|
94 | |||
93 | ## DISABLE REPO CREATE ON A GROUP |
|
95 | ## DISABLE REPO CREATE ON A GROUP | |
94 | response = self.app.put(url('users_group_perm', id=ug.users_group_id), |
|
96 | response = self.app.put(url('users_group_perm', id=ug.users_group_id), | |
95 | {}) |
|
97 | {}) | |
96 |
|
98 | |||
97 | response.follow() |
|
99 | response.follow() | |
98 | ug = UserGroup.get_by_group_name(users_group_name) |
|
100 | ug = UserGroup.get_by_group_name(users_group_name) | |
99 | p = Permission.get_by_key('hg.create.none') |
|
101 | p = Permission.get_by_key('hg.create.none') | |
100 |
p2 = Permission.get_by_key('hg. |
|
102 | p2 = Permission.get_by_key('hg.usergroup.create.false') | |
|
103 | p3 = Permission.get_by_key('hg.fork.none') | |||
|
104 | ||||
101 | # check if user has this perms, they should be here since |
|
105 | # check if user has this perms, they should be here since | |
102 | # defaults are on |
|
106 | # defaults are on | |
103 | perms = UserGroupToPerm.query()\ |
|
107 | perms = UserGroupToPerm.query()\ | |
104 | .filter(UserGroupToPerm.users_group == ug).all() |
|
108 | .filter(UserGroupToPerm.users_group == ug).all() | |
105 |
|
109 | |||
106 | self.assertEqual( |
|
110 | self.assertEqual( | |
107 | sorted([[x.users_group_id, x.permission_id, ] for x in perms]), |
|
111 | sorted([[x.users_group_id, x.permission_id, ] for x in perms]), | |
108 | sorted([[ug.users_group_id, p.permission_id], |
|
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 | # DELETE ! |
|
117 | # DELETE ! | |
113 | ug = UserGroup.get_by_group_name(users_group_name) |
|
118 | ug = UserGroup.get_by_group_name(users_group_name) | |
114 | ugid = ug.users_group_id |
|
119 | ugid = ug.users_group_id | |
115 | response = self.app.delete(url('users_group', id=ug.users_group_id)) |
|
120 | response = self.app.delete(url('users_group', id=ug.users_group_id)) | |
116 | response = response.follow() |
|
121 | response = response.follow() | |
117 | gr = self.Session.query(UserGroup)\ |
|
122 | gr = self.Session.query(UserGroup)\ | |
118 | .filter(UserGroup.users_group_name == |
|
123 | .filter(UserGroup.users_group_name == | |
119 | users_group_name).scalar() |
|
124 | users_group_name).scalar() | |
120 |
|
125 | |||
121 | self.assertEqual(gr, None) |
|
126 | self.assertEqual(gr, None) | |
122 | p = Permission.get_by_key('hg.create.repository') |
|
127 | p = Permission.get_by_key('hg.create.repository') | |
123 | perms = UserGroupToPerm.query()\ |
|
128 | perms = UserGroupToPerm.query()\ | |
124 | .filter(UserGroupToPerm.users_group_id == ugid).all() |
|
129 | .filter(UserGroupToPerm.users_group_id == ugid).all() | |
125 | perms = [[x.users_group_id, |
|
130 | perms = [[x.users_group_id, | |
126 | x.permission_id, ] for x in perms] |
|
131 | x.permission_id, ] for x in perms] | |
127 | self.assertEqual( |
|
132 | self.assertEqual( | |
128 | perms, |
|
133 | perms, | |
129 | [] |
|
134 | [] | |
130 | ) |
|
135 | ) | |
131 |
|
136 | |||
132 | def test_enable_repository_fork_on_group(self): |
|
137 | def test_enable_repository_fork_on_group(self): | |
133 | self.log_user() |
|
138 | self.log_user() | |
134 | users_group_name = TEST_USER_GROUP + 'another2' |
|
139 | users_group_name = TEST_USER_GROUP + 'another2' | |
135 | response = self.app.post(url('users_groups'), |
|
140 | response = self.app.post(url('users_groups'), | |
136 | {'users_group_name': users_group_name, |
|
141 | {'users_group_name': users_group_name, | |
137 | 'active': True}) |
|
142 | 'active': True}) | |
138 | response.follow() |
|
143 | response.follow() | |
139 |
|
144 | |||
140 | ug = UserGroup.get_by_group_name(users_group_name) |
|
145 | ug = UserGroup.get_by_group_name(users_group_name) | |
141 | self.checkSessionFlash(response, |
|
146 | self.checkSessionFlash(response, | |
142 | 'Created user group %s' % users_group_name) |
|
147 | 'Created user group %s' % users_group_name) | |
143 | ## ENABLE REPO CREATE ON A GROUP |
|
148 | ## ENABLE REPO CREATE ON A GROUP | |
144 | response = self.app.put(url('users_group_perm', id=ug.users_group_id), |
|
149 | response = self.app.put(url('users_group_perm', id=ug.users_group_id), | |
145 | {'fork_repo_perm': True}) |
|
150 | {'fork_repo_perm': True}) | |
146 |
|
151 | |||
147 | response.follow() |
|
152 | response.follow() | |
148 | ug = UserGroup.get_by_group_name(users_group_name) |
|
153 | ug = UserGroup.get_by_group_name(users_group_name) | |
149 | p = Permission.get_by_key('hg.create.none') |
|
154 | p = Permission.get_by_key('hg.create.none') | |
150 |
p2 = Permission.get_by_key('hg. |
|
155 | p2 = Permission.get_by_key('hg.usergroup.create.false') | |
|
156 | p3 = Permission.get_by_key('hg.fork.repository') | |||
151 | # check if user has this perms, they should be here since |
|
157 | # check if user has this perms, they should be here since | |
152 | # defaults are on |
|
158 | # defaults are on | |
153 | perms = UserGroupToPerm.query()\ |
|
159 | perms = UserGroupToPerm.query()\ | |
154 | .filter(UserGroupToPerm.users_group == ug).all() |
|
160 | .filter(UserGroupToPerm.users_group == ug).all() | |
155 |
|
161 | |||
156 | self.assertEqual( |
|
162 | self.assertEqual( | |
157 | [[x.users_group_id, x.permission_id, ] for x in perms], |
|
163 | sorted([[x.users_group_id, x.permission_id, ] for x in perms]), | |
158 | [[ug.users_group_id, p.permission_id], |
|
164 | sorted([[ug.users_group_id, p.permission_id], | |
159 |
[ug.users_group_id, p2.permission_id] |
|
165 | [ug.users_group_id, p2.permission_id], | |
|
166 | [ug.users_group_id, p3.permission_id]]) | |||
160 | ) |
|
167 | ) | |
161 |
|
168 | |||
162 | ## DISABLE REPO CREATE ON A GROUP |
|
169 | ## DISABLE REPO CREATE ON A GROUP | |
163 | response = self.app.put(url('users_group_perm', id=ug.users_group_id), |
|
170 | response = self.app.put(url('users_group_perm', id=ug.users_group_id), | |
164 | {}) |
|
171 | {}) | |
165 |
|
172 | |||
166 | response.follow() |
|
173 | response.follow() | |
167 | ug = UserGroup.get_by_group_name(users_group_name) |
|
174 | ug = UserGroup.get_by_group_name(users_group_name) | |
168 | p = Permission.get_by_key('hg.create.none') |
|
175 | p = Permission.get_by_key('hg.create.none') | |
169 |
p2 = Permission.get_by_key('hg. |
|
176 | p2 = Permission.get_by_key('hg.usergroup.create.false') | |
|
177 | p3 = Permission.get_by_key('hg.fork.none') | |||
170 | # check if user has this perms, they should be here since |
|
178 | # check if user has this perms, they should be here since | |
171 | # defaults are on |
|
179 | # defaults are on | |
172 | perms = UserGroupToPerm.query()\ |
|
180 | perms = UserGroupToPerm.query()\ | |
173 | .filter(UserGroupToPerm.users_group == ug).all() |
|
181 | .filter(UserGroupToPerm.users_group == ug).all() | |
174 |
|
182 | |||
175 | self.assertEqual( |
|
183 | self.assertEqual( | |
176 | [[x.users_group_id, x.permission_id, ] for x in perms], |
|
184 | sorted([[x.users_group_id, x.permission_id, ] for x in perms]), | |
177 | [[ug.users_group_id, p.permission_id], |
|
185 | sorted([[ug.users_group_id, p.permission_id], | |
178 |
[ug.users_group_id, p2.permission_id] |
|
186 | [ug.users_group_id, p2.permission_id], | |
|
187 | [ug.users_group_id, p3.permission_id]]) | |||
179 | ) |
|
188 | ) | |
180 |
|
189 | |||
181 | # DELETE ! |
|
190 | # DELETE ! | |
182 | ug = UserGroup.get_by_group_name(users_group_name) |
|
191 | ug = UserGroup.get_by_group_name(users_group_name) | |
183 | ugid = ug.users_group_id |
|
192 | ugid = ug.users_group_id | |
184 | response = self.app.delete(url('users_group', id=ug.users_group_id)) |
|
193 | response = self.app.delete(url('users_group', id=ug.users_group_id)) | |
185 | response = response.follow() |
|
194 | response = response.follow() | |
186 | gr = self.Session.query(UserGroup)\ |
|
195 | gr = self.Session.query(UserGroup)\ | |
187 | .filter(UserGroup.users_group_name == |
|
196 | .filter(UserGroup.users_group_name == | |
188 | users_group_name).scalar() |
|
197 | users_group_name).scalar() | |
189 |
|
198 | |||
190 | self.assertEqual(gr, None) |
|
199 | self.assertEqual(gr, None) | |
191 | p = Permission.get_by_key('hg.fork.repository') |
|
200 | p = Permission.get_by_key('hg.fork.repository') | |
192 | perms = UserGroupToPerm.query()\ |
|
201 | perms = UserGroupToPerm.query()\ | |
193 | .filter(UserGroupToPerm.users_group_id == ugid).all() |
|
202 | .filter(UserGroupToPerm.users_group_id == ugid).all() | |
194 | perms = [[x.users_group_id, |
|
203 | perms = [[x.users_group_id, | |
195 | x.permission_id, ] for x in perms] |
|
204 | x.permission_id, ] for x in perms] | |
196 | self.assertEqual( |
|
205 | self.assertEqual( | |
197 | perms, |
|
206 | perms, | |
198 | [] |
|
207 | [] | |
199 | ) |
|
208 | ) | |
200 |
|
209 | |||
201 | def test_delete_browser_fakeout(self): |
|
210 | def test_delete_browser_fakeout(self): | |
202 | response = self.app.post(url('users_group', id=1), |
|
211 | response = self.app.post(url('users_group', id=1), | |
203 | params=dict(_method='delete')) |
|
212 | params=dict(_method='delete')) | |
204 |
|
213 | |||
205 | def test_show(self): |
|
214 | def test_show(self): | |
206 | response = self.app.get(url('users_group', id=1)) |
|
215 | response = self.app.get(url('users_group', id=1)) | |
207 |
|
216 | |||
208 | def test_show_as_xml(self): |
|
217 | def test_show_as_xml(self): | |
209 | response = self.app.get(url('formatted_users_group', id=1, format='xml')) |
|
218 | response = self.app.get(url('formatted_users_group', id=1, format='xml')) | |
210 |
|
219 | |||
211 | def test_edit(self): |
|
220 | def test_edit(self): | |
212 | response = self.app.get(url('edit_users_group', id=1)) |
|
221 | response = self.app.get(url('edit_users_group', id=1)) | |
213 |
|
222 | |||
214 | def test_edit_as_xml(self): |
|
223 | def test_edit_as_xml(self): | |
215 | response = self.app.get(url('formatted_edit_users_group', id=1, format='xml')) |
|
224 | response = self.app.get(url('formatted_edit_users_group', id=1, format='xml')) | |
216 |
|
225 | |||
217 | def test_assign_members(self): |
|
226 | def test_assign_members(self): | |
218 | pass |
|
227 | pass | |
219 |
|
228 | |||
220 | def test_add_create_permission(self): |
|
229 | def test_add_create_permission(self): | |
221 | pass |
|
230 | pass | |
222 |
|
231 | |||
223 | def test_revoke_members(self): |
|
232 | def test_revoke_members(self): | |
224 | pass |
|
233 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now