Show More
@@ -1,1265 +1,1275 b'' | |||||
1 | from __future__ import with_statement |
|
1 | from __future__ import with_statement | |
2 | import random |
|
2 | import random | |
3 | import mock |
|
3 | import mock | |
4 |
|
4 | |||
5 | from rhodecode.tests import * |
|
5 | from rhodecode.tests import * | |
6 | from rhodecode.lib.compat import json |
|
6 | from rhodecode.lib.compat import json | |
7 | from rhodecode.lib.auth import AuthUser |
|
7 | from rhodecode.lib.auth import AuthUser | |
8 | from rhodecode.model.user import UserModel |
|
8 | from rhodecode.model.user import UserModel | |
9 | from rhodecode.model.users_group import UsersGroupModel |
|
9 | from rhodecode.model.users_group import UsersGroupModel | |
10 | from rhodecode.model.repo import RepoModel |
|
10 | from rhodecode.model.repo import RepoModel | |
11 | from rhodecode.model.meta import Session |
|
11 | from rhodecode.model.meta import Session | |
12 | from rhodecode.model.scm import ScmModel |
|
12 | from rhodecode.model.scm import ScmModel | |
13 | from rhodecode.model.db import Repository |
|
13 | from rhodecode.model.db import Repository | |
14 |
|
14 | |||
15 | API_URL = '/_admin/api' |
|
15 | API_URL = '/_admin/api' | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | def _build_data(apikey, method, **kw): |
|
18 | def _build_data(apikey, method, **kw): | |
19 | """ |
|
19 | """ | |
20 | Builds API data with given random ID |
|
20 | Builds API data with given random ID | |
21 |
|
21 | |||
22 | :param random_id: |
|
22 | :param random_id: | |
23 | :type random_id: |
|
23 | :type random_id: | |
24 | """ |
|
24 | """ | |
25 | random_id = random.randrange(1, 9999) |
|
25 | random_id = random.randrange(1, 9999) | |
26 | return random_id, json.dumps({ |
|
26 | return random_id, json.dumps({ | |
27 | "id": random_id, |
|
27 | "id": random_id, | |
28 | "api_key": apikey, |
|
28 | "api_key": apikey, | |
29 | "method": method, |
|
29 | "method": method, | |
30 | "args": kw |
|
30 | "args": kw | |
31 | }) |
|
31 | }) | |
32 |
|
32 | |||
33 | jsonify = lambda obj: json.loads(json.dumps(obj)) |
|
33 | jsonify = lambda obj: json.loads(json.dumps(obj)) | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | def crash(*args, **kwargs): |
|
36 | def crash(*args, **kwargs): | |
37 | raise Exception('Total Crash !') |
|
37 | raise Exception('Total Crash !') | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | def api_call(test_obj, params): |
|
40 | def api_call(test_obj, params): | |
41 | response = test_obj.app.post(API_URL, content_type='application/json', |
|
41 | response = test_obj.app.post(API_URL, content_type='application/json', | |
42 | params=params) |
|
42 | params=params) | |
43 | return response |
|
43 | return response | |
44 |
|
44 | |||
45 |
|
45 | |||
46 | TEST_USERS_GROUP = 'test_users_group' |
|
46 | TEST_USERS_GROUP = 'test_users_group' | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | def make_users_group(name=TEST_USERS_GROUP): |
|
49 | def make_users_group(name=TEST_USERS_GROUP): | |
50 | gr = UsersGroupModel().create(name=name) |
|
50 | gr = UsersGroupModel().create(name=name) | |
51 | UsersGroupModel().add_user_to_group(users_group=gr, |
|
51 | UsersGroupModel().add_user_to_group(users_group=gr, | |
52 | user=TEST_USER_ADMIN_LOGIN) |
|
52 | user=TEST_USER_ADMIN_LOGIN) | |
53 | Session().commit() |
|
53 | Session().commit() | |
54 | return gr |
|
54 | return gr | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | def destroy_users_group(name=TEST_USERS_GROUP): |
|
57 | def destroy_users_group(name=TEST_USERS_GROUP): | |
58 | UsersGroupModel().delete(users_group=name, force=True) |
|
58 | UsersGroupModel().delete(users_group=name, force=True) | |
59 | Session().commit() |
|
59 | Session().commit() | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | def create_repo(repo_name, repo_type, owner=None): |
|
62 | def create_repo(repo_name, repo_type, owner=None): | |
63 | # create new repo |
|
63 | # create new repo | |
64 | form_data = _get_repo_create_params( |
|
64 | form_data = _get_repo_create_params( | |
65 | repo_name_full=repo_name, |
|
65 | repo_name_full=repo_name, | |
66 | repo_description='description %s' % repo_name, |
|
66 | repo_description='description %s' % repo_name, | |
67 | ) |
|
67 | ) | |
68 | cur_user = UserModel().get_by_username(owner or TEST_USER_ADMIN_LOGIN) |
|
68 | cur_user = UserModel().get_by_username(owner or TEST_USER_ADMIN_LOGIN) | |
69 | r = RepoModel().create(form_data, cur_user) |
|
69 | r = RepoModel().create(form_data, cur_user) | |
70 | Session().commit() |
|
70 | Session().commit() | |
71 | return r |
|
71 | return r | |
72 |
|
72 | |||
73 |
|
73 | |||
74 | def create_fork(fork_name, fork_type, fork_of): |
|
74 | def create_fork(fork_name, fork_type, fork_of): | |
75 | fork = RepoModel(Session())._get_repo(fork_of) |
|
75 | fork = RepoModel(Session())._get_repo(fork_of) | |
76 | r = create_repo(fork_name, fork_type) |
|
76 | r = create_repo(fork_name, fork_type) | |
77 | r.fork = fork |
|
77 | r.fork = fork | |
78 | Session().add(r) |
|
78 | Session().add(r) | |
79 | Session().commit() |
|
79 | Session().commit() | |
80 | return r |
|
80 | return r | |
81 |
|
81 | |||
82 |
|
82 | |||
83 | def destroy_repo(repo_name): |
|
83 | def destroy_repo(repo_name): | |
84 | RepoModel().delete(repo_name) |
|
84 | RepoModel().delete(repo_name) | |
85 | Session().commit() |
|
85 | Session().commit() | |
86 |
|
86 | |||
87 |
|
87 | |||
88 | class BaseTestApi(object): |
|
88 | class BaseTestApi(object): | |
89 | REPO = None |
|
89 | REPO = None | |
90 | REPO_TYPE = None |
|
90 | REPO_TYPE = None | |
91 |
|
91 | |||
92 | @classmethod |
|
92 | @classmethod | |
93 | def setUpClass(self): |
|
93 | def setUpClass(self): | |
94 | self.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
94 | self.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
95 | self.apikey = self.usr.api_key |
|
95 | self.apikey = self.usr.api_key | |
96 | self.test_user = UserModel().create_or_update( |
|
96 | self.test_user = UserModel().create_or_update( | |
97 | username='test-api', |
|
97 | username='test-api', | |
98 | password='test', |
|
98 | password='test', | |
99 | email='test@api.rhodecode.org', |
|
99 | email='test@api.rhodecode.org', | |
100 | firstname='first', |
|
100 | firstname='first', | |
101 | lastname='last' |
|
101 | lastname='last' | |
102 | ) |
|
102 | ) | |
103 | Session().commit() |
|
103 | Session().commit() | |
104 | self.TEST_USER_LOGIN = self.test_user.username |
|
104 | self.TEST_USER_LOGIN = self.test_user.username | |
105 | self.apikey_regular = self.test_user.api_key |
|
105 | self.apikey_regular = self.test_user.api_key | |
106 |
|
106 | |||
107 | @classmethod |
|
107 | @classmethod | |
108 | def teardownClass(self): |
|
108 | def teardownClass(self): | |
109 | pass |
|
109 | pass | |
110 |
|
110 | |||
111 | def setUp(self): |
|
111 | def setUp(self): | |
112 | self.maxDiff = None |
|
112 | self.maxDiff = None | |
113 | make_users_group() |
|
113 | make_users_group() | |
114 |
|
114 | |||
115 | def tearDown(self): |
|
115 | def tearDown(self): | |
116 | destroy_users_group() |
|
116 | destroy_users_group() | |
117 |
|
117 | |||
118 | def _compare_ok(self, id_, expected, given): |
|
118 | def _compare_ok(self, id_, expected, given): | |
119 | expected = jsonify({ |
|
119 | expected = jsonify({ | |
120 | 'id': id_, |
|
120 | 'id': id_, | |
121 | 'error': None, |
|
121 | 'error': None, | |
122 | 'result': expected |
|
122 | 'result': expected | |
123 | }) |
|
123 | }) | |
124 | given = json.loads(given) |
|
124 | given = json.loads(given) | |
125 | self.assertEqual(expected, given) |
|
125 | self.assertEqual(expected, given) | |
126 |
|
126 | |||
127 | def _compare_error(self, id_, expected, given): |
|
127 | def _compare_error(self, id_, expected, given): | |
128 | expected = jsonify({ |
|
128 | expected = jsonify({ | |
129 | 'id': id_, |
|
129 | 'id': id_, | |
130 | 'error': expected, |
|
130 | 'error': expected, | |
131 | 'result': None |
|
131 | 'result': None | |
132 | }) |
|
132 | }) | |
133 | given = json.loads(given) |
|
133 | given = json.loads(given) | |
134 | self.assertEqual(expected, given) |
|
134 | self.assertEqual(expected, given) | |
135 |
|
135 | |||
136 | # def test_Optional(self): |
|
136 | # def test_Optional(self): | |
137 | # from rhodecode.controllers.api.api import Optional |
|
137 | # from rhodecode.controllers.api.api import Optional | |
138 | # option1 = Optional(None) |
|
138 | # option1 = Optional(None) | |
139 | # self.assertEqual('<Optional:%s>' % None, repr(option1)) |
|
139 | # self.assertEqual('<Optional:%s>' % None, repr(option1)) | |
140 | # |
|
140 | # | |
141 | # self.assertEqual(1, Optional.extract(Optional(1))) |
|
141 | # self.assertEqual(1, Optional.extract(Optional(1))) | |
142 | # self.assertEqual('trololo', Optional.extract('trololo')) |
|
142 | # self.assertEqual('trololo', Optional.extract('trololo')) | |
143 |
|
143 | |||
144 | def test_api_wrong_key(self): |
|
144 | def test_api_wrong_key(self): | |
145 | id_, params = _build_data('trololo', 'get_user') |
|
145 | id_, params = _build_data('trololo', 'get_user') | |
146 | response = api_call(self, params) |
|
146 | response = api_call(self, params) | |
147 |
|
147 | |||
148 | expected = 'Invalid API KEY' |
|
148 | expected = 'Invalid API KEY' | |
149 | self._compare_error(id_, expected, given=response.body) |
|
149 | self._compare_error(id_, expected, given=response.body) | |
150 |
|
150 | |||
151 | def test_api_missing_non_optional_param(self): |
|
151 | def test_api_missing_non_optional_param(self): | |
152 | id_, params = _build_data(self.apikey, 'get_repo') |
|
152 | id_, params = _build_data(self.apikey, 'get_repo') | |
153 | response = api_call(self, params) |
|
153 | response = api_call(self, params) | |
154 |
|
154 | |||
155 | expected = 'Missing non optional `repoid` arg in JSON DATA' |
|
155 | expected = 'Missing non optional `repoid` arg in JSON DATA' | |
156 | self._compare_error(id_, expected, given=response.body) |
|
156 | self._compare_error(id_, expected, given=response.body) | |
157 |
|
157 | |||
158 | def test_api_missing_non_optional_param_args_null(self): |
|
158 | def test_api_missing_non_optional_param_args_null(self): | |
159 | id_, params = _build_data(self.apikey, 'get_repo') |
|
159 | id_, params = _build_data(self.apikey, 'get_repo') | |
160 | params = params.replace('"args": {}', '"args": null') |
|
160 | params = params.replace('"args": {}', '"args": null') | |
161 | response = api_call(self, params) |
|
161 | response = api_call(self, params) | |
162 |
|
162 | |||
163 | expected = 'Missing non optional `repoid` arg in JSON DATA' |
|
163 | expected = 'Missing non optional `repoid` arg in JSON DATA' | |
164 | self._compare_error(id_, expected, given=response.body) |
|
164 | self._compare_error(id_, expected, given=response.body) | |
165 |
|
165 | |||
166 | def test_api_missing_non_optional_param_args_bad(self): |
|
166 | def test_api_missing_non_optional_param_args_bad(self): | |
167 | id_, params = _build_data(self.apikey, 'get_repo') |
|
167 | id_, params = _build_data(self.apikey, 'get_repo') | |
168 | params = params.replace('"args": {}', '"args": 1') |
|
168 | params = params.replace('"args": {}', '"args": 1') | |
169 | response = api_call(self, params) |
|
169 | response = api_call(self, params) | |
170 |
|
170 | |||
171 | expected = 'Missing non optional `repoid` arg in JSON DATA' |
|
171 | expected = 'Missing non optional `repoid` arg in JSON DATA' | |
172 | self._compare_error(id_, expected, given=response.body) |
|
172 | self._compare_error(id_, expected, given=response.body) | |
173 |
|
173 | |||
174 | def test_api_args_is_null(self): |
|
174 | def test_api_args_is_null(self): | |
175 | id_, params = _build_data(self.apikey, 'get_users',) |
|
175 | id_, params = _build_data(self.apikey, 'get_users',) | |
176 | params = params.replace('"args": {}', '"args": null') |
|
176 | params = params.replace('"args": {}', '"args": null') | |
177 | response = api_call(self, params) |
|
177 | response = api_call(self, params) | |
178 | self.assertEqual(response.status, '200 OK') |
|
178 | self.assertEqual(response.status, '200 OK') | |
179 |
|
179 | |||
180 | def test_api_args_is_bad(self): |
|
180 | def test_api_args_is_bad(self): | |
181 | id_, params = _build_data(self.apikey, 'get_users',) |
|
181 | id_, params = _build_data(self.apikey, 'get_users',) | |
182 | params = params.replace('"args": {}', '"args": 1') |
|
182 | params = params.replace('"args": {}', '"args": 1') | |
183 | response = api_call(self, params) |
|
183 | response = api_call(self, params) | |
184 | self.assertEqual(response.status, '200 OK') |
|
184 | self.assertEqual(response.status, '200 OK') | |
185 |
|
185 | |||
186 | def test_api_get_users(self): |
|
186 | def test_api_get_users(self): | |
187 | id_, params = _build_data(self.apikey, 'get_users',) |
|
187 | id_, params = _build_data(self.apikey, 'get_users',) | |
188 | response = api_call(self, params) |
|
188 | response = api_call(self, params) | |
189 | ret_all = [] |
|
189 | ret_all = [] | |
190 | for usr in UserModel().get_all(): |
|
190 | for usr in UserModel().get_all(): | |
191 | ret = usr.get_api_data() |
|
191 | ret = usr.get_api_data() | |
192 | ret_all.append(jsonify(ret)) |
|
192 | ret_all.append(jsonify(ret)) | |
193 | expected = ret_all |
|
193 | expected = ret_all | |
194 | self._compare_ok(id_, expected, given=response.body) |
|
194 | self._compare_ok(id_, expected, given=response.body) | |
195 |
|
195 | |||
196 | def test_api_get_user(self): |
|
196 | def test_api_get_user(self): | |
197 | id_, params = _build_data(self.apikey, 'get_user', |
|
197 | id_, params = _build_data(self.apikey, 'get_user', | |
198 | userid=TEST_USER_ADMIN_LOGIN) |
|
198 | userid=TEST_USER_ADMIN_LOGIN) | |
199 | response = api_call(self, params) |
|
199 | response = api_call(self, params) | |
200 |
|
200 | |||
201 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
201 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
202 | ret = usr.get_api_data() |
|
202 | ret = usr.get_api_data() | |
203 | ret['permissions'] = AuthUser(usr.user_id).permissions |
|
203 | ret['permissions'] = AuthUser(usr.user_id).permissions | |
204 |
|
204 | |||
205 | expected = ret |
|
205 | expected = ret | |
206 | self._compare_ok(id_, expected, given=response.body) |
|
206 | self._compare_ok(id_, expected, given=response.body) | |
207 |
|
207 | |||
208 | def test_api_get_user_that_does_not_exist(self): |
|
208 | def test_api_get_user_that_does_not_exist(self): | |
209 | id_, params = _build_data(self.apikey, 'get_user', |
|
209 | id_, params = _build_data(self.apikey, 'get_user', | |
210 | userid='trololo') |
|
210 | userid='trololo') | |
211 | response = api_call(self, params) |
|
211 | response = api_call(self, params) | |
212 |
|
212 | |||
213 | expected = "user `%s` does not exist" % 'trololo' |
|
213 | expected = "user `%s` does not exist" % 'trololo' | |
214 | self._compare_error(id_, expected, given=response.body) |
|
214 | self._compare_error(id_, expected, given=response.body) | |
215 |
|
215 | |||
216 | def test_api_get_user_without_giving_userid(self): |
|
216 | def test_api_get_user_without_giving_userid(self): | |
217 | id_, params = _build_data(self.apikey, 'get_user') |
|
217 | id_, params = _build_data(self.apikey, 'get_user') | |
218 | response = api_call(self, params) |
|
218 | response = api_call(self, params) | |
219 |
|
219 | |||
220 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
220 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
221 | ret = usr.get_api_data() |
|
221 | ret = usr.get_api_data() | |
222 | ret['permissions'] = AuthUser(usr.user_id).permissions |
|
222 | ret['permissions'] = AuthUser(usr.user_id).permissions | |
223 |
|
223 | |||
224 | expected = ret |
|
224 | expected = ret | |
225 | self._compare_ok(id_, expected, given=response.body) |
|
225 | self._compare_ok(id_, expected, given=response.body) | |
226 |
|
226 | |||
227 | def test_api_get_user_without_giving_userid_non_admin(self): |
|
227 | def test_api_get_user_without_giving_userid_non_admin(self): | |
228 | id_, params = _build_data(self.apikey_regular, 'get_user') |
|
228 | id_, params = _build_data(self.apikey_regular, 'get_user') | |
229 | response = api_call(self, params) |
|
229 | response = api_call(self, params) | |
230 |
|
230 | |||
231 | usr = UserModel().get_by_username(self.TEST_USER_LOGIN) |
|
231 | usr = UserModel().get_by_username(self.TEST_USER_LOGIN) | |
232 | ret = usr.get_api_data() |
|
232 | ret = usr.get_api_data() | |
233 | ret['permissions'] = AuthUser(usr.user_id).permissions |
|
233 | ret['permissions'] = AuthUser(usr.user_id).permissions | |
234 |
|
234 | |||
235 | expected = ret |
|
235 | expected = ret | |
236 | self._compare_ok(id_, expected, given=response.body) |
|
236 | self._compare_ok(id_, expected, given=response.body) | |
237 |
|
237 | |||
238 | def test_api_get_user_with_giving_userid_non_admin(self): |
|
238 | def test_api_get_user_with_giving_userid_non_admin(self): | |
239 | id_, params = _build_data(self.apikey_regular, 'get_user', |
|
239 | id_, params = _build_data(self.apikey_regular, 'get_user', | |
240 | userid=self.TEST_USER_LOGIN) |
|
240 | userid=self.TEST_USER_LOGIN) | |
241 | response = api_call(self, params) |
|
241 | response = api_call(self, params) | |
242 |
|
242 | |||
243 | expected = 'userid is not the same as your user' |
|
243 | expected = 'userid is not the same as your user' | |
244 | self._compare_error(id_, expected, given=response.body) |
|
244 | self._compare_error(id_, expected, given=response.body) | |
245 |
|
245 | |||
246 | def test_api_pull(self): |
|
246 | def test_api_pull(self): | |
247 | #TODO: issues with rhodecode_extras here.. not sure why ! |
|
247 | #TODO: issues with rhodecode_extras here.. not sure why ! | |
248 | pass |
|
248 | pass | |
249 |
|
249 | |||
250 | # repo_name = 'test_pull' |
|
250 | # repo_name = 'test_pull' | |
251 | # r = create_repo(repo_name, self.REPO_TYPE) |
|
251 | # r = create_repo(repo_name, self.REPO_TYPE) | |
252 | # r.clone_uri = TEST_self.REPO |
|
252 | # r.clone_uri = TEST_self.REPO | |
253 | # Session.add(r) |
|
253 | # Session.add(r) | |
254 | # Session.commit() |
|
254 | # Session.commit() | |
255 | # |
|
255 | # | |
256 | # id_, params = _build_data(self.apikey, 'pull', |
|
256 | # id_, params = _build_data(self.apikey, 'pull', | |
257 | # repoid=repo_name,) |
|
257 | # repoid=repo_name,) | |
258 | # response = self.app.post(API_URL, content_type='application/json', |
|
258 | # response = self.app.post(API_URL, content_type='application/json', | |
259 | # params=params) |
|
259 | # params=params) | |
260 | # |
|
260 | # | |
261 | # expected = 'Pulled from `%s`' % repo_name |
|
261 | # expected = 'Pulled from `%s`' % repo_name | |
262 | # self._compare_ok(id_, expected, given=response.body) |
|
262 | # self._compare_ok(id_, expected, given=response.body) | |
263 | # |
|
263 | # | |
264 | # destroy_repo(repo_name) |
|
264 | # destroy_repo(repo_name) | |
265 |
|
265 | |||
266 | def test_api_pull_error(self): |
|
266 | def test_api_pull_error(self): | |
267 | id_, params = _build_data(self.apikey, 'pull', |
|
267 | id_, params = _build_data(self.apikey, 'pull', | |
268 | repoid=self.REPO,) |
|
268 | repoid=self.REPO,) | |
269 | response = api_call(self, params) |
|
269 | response = api_call(self, params) | |
270 |
|
270 | |||
271 | expected = 'Unable to pull changes from `%s`' % self.REPO |
|
271 | expected = 'Unable to pull changes from `%s`' % self.REPO | |
272 | self._compare_error(id_, expected, given=response.body) |
|
272 | self._compare_error(id_, expected, given=response.body) | |
273 |
|
273 | |||
274 | def test_api_rescan_repos(self): |
|
274 | def test_api_rescan_repos(self): | |
275 | id_, params = _build_data(self.apikey, 'rescan_repos') |
|
275 | id_, params = _build_data(self.apikey, 'rescan_repos') | |
276 | response = api_call(self, params) |
|
276 | response = api_call(self, params) | |
277 |
|
277 | |||
278 | expected = {'added': [], 'removed': []} |
|
278 | expected = {'added': [], 'removed': []} | |
279 | self._compare_ok(id_, expected, given=response.body) |
|
279 | self._compare_ok(id_, expected, given=response.body) | |
280 |
|
280 | |||
281 | @mock.patch.object(ScmModel, 'repo_scan', crash) |
|
281 | @mock.patch.object(ScmModel, 'repo_scan', crash) | |
282 | def test_api_rescann_error(self): |
|
282 | def test_api_rescann_error(self): | |
283 | id_, params = _build_data(self.apikey, 'rescan_repos',) |
|
283 | id_, params = _build_data(self.apikey, 'rescan_repos',) | |
284 | response = api_call(self, params) |
|
284 | response = api_call(self, params) | |
285 |
|
285 | |||
286 | expected = 'Error occurred during rescan repositories action' |
|
286 | expected = 'Error occurred during rescan repositories action' | |
287 | self._compare_error(id_, expected, given=response.body) |
|
287 | self._compare_error(id_, expected, given=response.body) | |
288 |
|
288 | |||
289 | def test_api_lock_repo_lock_aquire(self): |
|
289 | def test_api_lock_repo_lock_aquire(self): | |
290 | id_, params = _build_data(self.apikey, 'lock', |
|
290 | id_, params = _build_data(self.apikey, 'lock', | |
291 | userid=TEST_USER_ADMIN_LOGIN, |
|
291 | userid=TEST_USER_ADMIN_LOGIN, | |
292 | repoid=self.REPO, |
|
292 | repoid=self.REPO, | |
293 | locked=True) |
|
293 | locked=True) | |
294 | response = api_call(self, params) |
|
294 | response = api_call(self, params) | |
295 | expected = ('User `%s` set lock state for repo `%s` to `%s`' |
|
295 | expected = ('User `%s` set lock state for repo `%s` to `%s`' | |
296 | % (TEST_USER_ADMIN_LOGIN, self.REPO, True)) |
|
296 | % (TEST_USER_ADMIN_LOGIN, self.REPO, True)) | |
297 | self._compare_ok(id_, expected, given=response.body) |
|
297 | self._compare_ok(id_, expected, given=response.body) | |
298 |
|
298 | |||
299 | def test_api_lock_repo_lock_aquire_by_non_admin(self): |
|
299 | def test_api_lock_repo_lock_aquire_by_non_admin(self): | |
300 | repo_name = 'api_delete_me' |
|
300 | repo_name = 'api_delete_me' | |
301 | create_repo(repo_name, self.REPO_TYPE, owner=self.TEST_USER_LOGIN) |
|
301 | create_repo(repo_name, self.REPO_TYPE, owner=self.TEST_USER_LOGIN) | |
302 | try: |
|
302 | try: | |
303 | id_, params = _build_data(self.apikey_regular, 'lock', |
|
303 | id_, params = _build_data(self.apikey_regular, 'lock', | |
304 | repoid=repo_name, |
|
304 | repoid=repo_name, | |
305 | locked=True) |
|
305 | locked=True) | |
306 | response = api_call(self, params) |
|
306 | response = api_call(self, params) | |
307 | expected = ('User `%s` set lock state for repo `%s` to `%s`' |
|
307 | expected = ('User `%s` set lock state for repo `%s` to `%s`' | |
308 | % (self.TEST_USER_LOGIN, repo_name, True)) |
|
308 | % (self.TEST_USER_LOGIN, repo_name, True)) | |
309 | self._compare_ok(id_, expected, given=response.body) |
|
309 | self._compare_ok(id_, expected, given=response.body) | |
310 | finally: |
|
310 | finally: | |
311 | destroy_repo(repo_name) |
|
311 | destroy_repo(repo_name) | |
312 |
|
312 | |||
313 | def test_api_lock_repo_lock_aquire_non_admin_with_userid(self): |
|
313 | def test_api_lock_repo_lock_aquire_non_admin_with_userid(self): | |
314 | repo_name = 'api_delete_me' |
|
314 | repo_name = 'api_delete_me' | |
315 | create_repo(repo_name, self.REPO_TYPE, owner=self.TEST_USER_LOGIN) |
|
315 | create_repo(repo_name, self.REPO_TYPE, owner=self.TEST_USER_LOGIN) | |
316 | try: |
|
316 | try: | |
317 | id_, params = _build_data(self.apikey_regular, 'lock', |
|
317 | id_, params = _build_data(self.apikey_regular, 'lock', | |
318 | userid=TEST_USER_ADMIN_LOGIN, |
|
318 | userid=TEST_USER_ADMIN_LOGIN, | |
319 | repoid=repo_name, |
|
319 | repoid=repo_name, | |
320 | locked=True) |
|
320 | locked=True) | |
321 | response = api_call(self, params) |
|
321 | response = api_call(self, params) | |
322 | expected = 'userid is not the same as your user' |
|
322 | expected = 'userid is not the same as your user' | |
323 | self._compare_error(id_, expected, given=response.body) |
|
323 | self._compare_error(id_, expected, given=response.body) | |
324 | finally: |
|
324 | finally: | |
325 | destroy_repo(repo_name) |
|
325 | destroy_repo(repo_name) | |
326 |
|
326 | |||
327 | def test_api_lock_repo_lock_aquire_non_admin_not_his_repo(self): |
|
327 | def test_api_lock_repo_lock_aquire_non_admin_not_his_repo(self): | |
328 | id_, params = _build_data(self.apikey_regular, 'lock', |
|
328 | id_, params = _build_data(self.apikey_regular, 'lock', | |
329 | repoid=self.REPO, |
|
329 | repoid=self.REPO, | |
330 | locked=True) |
|
330 | locked=True) | |
331 | response = api_call(self, params) |
|
331 | response = api_call(self, params) | |
332 | expected = 'repository `%s` does not exist' % (self.REPO) |
|
332 | expected = 'repository `%s` does not exist' % (self.REPO) | |
333 | self._compare_error(id_, expected, given=response.body) |
|
333 | self._compare_error(id_, expected, given=response.body) | |
334 |
|
334 | |||
335 | def test_api_lock_repo_lock_release(self): |
|
335 | def test_api_lock_repo_lock_release(self): | |
336 | id_, params = _build_data(self.apikey, 'lock', |
|
336 | id_, params = _build_data(self.apikey, 'lock', | |
337 | userid=TEST_USER_ADMIN_LOGIN, |
|
337 | userid=TEST_USER_ADMIN_LOGIN, | |
338 | repoid=self.REPO, |
|
338 | repoid=self.REPO, | |
339 | locked=False) |
|
339 | locked=False) | |
340 | response = api_call(self, params) |
|
340 | response = api_call(self, params) | |
341 | expected = ('User `%s` set lock state for repo `%s` to `%s`' |
|
341 | expected = ('User `%s` set lock state for repo `%s` to `%s`' | |
342 | % (TEST_USER_ADMIN_LOGIN, self.REPO, False)) |
|
342 | % (TEST_USER_ADMIN_LOGIN, self.REPO, False)) | |
343 | self._compare_ok(id_, expected, given=response.body) |
|
343 | self._compare_ok(id_, expected, given=response.body) | |
344 |
|
344 | |||
345 | def test_api_lock_repo_lock_aquire_optional_userid(self): |
|
345 | def test_api_lock_repo_lock_aquire_optional_userid(self): | |
346 | id_, params = _build_data(self.apikey, 'lock', |
|
346 | id_, params = _build_data(self.apikey, 'lock', | |
347 | repoid=self.REPO, |
|
347 | repoid=self.REPO, | |
348 | locked=True) |
|
348 | locked=True) | |
349 | response = api_call(self, params) |
|
349 | response = api_call(self, params) | |
350 | expected = ('User `%s` set lock state for repo `%s` to `%s`' |
|
350 | expected = ('User `%s` set lock state for repo `%s` to `%s`' | |
351 | % (TEST_USER_ADMIN_LOGIN, self.REPO, True)) |
|
351 | % (TEST_USER_ADMIN_LOGIN, self.REPO, True)) | |
352 | self._compare_ok(id_, expected, given=response.body) |
|
352 | self._compare_ok(id_, expected, given=response.body) | |
353 |
|
353 | |||
354 | @mock.patch.object(Repository, 'lock', crash) |
|
354 | @mock.patch.object(Repository, 'lock', crash) | |
355 | def test_api_lock_error(self): |
|
355 | def test_api_lock_error(self): | |
356 | id_, params = _build_data(self.apikey, 'lock', |
|
356 | id_, params = _build_data(self.apikey, 'lock', | |
357 | userid=TEST_USER_ADMIN_LOGIN, |
|
357 | userid=TEST_USER_ADMIN_LOGIN, | |
358 | repoid=self.REPO, |
|
358 | repoid=self.REPO, | |
359 | locked=True) |
|
359 | locked=True) | |
360 | response = api_call(self, params) |
|
360 | response = api_call(self, params) | |
361 |
|
361 | |||
362 | expected = 'Error occurred locking repository `%s`' % self.REPO |
|
362 | expected = 'Error occurred locking repository `%s`' % self.REPO | |
363 | self._compare_error(id_, expected, given=response.body) |
|
363 | self._compare_error(id_, expected, given=response.body) | |
364 |
|
364 | |||
365 | def test_api_create_existing_user(self): |
|
365 | def test_api_create_existing_user(self): | |
366 | id_, params = _build_data(self.apikey, 'create_user', |
|
366 | id_, params = _build_data(self.apikey, 'create_user', | |
367 | username=TEST_USER_ADMIN_LOGIN, |
|
367 | username=TEST_USER_ADMIN_LOGIN, | |
368 | email='test@foo.com', |
|
368 | email='test@foo.com', | |
369 | password='trololo') |
|
369 | password='trololo') | |
370 | response = api_call(self, params) |
|
370 | response = api_call(self, params) | |
371 |
|
371 | |||
372 | expected = "user `%s` already exist" % TEST_USER_ADMIN_LOGIN |
|
372 | expected = "user `%s` already exist" % TEST_USER_ADMIN_LOGIN | |
373 | self._compare_error(id_, expected, given=response.body) |
|
373 | self._compare_error(id_, expected, given=response.body) | |
374 |
|
374 | |||
375 | def test_api_create_user_with_existing_email(self): |
|
375 | def test_api_create_user_with_existing_email(self): | |
376 | id_, params = _build_data(self.apikey, 'create_user', |
|
376 | id_, params = _build_data(self.apikey, 'create_user', | |
377 | username=TEST_USER_ADMIN_LOGIN + 'new', |
|
377 | username=TEST_USER_ADMIN_LOGIN + 'new', | |
378 | email=TEST_USER_REGULAR_EMAIL, |
|
378 | email=TEST_USER_REGULAR_EMAIL, | |
379 | password='trololo') |
|
379 | password='trololo') | |
380 | response = api_call(self, params) |
|
380 | response = api_call(self, params) | |
381 |
|
381 | |||
382 | expected = "email `%s` already exist" % TEST_USER_REGULAR_EMAIL |
|
382 | expected = "email `%s` already exist" % TEST_USER_REGULAR_EMAIL | |
383 | self._compare_error(id_, expected, given=response.body) |
|
383 | self._compare_error(id_, expected, given=response.body) | |
384 |
|
384 | |||
385 | def test_api_create_user(self): |
|
385 | def test_api_create_user(self): | |
386 | username = 'test_new_api_user' |
|
386 | username = 'test_new_api_user' | |
387 | email = username + "@foo.com" |
|
387 | email = username + "@foo.com" | |
388 |
|
388 | |||
389 | id_, params = _build_data(self.apikey, 'create_user', |
|
389 | id_, params = _build_data(self.apikey, 'create_user', | |
390 | username=username, |
|
390 | username=username, | |
391 | email=email, |
|
391 | email=email, | |
392 | password='trololo') |
|
392 | password='trololo') | |
393 | response = api_call(self, params) |
|
393 | response = api_call(self, params) | |
394 |
|
394 | |||
395 | usr = UserModel().get_by_username(username) |
|
395 | usr = UserModel().get_by_username(username) | |
396 | ret = dict( |
|
396 | ret = dict( | |
397 | msg='created new user `%s`' % username, |
|
397 | msg='created new user `%s`' % username, | |
398 | user=jsonify(usr.get_api_data()) |
|
398 | user=jsonify(usr.get_api_data()) | |
399 | ) |
|
399 | ) | |
400 |
|
400 | |||
401 | expected = ret |
|
401 | expected = ret | |
402 | self._compare_ok(id_, expected, given=response.body) |
|
402 | self._compare_ok(id_, expected, given=response.body) | |
403 |
|
403 | |||
404 | UserModel().delete(usr.user_id) |
|
404 | UserModel().delete(usr.user_id) | |
405 | Session().commit() |
|
405 | Session().commit() | |
406 |
|
406 | |||
407 | @mock.patch.object(UserModel, 'create_or_update', crash) |
|
407 | @mock.patch.object(UserModel, 'create_or_update', crash) | |
408 | def test_api_create_user_when_exception_happened(self): |
|
408 | def test_api_create_user_when_exception_happened(self): | |
409 |
|
409 | |||
410 | username = 'test_new_api_user' |
|
410 | username = 'test_new_api_user' | |
411 | email = username + "@foo.com" |
|
411 | email = username + "@foo.com" | |
412 |
|
412 | |||
413 | id_, params = _build_data(self.apikey, 'create_user', |
|
413 | id_, params = _build_data(self.apikey, 'create_user', | |
414 | username=username, |
|
414 | username=username, | |
415 | email=email, |
|
415 | email=email, | |
416 | password='trololo') |
|
416 | password='trololo') | |
417 | response = api_call(self, params) |
|
417 | response = api_call(self, params) | |
418 | expected = 'failed to create user `%s`' % username |
|
418 | expected = 'failed to create user `%s`' % username | |
419 | self._compare_error(id_, expected, given=response.body) |
|
419 | self._compare_error(id_, expected, given=response.body) | |
420 |
|
420 | |||
421 | def test_api_delete_user(self): |
|
421 | def test_api_delete_user(self): | |
422 | usr = UserModel().create_or_update(username=u'test_user', |
|
422 | usr = UserModel().create_or_update(username=u'test_user', | |
423 | password=u'qweqwe', |
|
423 | password=u'qweqwe', | |
424 | email=u'u232@rhodecode.org', |
|
424 | email=u'u232@rhodecode.org', | |
425 | firstname=u'u1', lastname=u'u1') |
|
425 | firstname=u'u1', lastname=u'u1') | |
426 | Session().commit() |
|
426 | Session().commit() | |
427 | username = usr.username |
|
427 | username = usr.username | |
428 | email = usr.email |
|
428 | email = usr.email | |
429 | usr_id = usr.user_id |
|
429 | usr_id = usr.user_id | |
430 | ## DELETE THIS USER NOW |
|
430 | ## DELETE THIS USER NOW | |
431 |
|
431 | |||
432 | id_, params = _build_data(self.apikey, 'delete_user', |
|
432 | id_, params = _build_data(self.apikey, 'delete_user', | |
433 | userid=username,) |
|
433 | userid=username,) | |
434 | response = api_call(self, params) |
|
434 | response = api_call(self, params) | |
435 |
|
435 | |||
436 | ret = {'msg': 'deleted user ID:%s %s' % (usr_id, username), |
|
436 | ret = {'msg': 'deleted user ID:%s %s' % (usr_id, username), | |
437 | 'user': None} |
|
437 | 'user': None} | |
438 | expected = ret |
|
438 | expected = ret | |
439 | self._compare_ok(id_, expected, given=response.body) |
|
439 | self._compare_ok(id_, expected, given=response.body) | |
440 |
|
440 | |||
441 | @mock.patch.object(UserModel, 'delete', crash) |
|
441 | @mock.patch.object(UserModel, 'delete', crash) | |
442 | def test_api_delete_user_when_exception_happened(self): |
|
442 | def test_api_delete_user_when_exception_happened(self): | |
443 | usr = UserModel().create_or_update(username=u'test_user', |
|
443 | usr = UserModel().create_or_update(username=u'test_user', | |
444 | password=u'qweqwe', |
|
444 | password=u'qweqwe', | |
445 | email=u'u232@rhodecode.org', |
|
445 | email=u'u232@rhodecode.org', | |
446 | firstname=u'u1', lastname=u'u1') |
|
446 | firstname=u'u1', lastname=u'u1') | |
447 | Session().commit() |
|
447 | Session().commit() | |
448 | username = usr.username |
|
448 | username = usr.username | |
449 |
|
449 | |||
450 | id_, params = _build_data(self.apikey, 'delete_user', |
|
450 | id_, params = _build_data(self.apikey, 'delete_user', | |
451 | userid=username,) |
|
451 | userid=username,) | |
452 | response = api_call(self, params) |
|
452 | response = api_call(self, params) | |
453 | ret = 'failed to delete ID:%s %s' % (usr.user_id, |
|
453 | ret = 'failed to delete ID:%s %s' % (usr.user_id, | |
454 | usr.username) |
|
454 | usr.username) | |
455 | expected = ret |
|
455 | expected = ret | |
456 | self._compare_error(id_, expected, given=response.body) |
|
456 | self._compare_error(id_, expected, given=response.body) | |
457 |
|
457 | |||
458 | @parameterized.expand([('firstname', 'new_username'), |
|
458 | @parameterized.expand([('firstname', 'new_username'), | |
459 | ('lastname', 'new_username'), |
|
459 | ('lastname', 'new_username'), | |
460 | ('email', 'new_username'), |
|
460 | ('email', 'new_username'), | |
461 | ('admin', True), |
|
461 | ('admin', True), | |
462 | ('admin', False), |
|
462 | ('admin', False), | |
463 | ('ldap_dn', 'test'), |
|
463 | ('ldap_dn', 'test'), | |
464 | ('ldap_dn', None), |
|
464 | ('ldap_dn', None), | |
465 | ('active', False), |
|
465 | ('active', False), | |
466 | ('active', True), |
|
466 | ('active', True), | |
467 | ('password', 'newpass') |
|
467 | ('password', 'newpass') | |
468 | ]) |
|
468 | ]) | |
469 | def test_api_update_user(self, name, expected): |
|
469 | def test_api_update_user(self, name, expected): | |
470 | usr = UserModel().get_by_username(self.TEST_USER_LOGIN) |
|
470 | usr = UserModel().get_by_username(self.TEST_USER_LOGIN) | |
471 | kw = {name: expected, |
|
471 | kw = {name: expected, | |
472 | 'userid': usr.user_id} |
|
472 | 'userid': usr.user_id} | |
473 | id_, params = _build_data(self.apikey, 'update_user', **kw) |
|
473 | id_, params = _build_data(self.apikey, 'update_user', **kw) | |
474 | response = api_call(self, params) |
|
474 | response = api_call(self, params) | |
475 |
|
475 | |||
476 | ret = { |
|
476 | ret = { | |
477 | 'msg': 'updated user ID:%s %s' % (usr.user_id, self.TEST_USER_LOGIN), |
|
477 | 'msg': 'updated user ID:%s %s' % (usr.user_id, self.TEST_USER_LOGIN), | |
478 | 'user': jsonify(UserModel()\ |
|
478 | 'user': jsonify(UserModel()\ | |
479 | .get_by_username(self.TEST_USER_LOGIN)\ |
|
479 | .get_by_username(self.TEST_USER_LOGIN)\ | |
480 | .get_api_data()) |
|
480 | .get_api_data()) | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | expected = ret |
|
483 | expected = ret | |
484 | self._compare_ok(id_, expected, given=response.body) |
|
484 | self._compare_ok(id_, expected, given=response.body) | |
485 |
|
485 | |||
486 | def test_api_update_user_no_changed_params(self): |
|
486 | def test_api_update_user_no_changed_params(self): | |
487 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
487 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
488 | ret = jsonify(usr.get_api_data()) |
|
488 | ret = jsonify(usr.get_api_data()) | |
489 | id_, params = _build_data(self.apikey, 'update_user', |
|
489 | id_, params = _build_data(self.apikey, 'update_user', | |
490 | userid=TEST_USER_ADMIN_LOGIN) |
|
490 | userid=TEST_USER_ADMIN_LOGIN) | |
491 |
|
491 | |||
492 | response = api_call(self, params) |
|
492 | response = api_call(self, params) | |
493 | ret = { |
|
493 | ret = { | |
494 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), |
|
494 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), | |
495 | 'user': ret |
|
495 | 'user': ret | |
496 | } |
|
496 | } | |
497 | expected = ret |
|
497 | expected = ret | |
498 | self._compare_ok(id_, expected, given=response.body) |
|
498 | self._compare_ok(id_, expected, given=response.body) | |
499 |
|
499 | |||
500 | def test_api_update_user_by_user_id(self): |
|
500 | def test_api_update_user_by_user_id(self): | |
501 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
501 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
502 | ret = jsonify(usr.get_api_data()) |
|
502 | ret = jsonify(usr.get_api_data()) | |
503 | id_, params = _build_data(self.apikey, 'update_user', |
|
503 | id_, params = _build_data(self.apikey, 'update_user', | |
504 | userid=usr.user_id) |
|
504 | userid=usr.user_id) | |
505 |
|
505 | |||
506 | response = api_call(self, params) |
|
506 | response = api_call(self, params) | |
507 | ret = { |
|
507 | ret = { | |
508 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), |
|
508 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), | |
509 | 'user': ret |
|
509 | 'user': ret | |
510 | } |
|
510 | } | |
511 | expected = ret |
|
511 | expected = ret | |
512 | self._compare_ok(id_, expected, given=response.body) |
|
512 | self._compare_ok(id_, expected, given=response.body) | |
513 |
|
513 | |||
514 | @mock.patch.object(UserModel, 'update_user', crash) |
|
514 | @mock.patch.object(UserModel, 'update_user', crash) | |
515 | def test_api_update_user_when_exception_happens(self): |
|
515 | def test_api_update_user_when_exception_happens(self): | |
516 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
516 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
517 | ret = jsonify(usr.get_api_data()) |
|
517 | ret = jsonify(usr.get_api_data()) | |
518 | id_, params = _build_data(self.apikey, 'update_user', |
|
518 | id_, params = _build_data(self.apikey, 'update_user', | |
519 | userid=usr.user_id) |
|
519 | userid=usr.user_id) | |
520 |
|
520 | |||
521 | response = api_call(self, params) |
|
521 | response = api_call(self, params) | |
522 | ret = 'failed to update user `%s`' % usr.user_id |
|
522 | ret = 'failed to update user `%s`' % usr.user_id | |
523 |
|
523 | |||
524 | expected = ret |
|
524 | expected = ret | |
525 | self._compare_error(id_, expected, given=response.body) |
|
525 | self._compare_error(id_, expected, given=response.body) | |
526 |
|
526 | |||
527 | def test_api_get_repo(self): |
|
527 | def test_api_get_repo(self): | |
528 | new_group = 'some_new_group' |
|
528 | new_group = 'some_new_group' | |
529 | make_users_group(new_group) |
|
529 | make_users_group(new_group) | |
530 | RepoModel().grant_users_group_permission(repo=self.REPO, |
|
530 | RepoModel().grant_users_group_permission(repo=self.REPO, | |
531 | group_name=new_group, |
|
531 | group_name=new_group, | |
532 | perm='repository.read') |
|
532 | perm='repository.read') | |
533 | Session().commit() |
|
533 | Session().commit() | |
534 | id_, params = _build_data(self.apikey, 'get_repo', |
|
534 | id_, params = _build_data(self.apikey, 'get_repo', | |
535 | repoid=self.REPO) |
|
535 | repoid=self.REPO) | |
536 | response = api_call(self, params) |
|
536 | response = api_call(self, params) | |
537 |
|
537 | |||
538 | repo = RepoModel().get_by_repo_name(self.REPO) |
|
538 | repo = RepoModel().get_by_repo_name(self.REPO) | |
539 | ret = repo.get_api_data() |
|
539 | ret = repo.get_api_data() | |
540 |
|
540 | |||
541 | members = [] |
|
541 | members = [] | |
|
542 | followers = [] | |||
542 | for user in repo.repo_to_perm: |
|
543 | for user in repo.repo_to_perm: | |
543 | perm = user.permission.permission_name |
|
544 | perm = user.permission.permission_name | |
544 | user = user.user |
|
545 | user = user.user | |
545 | user_data = user.get_api_data() |
|
546 | user_data = user.get_api_data() | |
546 | user_data['type'] = "user" |
|
547 | user_data['type'] = "user" | |
547 | user_data['permission'] = perm |
|
548 | user_data['permission'] = perm | |
548 | members.append(user_data) |
|
549 | members.append(user_data) | |
549 |
|
550 | |||
550 | for users_group in repo.users_group_to_perm: |
|
551 | for users_group in repo.users_group_to_perm: | |
551 | perm = users_group.permission.permission_name |
|
552 | perm = users_group.permission.permission_name | |
552 | users_group = users_group.users_group |
|
553 | users_group = users_group.users_group | |
553 | users_group_data = users_group.get_api_data() |
|
554 | users_group_data = users_group.get_api_data() | |
554 | users_group_data['type'] = "users_group" |
|
555 | users_group_data['type'] = "users_group" | |
555 | users_group_data['permission'] = perm |
|
556 | users_group_data['permission'] = perm | |
556 | members.append(users_group_data) |
|
557 | members.append(users_group_data) | |
557 |
|
558 | |||
|
559 | for user in repo.followers: | |||
|
560 | followers.append(user.user.get_api_data()) | |||
|
561 | ||||
558 | ret['members'] = members |
|
562 | ret['members'] = members | |
|
563 | ret['followers'] = followers | |||
559 |
|
564 | |||
560 | expected = ret |
|
565 | expected = ret | |
561 | self._compare_ok(id_, expected, given=response.body) |
|
566 | self._compare_ok(id_, expected, given=response.body) | |
562 | destroy_users_group(new_group) |
|
567 | destroy_users_group(new_group) | |
563 |
|
568 | |||
564 | def test_api_get_repo_by_non_admin(self): |
|
569 | def test_api_get_repo_by_non_admin(self): | |
565 | id_, params = _build_data(self.apikey, 'get_repo', |
|
570 | id_, params = _build_data(self.apikey, 'get_repo', | |
566 | repoid=self.REPO) |
|
571 | repoid=self.REPO) | |
567 | response = api_call(self, params) |
|
572 | response = api_call(self, params) | |
568 |
|
573 | |||
569 | repo = RepoModel().get_by_repo_name(self.REPO) |
|
574 | repo = RepoModel().get_by_repo_name(self.REPO) | |
570 | ret = repo.get_api_data() |
|
575 | ret = repo.get_api_data() | |
571 |
|
576 | |||
572 | members = [] |
|
577 | members = [] | |
|
578 | followers = [] | |||
573 | for user in repo.repo_to_perm: |
|
579 | for user in repo.repo_to_perm: | |
574 | perm = user.permission.permission_name |
|
580 | perm = user.permission.permission_name | |
575 | user = user.user |
|
581 | user = user.user | |
576 | user_data = user.get_api_data() |
|
582 | user_data = user.get_api_data() | |
577 | user_data['type'] = "user" |
|
583 | user_data['type'] = "user" | |
578 | user_data['permission'] = perm |
|
584 | user_data['permission'] = perm | |
579 | members.append(user_data) |
|
585 | members.append(user_data) | |
580 |
|
586 | |||
581 | for users_group in repo.users_group_to_perm: |
|
587 | for users_group in repo.users_group_to_perm: | |
582 | perm = users_group.permission.permission_name |
|
588 | perm = users_group.permission.permission_name | |
583 | users_group = users_group.users_group |
|
589 | users_group = users_group.users_group | |
584 | users_group_data = users_group.get_api_data() |
|
590 | users_group_data = users_group.get_api_data() | |
585 | users_group_data['type'] = "users_group" |
|
591 | users_group_data['type'] = "users_group" | |
586 | users_group_data['permission'] = perm |
|
592 | users_group_data['permission'] = perm | |
587 | members.append(users_group_data) |
|
593 | members.append(users_group_data) | |
588 |
|
594 | |||
|
595 | for user in repo.followers: | |||
|
596 | followers.append(user.user.get_api_data()) | |||
|
597 | ||||
589 | ret['members'] = members |
|
598 | ret['members'] = members | |
|
599 | ret['followers'] = followers | |||
590 |
|
600 | |||
591 | expected = ret |
|
601 | expected = ret | |
592 | self._compare_ok(id_, expected, given=response.body) |
|
602 | self._compare_ok(id_, expected, given=response.body) | |
593 |
|
603 | |||
594 | def test_api_get_repo_by_non_admin_no_permission_to_repo(self): |
|
604 | def test_api_get_repo_by_non_admin_no_permission_to_repo(self): | |
595 | RepoModel().grant_user_permission(repo=self.REPO, |
|
605 | RepoModel().grant_user_permission(repo=self.REPO, | |
596 | user=self.TEST_USER_LOGIN, |
|
606 | user=self.TEST_USER_LOGIN, | |
597 | perm='repository.none') |
|
607 | perm='repository.none') | |
598 |
|
608 | |||
599 | id_, params = _build_data(self.apikey_regular, 'get_repo', |
|
609 | id_, params = _build_data(self.apikey_regular, 'get_repo', | |
600 | repoid=self.REPO) |
|
610 | repoid=self.REPO) | |
601 | response = api_call(self, params) |
|
611 | response = api_call(self, params) | |
602 |
|
612 | |||
603 | expected = 'repository `%s` does not exist' % (self.REPO) |
|
613 | expected = 'repository `%s` does not exist' % (self.REPO) | |
604 | self._compare_error(id_, expected, given=response.body) |
|
614 | self._compare_error(id_, expected, given=response.body) | |
605 |
|
615 | |||
606 | def test_api_get_repo_that_doesn_not_exist(self): |
|
616 | def test_api_get_repo_that_doesn_not_exist(self): | |
607 | id_, params = _build_data(self.apikey, 'get_repo', |
|
617 | id_, params = _build_data(self.apikey, 'get_repo', | |
608 | repoid='no-such-repo') |
|
618 | repoid='no-such-repo') | |
609 | response = api_call(self, params) |
|
619 | response = api_call(self, params) | |
610 |
|
620 | |||
611 | ret = 'repository `%s` does not exist' % 'no-such-repo' |
|
621 | ret = 'repository `%s` does not exist' % 'no-such-repo' | |
612 | expected = ret |
|
622 | expected = ret | |
613 | self._compare_error(id_, expected, given=response.body) |
|
623 | self._compare_error(id_, expected, given=response.body) | |
614 |
|
624 | |||
615 | def test_api_get_repos(self): |
|
625 | def test_api_get_repos(self): | |
616 | id_, params = _build_data(self.apikey, 'get_repos') |
|
626 | id_, params = _build_data(self.apikey, 'get_repos') | |
617 | response = api_call(self, params) |
|
627 | response = api_call(self, params) | |
618 |
|
628 | |||
619 | result = [] |
|
629 | result = [] | |
620 | for repo in RepoModel().get_all(): |
|
630 | for repo in RepoModel().get_all(): | |
621 | result.append(repo.get_api_data()) |
|
631 | result.append(repo.get_api_data()) | |
622 | ret = jsonify(result) |
|
632 | ret = jsonify(result) | |
623 |
|
633 | |||
624 | expected = ret |
|
634 | expected = ret | |
625 | self._compare_ok(id_, expected, given=response.body) |
|
635 | self._compare_ok(id_, expected, given=response.body) | |
626 |
|
636 | |||
627 | def test_api_get_repos_non_admin(self): |
|
637 | def test_api_get_repos_non_admin(self): | |
628 | id_, params = _build_data(self.apikey_regular, 'get_repos') |
|
638 | id_, params = _build_data(self.apikey_regular, 'get_repos') | |
629 | response = api_call(self, params) |
|
639 | response = api_call(self, params) | |
630 |
|
640 | |||
631 | result = [] |
|
641 | result = [] | |
632 | for repo in RepoModel().get_all_user_repos(self.TEST_USER_LOGIN): |
|
642 | for repo in RepoModel().get_all_user_repos(self.TEST_USER_LOGIN): | |
633 | result.append(repo.get_api_data()) |
|
643 | result.append(repo.get_api_data()) | |
634 | ret = jsonify(result) |
|
644 | ret = jsonify(result) | |
635 |
|
645 | |||
636 | expected = ret |
|
646 | expected = ret | |
637 | self._compare_ok(id_, expected, given=response.body) |
|
647 | self._compare_ok(id_, expected, given=response.body) | |
638 |
|
648 | |||
639 | @parameterized.expand([('all', 'all'), |
|
649 | @parameterized.expand([('all', 'all'), | |
640 | ('dirs', 'dirs'), |
|
650 | ('dirs', 'dirs'), | |
641 | ('files', 'files'), ]) |
|
651 | ('files', 'files'), ]) | |
642 | def test_api_get_repo_nodes(self, name, ret_type): |
|
652 | def test_api_get_repo_nodes(self, name, ret_type): | |
643 | rev = 'tip' |
|
653 | rev = 'tip' | |
644 | path = '/' |
|
654 | path = '/' | |
645 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
655 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
646 | repoid=self.REPO, revision=rev, |
|
656 | repoid=self.REPO, revision=rev, | |
647 | root_path=path, |
|
657 | root_path=path, | |
648 | ret_type=ret_type) |
|
658 | ret_type=ret_type) | |
649 | response = api_call(self, params) |
|
659 | response = api_call(self, params) | |
650 |
|
660 | |||
651 | # we don't the actual return types here since it's tested somewhere |
|
661 | # we don't the actual return types here since it's tested somewhere | |
652 | # else |
|
662 | # else | |
653 | expected = json.loads(response.body)['result'] |
|
663 | expected = json.loads(response.body)['result'] | |
654 | self._compare_ok(id_, expected, given=response.body) |
|
664 | self._compare_ok(id_, expected, given=response.body) | |
655 |
|
665 | |||
656 | def test_api_get_repo_nodes_bad_revisions(self): |
|
666 | def test_api_get_repo_nodes_bad_revisions(self): | |
657 | rev = 'i-dont-exist' |
|
667 | rev = 'i-dont-exist' | |
658 | path = '/' |
|
668 | path = '/' | |
659 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
669 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
660 | repoid=self.REPO, revision=rev, |
|
670 | repoid=self.REPO, revision=rev, | |
661 | root_path=path,) |
|
671 | root_path=path,) | |
662 | response = api_call(self, params) |
|
672 | response = api_call(self, params) | |
663 |
|
673 | |||
664 | expected = 'failed to get repo: `%s` nodes' % self.REPO |
|
674 | expected = 'failed to get repo: `%s` nodes' % self.REPO | |
665 | self._compare_error(id_, expected, given=response.body) |
|
675 | self._compare_error(id_, expected, given=response.body) | |
666 |
|
676 | |||
667 | def test_api_get_repo_nodes_bad_path(self): |
|
677 | def test_api_get_repo_nodes_bad_path(self): | |
668 | rev = 'tip' |
|
678 | rev = 'tip' | |
669 | path = '/idontexits' |
|
679 | path = '/idontexits' | |
670 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
680 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
671 | repoid=self.REPO, revision=rev, |
|
681 | repoid=self.REPO, revision=rev, | |
672 | root_path=path,) |
|
682 | root_path=path,) | |
673 | response = api_call(self, params) |
|
683 | response = api_call(self, params) | |
674 |
|
684 | |||
675 | expected = 'failed to get repo: `%s` nodes' % self.REPO |
|
685 | expected = 'failed to get repo: `%s` nodes' % self.REPO | |
676 | self._compare_error(id_, expected, given=response.body) |
|
686 | self._compare_error(id_, expected, given=response.body) | |
677 |
|
687 | |||
678 | def test_api_get_repo_nodes_bad_ret_type(self): |
|
688 | def test_api_get_repo_nodes_bad_ret_type(self): | |
679 | rev = 'tip' |
|
689 | rev = 'tip' | |
680 | path = '/' |
|
690 | path = '/' | |
681 | ret_type = 'error' |
|
691 | ret_type = 'error' | |
682 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
692 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
683 | repoid=self.REPO, revision=rev, |
|
693 | repoid=self.REPO, revision=rev, | |
684 | root_path=path, |
|
694 | root_path=path, | |
685 | ret_type=ret_type) |
|
695 | ret_type=ret_type) | |
686 | response = api_call(self, params) |
|
696 | response = api_call(self, params) | |
687 |
|
697 | |||
688 | expected = 'ret_type must be one of %s' % (['files', 'dirs', 'all']) |
|
698 | expected = 'ret_type must be one of %s' % (['files', 'dirs', 'all']) | |
689 | self._compare_error(id_, expected, given=response.body) |
|
699 | self._compare_error(id_, expected, given=response.body) | |
690 |
|
700 | |||
691 | def test_api_create_repo(self): |
|
701 | def test_api_create_repo(self): | |
692 | repo_name = 'api-repo' |
|
702 | repo_name = 'api-repo' | |
693 | id_, params = _build_data(self.apikey, 'create_repo', |
|
703 | id_, params = _build_data(self.apikey, 'create_repo', | |
694 | repo_name=repo_name, |
|
704 | repo_name=repo_name, | |
695 | owner=TEST_USER_ADMIN_LOGIN, |
|
705 | owner=TEST_USER_ADMIN_LOGIN, | |
696 | repo_type='hg', |
|
706 | repo_type='hg', | |
697 | ) |
|
707 | ) | |
698 | response = api_call(self, params) |
|
708 | response = api_call(self, params) | |
699 |
|
709 | |||
700 | repo = RepoModel().get_by_repo_name(repo_name) |
|
710 | repo = RepoModel().get_by_repo_name(repo_name) | |
701 | ret = { |
|
711 | ret = { | |
702 | 'msg': 'Created new repository `%s`' % repo_name, |
|
712 | 'msg': 'Created new repository `%s`' % repo_name, | |
703 | 'repo': jsonify(repo.get_api_data()) |
|
713 | 'repo': jsonify(repo.get_api_data()) | |
704 | } |
|
714 | } | |
705 | expected = ret |
|
715 | expected = ret | |
706 | self._compare_ok(id_, expected, given=response.body) |
|
716 | self._compare_ok(id_, expected, given=response.body) | |
707 | destroy_repo(repo_name) |
|
717 | destroy_repo(repo_name) | |
708 |
|
718 | |||
709 | def test_api_create_repo_unknown_owner(self): |
|
719 | def test_api_create_repo_unknown_owner(self): | |
710 | repo_name = 'api-repo' |
|
720 | repo_name = 'api-repo' | |
711 | owner = 'i-dont-exist' |
|
721 | owner = 'i-dont-exist' | |
712 | id_, params = _build_data(self.apikey, 'create_repo', |
|
722 | id_, params = _build_data(self.apikey, 'create_repo', | |
713 | repo_name=repo_name, |
|
723 | repo_name=repo_name, | |
714 | owner=owner, |
|
724 | owner=owner, | |
715 | repo_type='hg', |
|
725 | repo_type='hg', | |
716 | ) |
|
726 | ) | |
717 | response = api_call(self, params) |
|
727 | response = api_call(self, params) | |
718 | expected = 'user `%s` does not exist' % owner |
|
728 | expected = 'user `%s` does not exist' % owner | |
719 | self._compare_error(id_, expected, given=response.body) |
|
729 | self._compare_error(id_, expected, given=response.body) | |
720 |
|
730 | |||
721 | def test_api_create_repo_dont_specify_owner(self): |
|
731 | def test_api_create_repo_dont_specify_owner(self): | |
722 | repo_name = 'api-repo' |
|
732 | repo_name = 'api-repo' | |
723 | owner = 'i-dont-exist' |
|
733 | owner = 'i-dont-exist' | |
724 | id_, params = _build_data(self.apikey, 'create_repo', |
|
734 | id_, params = _build_data(self.apikey, 'create_repo', | |
725 | repo_name=repo_name, |
|
735 | repo_name=repo_name, | |
726 | repo_type='hg', |
|
736 | repo_type='hg', | |
727 | ) |
|
737 | ) | |
728 | response = api_call(self, params) |
|
738 | response = api_call(self, params) | |
729 |
|
739 | |||
730 | repo = RepoModel().get_by_repo_name(repo_name) |
|
740 | repo = RepoModel().get_by_repo_name(repo_name) | |
731 | ret = { |
|
741 | ret = { | |
732 | 'msg': 'Created new repository `%s`' % repo_name, |
|
742 | 'msg': 'Created new repository `%s`' % repo_name, | |
733 | 'repo': jsonify(repo.get_api_data()) |
|
743 | 'repo': jsonify(repo.get_api_data()) | |
734 | } |
|
744 | } | |
735 | expected = ret |
|
745 | expected = ret | |
736 | self._compare_ok(id_, expected, given=response.body) |
|
746 | self._compare_ok(id_, expected, given=response.body) | |
737 | destroy_repo(repo_name) |
|
747 | destroy_repo(repo_name) | |
738 |
|
748 | |||
739 | def test_api_create_repo_by_non_admin(self): |
|
749 | def test_api_create_repo_by_non_admin(self): | |
740 | repo_name = 'api-repo' |
|
750 | repo_name = 'api-repo' | |
741 | owner = 'i-dont-exist' |
|
751 | owner = 'i-dont-exist' | |
742 | id_, params = _build_data(self.apikey_regular, 'create_repo', |
|
752 | id_, params = _build_data(self.apikey_regular, 'create_repo', | |
743 | repo_name=repo_name, |
|
753 | repo_name=repo_name, | |
744 | repo_type='hg', |
|
754 | repo_type='hg', | |
745 | ) |
|
755 | ) | |
746 | response = api_call(self, params) |
|
756 | response = api_call(self, params) | |
747 |
|
757 | |||
748 | repo = RepoModel().get_by_repo_name(repo_name) |
|
758 | repo = RepoModel().get_by_repo_name(repo_name) | |
749 | ret = { |
|
759 | ret = { | |
750 | 'msg': 'Created new repository `%s`' % repo_name, |
|
760 | 'msg': 'Created new repository `%s`' % repo_name, | |
751 | 'repo': jsonify(repo.get_api_data()) |
|
761 | 'repo': jsonify(repo.get_api_data()) | |
752 | } |
|
762 | } | |
753 | expected = ret |
|
763 | expected = ret | |
754 | self._compare_ok(id_, expected, given=response.body) |
|
764 | self._compare_ok(id_, expected, given=response.body) | |
755 | destroy_repo(repo_name) |
|
765 | destroy_repo(repo_name) | |
756 |
|
766 | |||
757 | def test_api_create_repo_by_non_admin_specify_owner(self): |
|
767 | def test_api_create_repo_by_non_admin_specify_owner(self): | |
758 | repo_name = 'api-repo' |
|
768 | repo_name = 'api-repo' | |
759 | owner = 'i-dont-exist' |
|
769 | owner = 'i-dont-exist' | |
760 | id_, params = _build_data(self.apikey_regular, 'create_repo', |
|
770 | id_, params = _build_data(self.apikey_regular, 'create_repo', | |
761 | repo_name=repo_name, |
|
771 | repo_name=repo_name, | |
762 | repo_type='hg', |
|
772 | repo_type='hg', | |
763 | owner=owner |
|
773 | owner=owner | |
764 | ) |
|
774 | ) | |
765 | response = api_call(self, params) |
|
775 | response = api_call(self, params) | |
766 |
|
776 | |||
767 | expected = 'Only RhodeCode admin can specify `owner` param' |
|
777 | expected = 'Only RhodeCode admin can specify `owner` param' | |
768 | self._compare_error(id_, expected, given=response.body) |
|
778 | self._compare_error(id_, expected, given=response.body) | |
769 | destroy_repo(repo_name) |
|
779 | destroy_repo(repo_name) | |
770 |
|
780 | |||
771 | def test_api_create_repo_exists(self): |
|
781 | def test_api_create_repo_exists(self): | |
772 | repo_name = self.REPO |
|
782 | repo_name = self.REPO | |
773 | id_, params = _build_data(self.apikey, 'create_repo', |
|
783 | id_, params = _build_data(self.apikey, 'create_repo', | |
774 | repo_name=repo_name, |
|
784 | repo_name=repo_name, | |
775 | owner=TEST_USER_ADMIN_LOGIN, |
|
785 | owner=TEST_USER_ADMIN_LOGIN, | |
776 | repo_type='hg', |
|
786 | repo_type='hg', | |
777 | ) |
|
787 | ) | |
778 | response = api_call(self, params) |
|
788 | response = api_call(self, params) | |
779 | expected = "repo `%s` already exist" % repo_name |
|
789 | expected = "repo `%s` already exist" % repo_name | |
780 | self._compare_error(id_, expected, given=response.body) |
|
790 | self._compare_error(id_, expected, given=response.body) | |
781 |
|
791 | |||
782 | @mock.patch.object(RepoModel, 'create_repo', crash) |
|
792 | @mock.patch.object(RepoModel, 'create_repo', crash) | |
783 | def test_api_create_repo_exception_occurred(self): |
|
793 | def test_api_create_repo_exception_occurred(self): | |
784 | repo_name = 'api-repo' |
|
794 | repo_name = 'api-repo' | |
785 | id_, params = _build_data(self.apikey, 'create_repo', |
|
795 | id_, params = _build_data(self.apikey, 'create_repo', | |
786 | repo_name=repo_name, |
|
796 | repo_name=repo_name, | |
787 | owner=TEST_USER_ADMIN_LOGIN, |
|
797 | owner=TEST_USER_ADMIN_LOGIN, | |
788 | repo_type='hg', |
|
798 | repo_type='hg', | |
789 | ) |
|
799 | ) | |
790 | response = api_call(self, params) |
|
800 | response = api_call(self, params) | |
791 | expected = 'failed to create repository `%s`' % repo_name |
|
801 | expected = 'failed to create repository `%s`' % repo_name | |
792 | self._compare_error(id_, expected, given=response.body) |
|
802 | self._compare_error(id_, expected, given=response.body) | |
793 |
|
803 | |||
794 | def test_api_delete_repo(self): |
|
804 | def test_api_delete_repo(self): | |
795 | repo_name = 'api_delete_me' |
|
805 | repo_name = 'api_delete_me' | |
796 | create_repo(repo_name, self.REPO_TYPE) |
|
806 | create_repo(repo_name, self.REPO_TYPE) | |
797 |
|
807 | |||
798 | id_, params = _build_data(self.apikey, 'delete_repo', |
|
808 | id_, params = _build_data(self.apikey, 'delete_repo', | |
799 | repoid=repo_name,) |
|
809 | repoid=repo_name,) | |
800 | response = api_call(self, params) |
|
810 | response = api_call(self, params) | |
801 |
|
811 | |||
802 | ret = { |
|
812 | ret = { | |
803 | 'msg': 'Deleted repository `%s`' % repo_name, |
|
813 | 'msg': 'Deleted repository `%s`' % repo_name, | |
804 | 'success': True |
|
814 | 'success': True | |
805 | } |
|
815 | } | |
806 | expected = ret |
|
816 | expected = ret | |
807 | self._compare_ok(id_, expected, given=response.body) |
|
817 | self._compare_ok(id_, expected, given=response.body) | |
808 |
|
818 | |||
809 | def test_api_delete_repo_by_non_admin(self): |
|
819 | def test_api_delete_repo_by_non_admin(self): | |
810 | repo_name = 'api_delete_me' |
|
820 | repo_name = 'api_delete_me' | |
811 | create_repo(repo_name, self.REPO_TYPE, owner=self.TEST_USER_LOGIN) |
|
821 | create_repo(repo_name, self.REPO_TYPE, owner=self.TEST_USER_LOGIN) | |
812 | try: |
|
822 | try: | |
813 | id_, params = _build_data(self.apikey_regular, 'delete_repo', |
|
823 | id_, params = _build_data(self.apikey_regular, 'delete_repo', | |
814 | repoid=repo_name,) |
|
824 | repoid=repo_name,) | |
815 | response = api_call(self, params) |
|
825 | response = api_call(self, params) | |
816 |
|
826 | |||
817 | ret = { |
|
827 | ret = { | |
818 | 'msg': 'Deleted repository `%s`' % repo_name, |
|
828 | 'msg': 'Deleted repository `%s`' % repo_name, | |
819 | 'success': True |
|
829 | 'success': True | |
820 | } |
|
830 | } | |
821 | expected = ret |
|
831 | expected = ret | |
822 | self._compare_ok(id_, expected, given=response.body) |
|
832 | self._compare_ok(id_, expected, given=response.body) | |
823 | finally: |
|
833 | finally: | |
824 | destroy_repo(repo_name) |
|
834 | destroy_repo(repo_name) | |
825 |
|
835 | |||
826 | def test_api_delete_repo_by_non_admin_no_permission(self): |
|
836 | def test_api_delete_repo_by_non_admin_no_permission(self): | |
827 | repo_name = 'api_delete_me' |
|
837 | repo_name = 'api_delete_me' | |
828 | create_repo(repo_name, self.REPO_TYPE) |
|
838 | create_repo(repo_name, self.REPO_TYPE) | |
829 | try: |
|
839 | try: | |
830 | id_, params = _build_data(self.apikey_regular, 'delete_repo', |
|
840 | id_, params = _build_data(self.apikey_regular, 'delete_repo', | |
831 | repoid=repo_name,) |
|
841 | repoid=repo_name,) | |
832 | response = api_call(self, params) |
|
842 | response = api_call(self, params) | |
833 | expected = 'repository `%s` does not exist' % (repo_name) |
|
843 | expected = 'repository `%s` does not exist' % (repo_name) | |
834 | self._compare_error(id_, expected, given=response.body) |
|
844 | self._compare_error(id_, expected, given=response.body) | |
835 | finally: |
|
845 | finally: | |
836 | destroy_repo(repo_name) |
|
846 | destroy_repo(repo_name) | |
837 |
|
847 | |||
838 | def test_api_delete_repo_exception_occurred(self): |
|
848 | def test_api_delete_repo_exception_occurred(self): | |
839 | repo_name = 'api_delete_me' |
|
849 | repo_name = 'api_delete_me' | |
840 | create_repo(repo_name, self.REPO_TYPE) |
|
850 | create_repo(repo_name, self.REPO_TYPE) | |
841 | try: |
|
851 | try: | |
842 | with mock.patch.object(RepoModel, 'delete', crash): |
|
852 | with mock.patch.object(RepoModel, 'delete', crash): | |
843 | id_, params = _build_data(self.apikey, 'delete_repo', |
|
853 | id_, params = _build_data(self.apikey, 'delete_repo', | |
844 | repoid=repo_name,) |
|
854 | repoid=repo_name,) | |
845 | response = api_call(self, params) |
|
855 | response = api_call(self, params) | |
846 |
|
856 | |||
847 | expected = 'failed to delete repository `%s`' % repo_name |
|
857 | expected = 'failed to delete repository `%s`' % repo_name | |
848 | self._compare_error(id_, expected, given=response.body) |
|
858 | self._compare_error(id_, expected, given=response.body) | |
849 | finally: |
|
859 | finally: | |
850 | destroy_repo(repo_name) |
|
860 | destroy_repo(repo_name) | |
851 |
|
861 | |||
852 | def test_api_fork_repo(self): |
|
862 | def test_api_fork_repo(self): | |
853 | fork_name = 'api-repo-fork' |
|
863 | fork_name = 'api-repo-fork' | |
854 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
864 | id_, params = _build_data(self.apikey, 'fork_repo', | |
855 | repoid=self.REPO, |
|
865 | repoid=self.REPO, | |
856 | fork_name=fork_name, |
|
866 | fork_name=fork_name, | |
857 | owner=TEST_USER_ADMIN_LOGIN, |
|
867 | owner=TEST_USER_ADMIN_LOGIN, | |
858 | ) |
|
868 | ) | |
859 | response = api_call(self, params) |
|
869 | response = api_call(self, params) | |
860 |
|
870 | |||
861 | ret = { |
|
871 | ret = { | |
862 | 'msg': 'Created fork of `%s` as `%s`' % (self.REPO, |
|
872 | 'msg': 'Created fork of `%s` as `%s`' % (self.REPO, | |
863 | fork_name), |
|
873 | fork_name), | |
864 | 'success': True |
|
874 | 'success': True | |
865 | } |
|
875 | } | |
866 | expected = ret |
|
876 | expected = ret | |
867 | self._compare_ok(id_, expected, given=response.body) |
|
877 | self._compare_ok(id_, expected, given=response.body) | |
868 | destroy_repo(fork_name) |
|
878 | destroy_repo(fork_name) | |
869 |
|
879 | |||
870 | def test_api_fork_repo_non_admin(self): |
|
880 | def test_api_fork_repo_non_admin(self): | |
871 | fork_name = 'api-repo-fork' |
|
881 | fork_name = 'api-repo-fork' | |
872 | id_, params = _build_data(self.apikey_regular, 'fork_repo', |
|
882 | id_, params = _build_data(self.apikey_regular, 'fork_repo', | |
873 | repoid=self.REPO, |
|
883 | repoid=self.REPO, | |
874 | fork_name=fork_name, |
|
884 | fork_name=fork_name, | |
875 | ) |
|
885 | ) | |
876 | response = api_call(self, params) |
|
886 | response = api_call(self, params) | |
877 |
|
887 | |||
878 | ret = { |
|
888 | ret = { | |
879 | 'msg': 'Created fork of `%s` as `%s`' % (self.REPO, |
|
889 | 'msg': 'Created fork of `%s` as `%s`' % (self.REPO, | |
880 | fork_name), |
|
890 | fork_name), | |
881 | 'success': True |
|
891 | 'success': True | |
882 | } |
|
892 | } | |
883 | expected = ret |
|
893 | expected = ret | |
884 | self._compare_ok(id_, expected, given=response.body) |
|
894 | self._compare_ok(id_, expected, given=response.body) | |
885 | destroy_repo(fork_name) |
|
895 | destroy_repo(fork_name) | |
886 |
|
896 | |||
887 | def test_api_fork_repo_non_admin_specify_owner(self): |
|
897 | def test_api_fork_repo_non_admin_specify_owner(self): | |
888 | fork_name = 'api-repo-fork' |
|
898 | fork_name = 'api-repo-fork' | |
889 | id_, params = _build_data(self.apikey_regular, 'fork_repo', |
|
899 | id_, params = _build_data(self.apikey_regular, 'fork_repo', | |
890 | repoid=self.REPO, |
|
900 | repoid=self.REPO, | |
891 | fork_name=fork_name, |
|
901 | fork_name=fork_name, | |
892 | owner=TEST_USER_ADMIN_LOGIN, |
|
902 | owner=TEST_USER_ADMIN_LOGIN, | |
893 | ) |
|
903 | ) | |
894 | response = api_call(self, params) |
|
904 | response = api_call(self, params) | |
895 | expected = 'Only RhodeCode admin can specify `owner` param' |
|
905 | expected = 'Only RhodeCode admin can specify `owner` param' | |
896 | self._compare_error(id_, expected, given=response.body) |
|
906 | self._compare_error(id_, expected, given=response.body) | |
897 | destroy_repo(fork_name) |
|
907 | destroy_repo(fork_name) | |
898 |
|
908 | |||
899 | def test_api_fork_repo_non_admin_no_permission_to_fork(self): |
|
909 | def test_api_fork_repo_non_admin_no_permission_to_fork(self): | |
900 | RepoModel().grant_user_permission(repo=self.REPO, |
|
910 | RepoModel().grant_user_permission(repo=self.REPO, | |
901 | user=self.TEST_USER_LOGIN, |
|
911 | user=self.TEST_USER_LOGIN, | |
902 | perm='repository.none') |
|
912 | perm='repository.none') | |
903 | fork_name = 'api-repo-fork' |
|
913 | fork_name = 'api-repo-fork' | |
904 | id_, params = _build_data(self.apikey_regular, 'fork_repo', |
|
914 | id_, params = _build_data(self.apikey_regular, 'fork_repo', | |
905 | repoid=self.REPO, |
|
915 | repoid=self.REPO, | |
906 | fork_name=fork_name, |
|
916 | fork_name=fork_name, | |
907 | ) |
|
917 | ) | |
908 | response = api_call(self, params) |
|
918 | response = api_call(self, params) | |
909 | expected = 'repository `%s` does not exist' % (self.REPO) |
|
919 | expected = 'repository `%s` does not exist' % (self.REPO) | |
910 | self._compare_error(id_, expected, given=response.body) |
|
920 | self._compare_error(id_, expected, given=response.body) | |
911 | destroy_repo(fork_name) |
|
921 | destroy_repo(fork_name) | |
912 |
|
922 | |||
913 | def test_api_fork_repo_unknown_owner(self): |
|
923 | def test_api_fork_repo_unknown_owner(self): | |
914 | fork_name = 'api-repo-fork' |
|
924 | fork_name = 'api-repo-fork' | |
915 | owner = 'i-dont-exist' |
|
925 | owner = 'i-dont-exist' | |
916 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
926 | id_, params = _build_data(self.apikey, 'fork_repo', | |
917 | repoid=self.REPO, |
|
927 | repoid=self.REPO, | |
918 | fork_name=fork_name, |
|
928 | fork_name=fork_name, | |
919 | owner=owner, |
|
929 | owner=owner, | |
920 | ) |
|
930 | ) | |
921 | response = api_call(self, params) |
|
931 | response = api_call(self, params) | |
922 | expected = 'user `%s` does not exist' % owner |
|
932 | expected = 'user `%s` does not exist' % owner | |
923 | self._compare_error(id_, expected, given=response.body) |
|
933 | self._compare_error(id_, expected, given=response.body) | |
924 |
|
934 | |||
925 | def test_api_fork_repo_fork_exists(self): |
|
935 | def test_api_fork_repo_fork_exists(self): | |
926 | fork_name = 'api-repo-fork' |
|
936 | fork_name = 'api-repo-fork' | |
927 | create_fork(fork_name, self.REPO_TYPE, self.REPO) |
|
937 | create_fork(fork_name, self.REPO_TYPE, self.REPO) | |
928 |
|
938 | |||
929 | try: |
|
939 | try: | |
930 | fork_name = 'api-repo-fork' |
|
940 | fork_name = 'api-repo-fork' | |
931 |
|
941 | |||
932 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
942 | id_, params = _build_data(self.apikey, 'fork_repo', | |
933 | repoid=self.REPO, |
|
943 | repoid=self.REPO, | |
934 | fork_name=fork_name, |
|
944 | fork_name=fork_name, | |
935 | owner=TEST_USER_ADMIN_LOGIN, |
|
945 | owner=TEST_USER_ADMIN_LOGIN, | |
936 | ) |
|
946 | ) | |
937 | response = api_call(self, params) |
|
947 | response = api_call(self, params) | |
938 |
|
948 | |||
939 | expected = "fork `%s` already exist" % fork_name |
|
949 | expected = "fork `%s` already exist" % fork_name | |
940 | self._compare_error(id_, expected, given=response.body) |
|
950 | self._compare_error(id_, expected, given=response.body) | |
941 | finally: |
|
951 | finally: | |
942 | destroy_repo(fork_name) |
|
952 | destroy_repo(fork_name) | |
943 |
|
953 | |||
944 | def test_api_fork_repo_repo_exists(self): |
|
954 | def test_api_fork_repo_repo_exists(self): | |
945 | fork_name = self.REPO |
|
955 | fork_name = self.REPO | |
946 |
|
956 | |||
947 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
957 | id_, params = _build_data(self.apikey, 'fork_repo', | |
948 | repoid=self.REPO, |
|
958 | repoid=self.REPO, | |
949 | fork_name=fork_name, |
|
959 | fork_name=fork_name, | |
950 | owner=TEST_USER_ADMIN_LOGIN, |
|
960 | owner=TEST_USER_ADMIN_LOGIN, | |
951 | ) |
|
961 | ) | |
952 | response = api_call(self, params) |
|
962 | response = api_call(self, params) | |
953 |
|
963 | |||
954 | expected = "repo `%s` already exist" % fork_name |
|
964 | expected = "repo `%s` already exist" % fork_name | |
955 | self._compare_error(id_, expected, given=response.body) |
|
965 | self._compare_error(id_, expected, given=response.body) | |
956 |
|
966 | |||
957 | @mock.patch.object(RepoModel, 'create_fork', crash) |
|
967 | @mock.patch.object(RepoModel, 'create_fork', crash) | |
958 | def test_api_fork_repo_exception_occurred(self): |
|
968 | def test_api_fork_repo_exception_occurred(self): | |
959 | fork_name = 'api-repo-fork' |
|
969 | fork_name = 'api-repo-fork' | |
960 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
970 | id_, params = _build_data(self.apikey, 'fork_repo', | |
961 | repoid=self.REPO, |
|
971 | repoid=self.REPO, | |
962 | fork_name=fork_name, |
|
972 | fork_name=fork_name, | |
963 | owner=TEST_USER_ADMIN_LOGIN, |
|
973 | owner=TEST_USER_ADMIN_LOGIN, | |
964 | ) |
|
974 | ) | |
965 | response = api_call(self, params) |
|
975 | response = api_call(self, params) | |
966 |
|
976 | |||
967 | expected = 'failed to fork repository `%s` as `%s`' % (self.REPO, |
|
977 | expected = 'failed to fork repository `%s` as `%s`' % (self.REPO, | |
968 | fork_name) |
|
978 | fork_name) | |
969 | self._compare_error(id_, expected, given=response.body) |
|
979 | self._compare_error(id_, expected, given=response.body) | |
970 |
|
980 | |||
971 | def test_api_get_users_group(self): |
|
981 | def test_api_get_users_group(self): | |
972 | id_, params = _build_data(self.apikey, 'get_users_group', |
|
982 | id_, params = _build_data(self.apikey, 'get_users_group', | |
973 | usersgroupid=TEST_USERS_GROUP) |
|
983 | usersgroupid=TEST_USERS_GROUP) | |
974 | response = api_call(self, params) |
|
984 | response = api_call(self, params) | |
975 |
|
985 | |||
976 | users_group = UsersGroupModel().get_group(TEST_USERS_GROUP) |
|
986 | users_group = UsersGroupModel().get_group(TEST_USERS_GROUP) | |
977 | members = [] |
|
987 | members = [] | |
978 | for user in users_group.members: |
|
988 | for user in users_group.members: | |
979 | user = user.user |
|
989 | user = user.user | |
980 | members.append(user.get_api_data()) |
|
990 | members.append(user.get_api_data()) | |
981 |
|
991 | |||
982 | ret = users_group.get_api_data() |
|
992 | ret = users_group.get_api_data() | |
983 | ret['members'] = members |
|
993 | ret['members'] = members | |
984 | expected = ret |
|
994 | expected = ret | |
985 | self._compare_ok(id_, expected, given=response.body) |
|
995 | self._compare_ok(id_, expected, given=response.body) | |
986 |
|
996 | |||
987 | def test_api_get_users_groups(self): |
|
997 | def test_api_get_users_groups(self): | |
988 |
|
998 | |||
989 | make_users_group('test_users_group2') |
|
999 | make_users_group('test_users_group2') | |
990 |
|
1000 | |||
991 | id_, params = _build_data(self.apikey, 'get_users_groups',) |
|
1001 | id_, params = _build_data(self.apikey, 'get_users_groups',) | |
992 | response = api_call(self, params) |
|
1002 | response = api_call(self, params) | |
993 |
|
1003 | |||
994 | expected = [] |
|
1004 | expected = [] | |
995 | for gr_name in [TEST_USERS_GROUP, 'test_users_group2']: |
|
1005 | for gr_name in [TEST_USERS_GROUP, 'test_users_group2']: | |
996 | users_group = UsersGroupModel().get_group(gr_name) |
|
1006 | users_group = UsersGroupModel().get_group(gr_name) | |
997 | ret = users_group.get_api_data() |
|
1007 | ret = users_group.get_api_data() | |
998 | expected.append(ret) |
|
1008 | expected.append(ret) | |
999 | self._compare_ok(id_, expected, given=response.body) |
|
1009 | self._compare_ok(id_, expected, given=response.body) | |
1000 |
|
1010 | |||
1001 | UsersGroupModel().delete(users_group='test_users_group2') |
|
1011 | UsersGroupModel().delete(users_group='test_users_group2') | |
1002 | Session().commit() |
|
1012 | Session().commit() | |
1003 |
|
1013 | |||
1004 | def test_api_create_users_group(self): |
|
1014 | def test_api_create_users_group(self): | |
1005 | group_name = 'some_new_group' |
|
1015 | group_name = 'some_new_group' | |
1006 | id_, params = _build_data(self.apikey, 'create_users_group', |
|
1016 | id_, params = _build_data(self.apikey, 'create_users_group', | |
1007 | group_name=group_name) |
|
1017 | group_name=group_name) | |
1008 | response = api_call(self, params) |
|
1018 | response = api_call(self, params) | |
1009 |
|
1019 | |||
1010 | ret = { |
|
1020 | ret = { | |
1011 | 'msg': 'created new users group `%s`' % group_name, |
|
1021 | 'msg': 'created new users group `%s`' % group_name, | |
1012 | 'users_group': jsonify(UsersGroupModel()\ |
|
1022 | 'users_group': jsonify(UsersGroupModel()\ | |
1013 | .get_by_name(group_name)\ |
|
1023 | .get_by_name(group_name)\ | |
1014 | .get_api_data()) |
|
1024 | .get_api_data()) | |
1015 | } |
|
1025 | } | |
1016 | expected = ret |
|
1026 | expected = ret | |
1017 | self._compare_ok(id_, expected, given=response.body) |
|
1027 | self._compare_ok(id_, expected, given=response.body) | |
1018 |
|
1028 | |||
1019 | destroy_users_group(group_name) |
|
1029 | destroy_users_group(group_name) | |
1020 |
|
1030 | |||
1021 | def test_api_get_users_group_that_exist(self): |
|
1031 | def test_api_get_users_group_that_exist(self): | |
1022 | id_, params = _build_data(self.apikey, 'create_users_group', |
|
1032 | id_, params = _build_data(self.apikey, 'create_users_group', | |
1023 | group_name=TEST_USERS_GROUP) |
|
1033 | group_name=TEST_USERS_GROUP) | |
1024 | response = api_call(self, params) |
|
1034 | response = api_call(self, params) | |
1025 |
|
1035 | |||
1026 | expected = "users group `%s` already exist" % TEST_USERS_GROUP |
|
1036 | expected = "users group `%s` already exist" % TEST_USERS_GROUP | |
1027 | self._compare_error(id_, expected, given=response.body) |
|
1037 | self._compare_error(id_, expected, given=response.body) | |
1028 |
|
1038 | |||
1029 | @mock.patch.object(UsersGroupModel, 'create', crash) |
|
1039 | @mock.patch.object(UsersGroupModel, 'create', crash) | |
1030 | def test_api_get_users_group_exception_occurred(self): |
|
1040 | def test_api_get_users_group_exception_occurred(self): | |
1031 | group_name = 'exception_happens' |
|
1041 | group_name = 'exception_happens' | |
1032 | id_, params = _build_data(self.apikey, 'create_users_group', |
|
1042 | id_, params = _build_data(self.apikey, 'create_users_group', | |
1033 | group_name=group_name) |
|
1043 | group_name=group_name) | |
1034 | response = api_call(self, params) |
|
1044 | response = api_call(self, params) | |
1035 |
|
1045 | |||
1036 | expected = 'failed to create group `%s`' % group_name |
|
1046 | expected = 'failed to create group `%s`' % group_name | |
1037 | self._compare_error(id_, expected, given=response.body) |
|
1047 | self._compare_error(id_, expected, given=response.body) | |
1038 |
|
1048 | |||
1039 | def test_api_add_user_to_users_group(self): |
|
1049 | def test_api_add_user_to_users_group(self): | |
1040 | gr_name = 'test_group' |
|
1050 | gr_name = 'test_group' | |
1041 | UsersGroupModel().create(gr_name) |
|
1051 | UsersGroupModel().create(gr_name) | |
1042 | Session().commit() |
|
1052 | Session().commit() | |
1043 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
1053 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', | |
1044 | usersgroupid=gr_name, |
|
1054 | usersgroupid=gr_name, | |
1045 | userid=TEST_USER_ADMIN_LOGIN) |
|
1055 | userid=TEST_USER_ADMIN_LOGIN) | |
1046 | response = api_call(self, params) |
|
1056 | response = api_call(self, params) | |
1047 |
|
1057 | |||
1048 | expected = { |
|
1058 | expected = { | |
1049 | 'msg': 'added member `%s` to users group `%s`' % ( |
|
1059 | 'msg': 'added member `%s` to users group `%s`' % ( | |
1050 | TEST_USER_ADMIN_LOGIN, gr_name |
|
1060 | TEST_USER_ADMIN_LOGIN, gr_name | |
1051 | ), |
|
1061 | ), | |
1052 | 'success': True} |
|
1062 | 'success': True} | |
1053 | self._compare_ok(id_, expected, given=response.body) |
|
1063 | self._compare_ok(id_, expected, given=response.body) | |
1054 |
|
1064 | |||
1055 | UsersGroupModel().delete(users_group=gr_name) |
|
1065 | UsersGroupModel().delete(users_group=gr_name) | |
1056 | Session().commit() |
|
1066 | Session().commit() | |
1057 |
|
1067 | |||
1058 | def test_api_add_user_to_users_group_that_doesnt_exist(self): |
|
1068 | def test_api_add_user_to_users_group_that_doesnt_exist(self): | |
1059 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
1069 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', | |
1060 | usersgroupid='false-group', |
|
1070 | usersgroupid='false-group', | |
1061 | userid=TEST_USER_ADMIN_LOGIN) |
|
1071 | userid=TEST_USER_ADMIN_LOGIN) | |
1062 | response = api_call(self, params) |
|
1072 | response = api_call(self, params) | |
1063 |
|
1073 | |||
1064 | expected = 'users group `%s` does not exist' % 'false-group' |
|
1074 | expected = 'users group `%s` does not exist' % 'false-group' | |
1065 | self._compare_error(id_, expected, given=response.body) |
|
1075 | self._compare_error(id_, expected, given=response.body) | |
1066 |
|
1076 | |||
1067 | @mock.patch.object(UsersGroupModel, 'add_user_to_group', crash) |
|
1077 | @mock.patch.object(UsersGroupModel, 'add_user_to_group', crash) | |
1068 | def test_api_add_user_to_users_group_exception_occurred(self): |
|
1078 | def test_api_add_user_to_users_group_exception_occurred(self): | |
1069 | gr_name = 'test_group' |
|
1079 | gr_name = 'test_group' | |
1070 | UsersGroupModel().create(gr_name) |
|
1080 | UsersGroupModel().create(gr_name) | |
1071 | Session().commit() |
|
1081 | Session().commit() | |
1072 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
1082 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', | |
1073 | usersgroupid=gr_name, |
|
1083 | usersgroupid=gr_name, | |
1074 | userid=TEST_USER_ADMIN_LOGIN) |
|
1084 | userid=TEST_USER_ADMIN_LOGIN) | |
1075 | response = api_call(self, params) |
|
1085 | response = api_call(self, params) | |
1076 |
|
1086 | |||
1077 | expected = 'failed to add member to users group `%s`' % gr_name |
|
1087 | expected = 'failed to add member to users group `%s`' % gr_name | |
1078 | self._compare_error(id_, expected, given=response.body) |
|
1088 | self._compare_error(id_, expected, given=response.body) | |
1079 |
|
1089 | |||
1080 | UsersGroupModel().delete(users_group=gr_name) |
|
1090 | UsersGroupModel().delete(users_group=gr_name) | |
1081 | Session().commit() |
|
1091 | Session().commit() | |
1082 |
|
1092 | |||
1083 | def test_api_remove_user_from_users_group(self): |
|
1093 | def test_api_remove_user_from_users_group(self): | |
1084 | gr_name = 'test_group_3' |
|
1094 | gr_name = 'test_group_3' | |
1085 | gr = UsersGroupModel().create(gr_name) |
|
1095 | gr = UsersGroupModel().create(gr_name) | |
1086 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) |
|
1096 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) | |
1087 | Session().commit() |
|
1097 | Session().commit() | |
1088 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', |
|
1098 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', | |
1089 | usersgroupid=gr_name, |
|
1099 | usersgroupid=gr_name, | |
1090 | userid=TEST_USER_ADMIN_LOGIN) |
|
1100 | userid=TEST_USER_ADMIN_LOGIN) | |
1091 | response = api_call(self, params) |
|
1101 | response = api_call(self, params) | |
1092 |
|
1102 | |||
1093 | expected = { |
|
1103 | expected = { | |
1094 | 'msg': 'removed member `%s` from users group `%s`' % ( |
|
1104 | 'msg': 'removed member `%s` from users group `%s`' % ( | |
1095 | TEST_USER_ADMIN_LOGIN, gr_name |
|
1105 | TEST_USER_ADMIN_LOGIN, gr_name | |
1096 | ), |
|
1106 | ), | |
1097 | 'success': True} |
|
1107 | 'success': True} | |
1098 | self._compare_ok(id_, expected, given=response.body) |
|
1108 | self._compare_ok(id_, expected, given=response.body) | |
1099 |
|
1109 | |||
1100 | UsersGroupModel().delete(users_group=gr_name) |
|
1110 | UsersGroupModel().delete(users_group=gr_name) | |
1101 | Session().commit() |
|
1111 | Session().commit() | |
1102 |
|
1112 | |||
1103 | @mock.patch.object(UsersGroupModel, 'remove_user_from_group', crash) |
|
1113 | @mock.patch.object(UsersGroupModel, 'remove_user_from_group', crash) | |
1104 | def test_api_remove_user_from_users_group_exception_occurred(self): |
|
1114 | def test_api_remove_user_from_users_group_exception_occurred(self): | |
1105 | gr_name = 'test_group_3' |
|
1115 | gr_name = 'test_group_3' | |
1106 | gr = UsersGroupModel().create(gr_name) |
|
1116 | gr = UsersGroupModel().create(gr_name) | |
1107 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) |
|
1117 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) | |
1108 | Session().commit() |
|
1118 | Session().commit() | |
1109 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', |
|
1119 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', | |
1110 | usersgroupid=gr_name, |
|
1120 | usersgroupid=gr_name, | |
1111 | userid=TEST_USER_ADMIN_LOGIN) |
|
1121 | userid=TEST_USER_ADMIN_LOGIN) | |
1112 | response = api_call(self, params) |
|
1122 | response = api_call(self, params) | |
1113 |
|
1123 | |||
1114 | expected = 'failed to remove member from users group `%s`' % gr_name |
|
1124 | expected = 'failed to remove member from users group `%s`' % gr_name | |
1115 | self._compare_error(id_, expected, given=response.body) |
|
1125 | self._compare_error(id_, expected, given=response.body) | |
1116 |
|
1126 | |||
1117 | UsersGroupModel().delete(users_group=gr_name) |
|
1127 | UsersGroupModel().delete(users_group=gr_name) | |
1118 | Session().commit() |
|
1128 | Session().commit() | |
1119 |
|
1129 | |||
1120 | @parameterized.expand([('none', 'repository.none'), |
|
1130 | @parameterized.expand([('none', 'repository.none'), | |
1121 | ('read', 'repository.read'), |
|
1131 | ('read', 'repository.read'), | |
1122 | ('write', 'repository.write'), |
|
1132 | ('write', 'repository.write'), | |
1123 | ('admin', 'repository.admin')]) |
|
1133 | ('admin', 'repository.admin')]) | |
1124 | def test_api_grant_user_permission(self, name, perm): |
|
1134 | def test_api_grant_user_permission(self, name, perm): | |
1125 | id_, params = _build_data(self.apikey, 'grant_user_permission', |
|
1135 | id_, params = _build_data(self.apikey, 'grant_user_permission', | |
1126 | repoid=self.REPO, |
|
1136 | repoid=self.REPO, | |
1127 | userid=TEST_USER_ADMIN_LOGIN, |
|
1137 | userid=TEST_USER_ADMIN_LOGIN, | |
1128 | perm=perm) |
|
1138 | perm=perm) | |
1129 | response = api_call(self, params) |
|
1139 | response = api_call(self, params) | |
1130 |
|
1140 | |||
1131 | ret = { |
|
1141 | ret = { | |
1132 | 'msg': 'Granted perm: `%s` for user: `%s` in repo: `%s`' % ( |
|
1142 | 'msg': 'Granted perm: `%s` for user: `%s` in repo: `%s`' % ( | |
1133 | perm, TEST_USER_ADMIN_LOGIN, self.REPO |
|
1143 | perm, TEST_USER_ADMIN_LOGIN, self.REPO | |
1134 | ), |
|
1144 | ), | |
1135 | 'success': True |
|
1145 | 'success': True | |
1136 | } |
|
1146 | } | |
1137 | expected = ret |
|
1147 | expected = ret | |
1138 | self._compare_ok(id_, expected, given=response.body) |
|
1148 | self._compare_ok(id_, expected, given=response.body) | |
1139 |
|
1149 | |||
1140 | def test_api_grant_user_permission_wrong_permission(self): |
|
1150 | def test_api_grant_user_permission_wrong_permission(self): | |
1141 | perm = 'haha.no.permission' |
|
1151 | perm = 'haha.no.permission' | |
1142 | id_, params = _build_data(self.apikey, 'grant_user_permission', |
|
1152 | id_, params = _build_data(self.apikey, 'grant_user_permission', | |
1143 | repoid=self.REPO, |
|
1153 | repoid=self.REPO, | |
1144 | userid=TEST_USER_ADMIN_LOGIN, |
|
1154 | userid=TEST_USER_ADMIN_LOGIN, | |
1145 | perm=perm) |
|
1155 | perm=perm) | |
1146 | response = api_call(self, params) |
|
1156 | response = api_call(self, params) | |
1147 |
|
1157 | |||
1148 | expected = 'permission `%s` does not exist' % perm |
|
1158 | expected = 'permission `%s` does not exist' % perm | |
1149 | self._compare_error(id_, expected, given=response.body) |
|
1159 | self._compare_error(id_, expected, given=response.body) | |
1150 |
|
1160 | |||
1151 | @mock.patch.object(RepoModel, 'grant_user_permission', crash) |
|
1161 | @mock.patch.object(RepoModel, 'grant_user_permission', crash) | |
1152 | def test_api_grant_user_permission_exception_when_adding(self): |
|
1162 | def test_api_grant_user_permission_exception_when_adding(self): | |
1153 | perm = 'repository.read' |
|
1163 | perm = 'repository.read' | |
1154 | id_, params = _build_data(self.apikey, 'grant_user_permission', |
|
1164 | id_, params = _build_data(self.apikey, 'grant_user_permission', | |
1155 | repoid=self.REPO, |
|
1165 | repoid=self.REPO, | |
1156 | userid=TEST_USER_ADMIN_LOGIN, |
|
1166 | userid=TEST_USER_ADMIN_LOGIN, | |
1157 | perm=perm) |
|
1167 | perm=perm) | |
1158 | response = api_call(self, params) |
|
1168 | response = api_call(self, params) | |
1159 |
|
1169 | |||
1160 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
|
1170 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( | |
1161 | TEST_USER_ADMIN_LOGIN, self.REPO |
|
1171 | TEST_USER_ADMIN_LOGIN, self.REPO | |
1162 | ) |
|
1172 | ) | |
1163 | self._compare_error(id_, expected, given=response.body) |
|
1173 | self._compare_error(id_, expected, given=response.body) | |
1164 |
|
1174 | |||
1165 | def test_api_revoke_user_permission(self): |
|
1175 | def test_api_revoke_user_permission(self): | |
1166 | id_, params = _build_data(self.apikey, 'revoke_user_permission', |
|
1176 | id_, params = _build_data(self.apikey, 'revoke_user_permission', | |
1167 | repoid=self.REPO, |
|
1177 | repoid=self.REPO, | |
1168 | userid=TEST_USER_ADMIN_LOGIN,) |
|
1178 | userid=TEST_USER_ADMIN_LOGIN,) | |
1169 | response = api_call(self, params) |
|
1179 | response = api_call(self, params) | |
1170 |
|
1180 | |||
1171 | expected = { |
|
1181 | expected = { | |
1172 | 'msg': 'Revoked perm for user: `%s` in repo: `%s`' % ( |
|
1182 | 'msg': 'Revoked perm for user: `%s` in repo: `%s`' % ( | |
1173 | TEST_USER_ADMIN_LOGIN, self.REPO |
|
1183 | TEST_USER_ADMIN_LOGIN, self.REPO | |
1174 | ), |
|
1184 | ), | |
1175 | 'success': True |
|
1185 | 'success': True | |
1176 | } |
|
1186 | } | |
1177 | self._compare_ok(id_, expected, given=response.body) |
|
1187 | self._compare_ok(id_, expected, given=response.body) | |
1178 |
|
1188 | |||
1179 | @mock.patch.object(RepoModel, 'revoke_user_permission', crash) |
|
1189 | @mock.patch.object(RepoModel, 'revoke_user_permission', crash) | |
1180 | def test_api_revoke_user_permission_exception_when_adding(self): |
|
1190 | def test_api_revoke_user_permission_exception_when_adding(self): | |
1181 | id_, params = _build_data(self.apikey, 'revoke_user_permission', |
|
1191 | id_, params = _build_data(self.apikey, 'revoke_user_permission', | |
1182 | repoid=self.REPO, |
|
1192 | repoid=self.REPO, | |
1183 | userid=TEST_USER_ADMIN_LOGIN,) |
|
1193 | userid=TEST_USER_ADMIN_LOGIN,) | |
1184 | response = api_call(self, params) |
|
1194 | response = api_call(self, params) | |
1185 |
|
1195 | |||
1186 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
|
1196 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( | |
1187 | TEST_USER_ADMIN_LOGIN, self.REPO |
|
1197 | TEST_USER_ADMIN_LOGIN, self.REPO | |
1188 | ) |
|
1198 | ) | |
1189 | self._compare_error(id_, expected, given=response.body) |
|
1199 | self._compare_error(id_, expected, given=response.body) | |
1190 |
|
1200 | |||
1191 | @parameterized.expand([('none', 'repository.none'), |
|
1201 | @parameterized.expand([('none', 'repository.none'), | |
1192 | ('read', 'repository.read'), |
|
1202 | ('read', 'repository.read'), | |
1193 | ('write', 'repository.write'), |
|
1203 | ('write', 'repository.write'), | |
1194 | ('admin', 'repository.admin')]) |
|
1204 | ('admin', 'repository.admin')]) | |
1195 | def test_api_grant_users_group_permission(self, name, perm): |
|
1205 | def test_api_grant_users_group_permission(self, name, perm): | |
1196 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
1206 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', | |
1197 | repoid=self.REPO, |
|
1207 | repoid=self.REPO, | |
1198 | usersgroupid=TEST_USERS_GROUP, |
|
1208 | usersgroupid=TEST_USERS_GROUP, | |
1199 | perm=perm) |
|
1209 | perm=perm) | |
1200 | response = api_call(self, params) |
|
1210 | response = api_call(self, params) | |
1201 |
|
1211 | |||
1202 | ret = { |
|
1212 | ret = { | |
1203 | 'msg': 'Granted perm: `%s` for users group: `%s` in repo: `%s`' % ( |
|
1213 | 'msg': 'Granted perm: `%s` for users group: `%s` in repo: `%s`' % ( | |
1204 | perm, TEST_USERS_GROUP, self.REPO |
|
1214 | perm, TEST_USERS_GROUP, self.REPO | |
1205 | ), |
|
1215 | ), | |
1206 | 'success': True |
|
1216 | 'success': True | |
1207 | } |
|
1217 | } | |
1208 | expected = ret |
|
1218 | expected = ret | |
1209 | self._compare_ok(id_, expected, given=response.body) |
|
1219 | self._compare_ok(id_, expected, given=response.body) | |
1210 |
|
1220 | |||
1211 | def test_api_grant_users_group_permission_wrong_permission(self): |
|
1221 | def test_api_grant_users_group_permission_wrong_permission(self): | |
1212 | perm = 'haha.no.permission' |
|
1222 | perm = 'haha.no.permission' | |
1213 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
1223 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', | |
1214 | repoid=self.REPO, |
|
1224 | repoid=self.REPO, | |
1215 | usersgroupid=TEST_USERS_GROUP, |
|
1225 | usersgroupid=TEST_USERS_GROUP, | |
1216 | perm=perm) |
|
1226 | perm=perm) | |
1217 | response = api_call(self, params) |
|
1227 | response = api_call(self, params) | |
1218 |
|
1228 | |||
1219 | expected = 'permission `%s` does not exist' % perm |
|
1229 | expected = 'permission `%s` does not exist' % perm | |
1220 | self._compare_error(id_, expected, given=response.body) |
|
1230 | self._compare_error(id_, expected, given=response.body) | |
1221 |
|
1231 | |||
1222 | @mock.patch.object(RepoModel, 'grant_users_group_permission', crash) |
|
1232 | @mock.patch.object(RepoModel, 'grant_users_group_permission', crash) | |
1223 | def test_api_grant_users_group_permission_exception_when_adding(self): |
|
1233 | def test_api_grant_users_group_permission_exception_when_adding(self): | |
1224 | perm = 'repository.read' |
|
1234 | perm = 'repository.read' | |
1225 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
1235 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', | |
1226 | repoid=self.REPO, |
|
1236 | repoid=self.REPO, | |
1227 | usersgroupid=TEST_USERS_GROUP, |
|
1237 | usersgroupid=TEST_USERS_GROUP, | |
1228 | perm=perm) |
|
1238 | perm=perm) | |
1229 | response = api_call(self, params) |
|
1239 | response = api_call(self, params) | |
1230 |
|
1240 | |||
1231 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( |
|
1241 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( | |
1232 | TEST_USERS_GROUP, self.REPO |
|
1242 | TEST_USERS_GROUP, self.REPO | |
1233 | ) |
|
1243 | ) | |
1234 | self._compare_error(id_, expected, given=response.body) |
|
1244 | self._compare_error(id_, expected, given=response.body) | |
1235 |
|
1245 | |||
1236 | def test_api_revoke_users_group_permission(self): |
|
1246 | def test_api_revoke_users_group_permission(self): | |
1237 | RepoModel().grant_users_group_permission(repo=self.REPO, |
|
1247 | RepoModel().grant_users_group_permission(repo=self.REPO, | |
1238 | group_name=TEST_USERS_GROUP, |
|
1248 | group_name=TEST_USERS_GROUP, | |
1239 | perm='repository.read') |
|
1249 | perm='repository.read') | |
1240 | Session().commit() |
|
1250 | Session().commit() | |
1241 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', |
|
1251 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', | |
1242 | repoid=self.REPO, |
|
1252 | repoid=self.REPO, | |
1243 | usersgroupid=TEST_USERS_GROUP,) |
|
1253 | usersgroupid=TEST_USERS_GROUP,) | |
1244 | response = api_call(self, params) |
|
1254 | response = api_call(self, params) | |
1245 |
|
1255 | |||
1246 | expected = { |
|
1256 | expected = { | |
1247 | 'msg': 'Revoked perm for users group: `%s` in repo: `%s`' % ( |
|
1257 | 'msg': 'Revoked perm for users group: `%s` in repo: `%s`' % ( | |
1248 | TEST_USERS_GROUP, self.REPO |
|
1258 | TEST_USERS_GROUP, self.REPO | |
1249 | ), |
|
1259 | ), | |
1250 | 'success': True |
|
1260 | 'success': True | |
1251 | } |
|
1261 | } | |
1252 | self._compare_ok(id_, expected, given=response.body) |
|
1262 | self._compare_ok(id_, expected, given=response.body) | |
1253 |
|
1263 | |||
1254 | @mock.patch.object(RepoModel, 'revoke_users_group_permission', crash) |
|
1264 | @mock.patch.object(RepoModel, 'revoke_users_group_permission', crash) | |
1255 | def test_api_revoke_users_group_permission_exception_when_adding(self): |
|
1265 | def test_api_revoke_users_group_permission_exception_when_adding(self): | |
1256 |
|
1266 | |||
1257 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', |
|
1267 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', | |
1258 | repoid=self.REPO, |
|
1268 | repoid=self.REPO, | |
1259 | usersgroupid=TEST_USERS_GROUP,) |
|
1269 | usersgroupid=TEST_USERS_GROUP,) | |
1260 | response = api_call(self, params) |
|
1270 | response = api_call(self, params) | |
1261 |
|
1271 | |||
1262 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( |
|
1272 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( | |
1263 | TEST_USERS_GROUP, self.REPO |
|
1273 | TEST_USERS_GROUP, self.REPO | |
1264 | ) |
|
1274 | ) | |
1265 | self._compare_error(id_, expected, given=response.body) |
|
1275 | self._compare_error(id_, expected, given=response.body) |
@@ -1,108 +1,108 b'' | |||||
1 | import time |
|
1 | import time | |
2 | from rhodecode.tests import * |
|
2 | from rhodecode.tests import * | |
3 | from rhodecode.model.meta import Session |
|
3 | from rhodecode.model.meta import Session | |
4 | from rhodecode.model.db import User, RhodeCodeSetting, Repository |
|
4 | from rhodecode.model.db import User, RhodeCodeSetting, Repository | |
5 | from rhodecode.lib.utils import set_rhodecode_config |
|
5 | from rhodecode.lib.utils import set_rhodecode_config | |
6 | from rhodecode.tests.models.common import _make_repo, _make_group |
|
6 | from rhodecode.tests.models.common import _make_repo, _make_group | |
7 | from rhodecode.model.repo import RepoModel |
|
7 | from rhodecode.model.repo import RepoModel | |
8 | from rhodecode.model.repos_group import ReposGroupModel |
|
8 | from rhodecode.model.repos_group import ReposGroupModel | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | class TestHomeController(TestController): |
|
11 | class TestHomeController(TestController): | |
12 |
|
12 | |||
13 | def test_index(self): |
|
13 | def test_index(self): | |
14 | self.log_user() |
|
14 | self.log_user() | |
15 | response = self.app.get(url(controller='home', action='index')) |
|
15 | response = self.app.get(url(controller='home', action='index')) | |
16 | #if global permission is set |
|
16 | #if global permission is set | |
17 |
response.mustcontain('A |
|
17 | response.mustcontain('Add repository') | |
18 | response.mustcontain('href="/%s/summary"' % HG_REPO) |
|
18 | response.mustcontain('href="/%s/summary"' % HG_REPO) | |
19 |
|
19 | |||
20 | response.mustcontain("""<img class="icon" title="Mercurial repository" """ |
|
20 | response.mustcontain("""<img class="icon" title="Mercurial repository" """ | |
21 | """alt="Mercurial repository" src="/images/icons/hg""" |
|
21 | """alt="Mercurial repository" src="/images/icons/hg""" | |
22 | """icon.png"/>""") |
|
22 | """icon.png"/>""") | |
23 | response.mustcontain("""<img class="icon" title="public repository" """ |
|
23 | response.mustcontain("""<img class="icon" title="public repository" """ | |
24 | """alt="public repository" src="/images/icons/lock_""" |
|
24 | """alt="public repository" src="/images/icons/lock_""" | |
25 | """open.png"/>""") |
|
25 | """open.png"/>""") | |
26 |
|
26 | |||
27 | response.mustcontain( |
|
27 | response.mustcontain( | |
28 | """<a title="Marcin Kuzminski &lt;marcin@python-works.com&gt;:\n |
|
28 | """<a title="Marcin Kuzminski &lt;marcin@python-works.com&gt;:\n | |
29 | merge" class="tooltip" href="/vcs_test_hg/changeset/27cd5cce30c96924232""" |
|
29 | merge" class="tooltip" href="/vcs_test_hg/changeset/27cd5cce30c96924232""" | |
30 | """dffcd24178a07ffeb5dfc">r173:27cd5cce30c9</a>""" |
|
30 | """dffcd24178a07ffeb5dfc">r173:27cd5cce30c9</a>""" | |
31 | ) |
|
31 | ) | |
32 |
|
32 | |||
33 | def test_repo_summary_with_anonymous_access_disabled(self): |
|
33 | def test_repo_summary_with_anonymous_access_disabled(self): | |
34 | anon = User.get_by_username('default') |
|
34 | anon = User.get_by_username('default') | |
35 | anon.active = False |
|
35 | anon.active = False | |
36 | Session().add(anon) |
|
36 | Session().add(anon) | |
37 | Session().commit() |
|
37 | Session().commit() | |
38 | time.sleep(1.5) # must sleep for cache (1s to expire) |
|
38 | time.sleep(1.5) # must sleep for cache (1s to expire) | |
39 | try: |
|
39 | try: | |
40 | response = self.app.get(url(controller='summary', |
|
40 | response = self.app.get(url(controller='summary', | |
41 | action='index', repo_name=HG_REPO), |
|
41 | action='index', repo_name=HG_REPO), | |
42 | status=302) |
|
42 | status=302) | |
43 | assert 'login' in response.location |
|
43 | assert 'login' in response.location | |
44 |
|
44 | |||
45 | finally: |
|
45 | finally: | |
46 | anon = User.get_by_username('default') |
|
46 | anon = User.get_by_username('default') | |
47 | anon.active = True |
|
47 | anon.active = True | |
48 | Session().add(anon) |
|
48 | Session().add(anon) | |
49 | Session().commit() |
|
49 | Session().commit() | |
50 |
|
50 | |||
51 | def test_index_with_anonymous_access_disabled(self): |
|
51 | def test_index_with_anonymous_access_disabled(self): | |
52 | anon = User.get_by_username('default') |
|
52 | anon = User.get_by_username('default') | |
53 | anon.active = False |
|
53 | anon.active = False | |
54 | Session().add(anon) |
|
54 | Session().add(anon) | |
55 | Session().commit() |
|
55 | Session().commit() | |
56 | time.sleep(1.5) # must sleep for cache (1s to expire) |
|
56 | time.sleep(1.5) # must sleep for cache (1s to expire) | |
57 | try: |
|
57 | try: | |
58 | response = self.app.get(url(controller='home', action='index'), |
|
58 | response = self.app.get(url(controller='home', action='index'), | |
59 | status=302) |
|
59 | status=302) | |
60 | assert 'login' in response.location |
|
60 | assert 'login' in response.location | |
61 | finally: |
|
61 | finally: | |
62 | anon = User.get_by_username('default') |
|
62 | anon = User.get_by_username('default') | |
63 | anon.active = True |
|
63 | anon.active = True | |
64 | Session().add(anon) |
|
64 | Session().add(anon) | |
65 | Session().commit() |
|
65 | Session().commit() | |
66 |
|
66 | |||
67 | def _set_l_dash(self, set_to): |
|
67 | def _set_l_dash(self, set_to): | |
68 | self.app.post(url('admin_setting', setting_id='visual'), |
|
68 | self.app.post(url('admin_setting', setting_id='visual'), | |
69 | params=dict(_method='put', |
|
69 | params=dict(_method='put', | |
70 | rhodecode_lightweight_dashboard=set_to,)) |
|
70 | rhodecode_lightweight_dashboard=set_to,)) | |
71 |
|
71 | |||
72 | def test_index_with_lightweight_dashboard(self): |
|
72 | def test_index_with_lightweight_dashboard(self): | |
73 | self.log_user() |
|
73 | self.log_user() | |
74 | self._set_l_dash(True) |
|
74 | self._set_l_dash(True) | |
75 |
|
75 | |||
76 | try: |
|
76 | try: | |
77 | response = self.app.get(url(controller='home', action='index')) |
|
77 | response = self.app.get(url(controller='home', action='index')) | |
78 | response.mustcontain("""var data = {"totalRecords": %s""" % len(Repository.getAll())) |
|
78 | response.mustcontain("""var data = {"totalRecords": %s""" % len(Repository.getAll())) | |
79 | finally: |
|
79 | finally: | |
80 | self._set_l_dash(False) |
|
80 | self._set_l_dash(False) | |
81 |
|
81 | |||
82 | def test_index_page_on_groups(self): |
|
82 | def test_index_page_on_groups(self): | |
83 | self.log_user() |
|
83 | self.log_user() | |
84 | _make_repo(name='gr1/repo_in_group', repos_group=_make_group('gr1')) |
|
84 | _make_repo(name='gr1/repo_in_group', repos_group=_make_group('gr1')) | |
85 | Session().commit() |
|
85 | Session().commit() | |
86 | response = self.app.get(url('repos_group_home', group_name='gr1')) |
|
86 | response = self.app.get(url('repos_group_home', group_name='gr1')) | |
87 |
|
87 | |||
88 | try: |
|
88 | try: | |
89 | response.mustcontain("""gr1/repo_in_group""") |
|
89 | response.mustcontain("""gr1/repo_in_group""") | |
90 | finally: |
|
90 | finally: | |
91 | RepoModel().delete('gr1/repo_in_group') |
|
91 | RepoModel().delete('gr1/repo_in_group') | |
92 | ReposGroupModel().delete(repos_group='gr1', force_delete=True) |
|
92 | ReposGroupModel().delete(repos_group='gr1', force_delete=True) | |
93 | Session().commit() |
|
93 | Session().commit() | |
94 |
|
94 | |||
95 | def test_index_page_on_groups_with_lightweight_dashboard(self): |
|
95 | def test_index_page_on_groups_with_lightweight_dashboard(self): | |
96 | self.log_user() |
|
96 | self.log_user() | |
97 | self._set_l_dash(True) |
|
97 | self._set_l_dash(True) | |
98 | _make_repo(name='gr1/repo_in_group', repos_group=_make_group('gr1')) |
|
98 | _make_repo(name='gr1/repo_in_group', repos_group=_make_group('gr1')) | |
99 | Session().commit() |
|
99 | Session().commit() | |
100 | response = self.app.get(url('repos_group_home', group_name='gr1')) |
|
100 | response = self.app.get(url('repos_group_home', group_name='gr1')) | |
101 |
|
101 | |||
102 | try: |
|
102 | try: | |
103 | response.mustcontain("""gr1/repo_in_group""") |
|
103 | response.mustcontain("""gr1/repo_in_group""") | |
104 | finally: |
|
104 | finally: | |
105 | self._set_l_dash(False) |
|
105 | self._set_l_dash(False) | |
106 | RepoModel().delete('gr1/repo_in_group') |
|
106 | RepoModel().delete('gr1/repo_in_group') | |
107 | ReposGroupModel().delete(repos_group='gr1', force_delete=True) |
|
107 | ReposGroupModel().delete(repos_group='gr1', force_delete=True) | |
108 | Session().commit() |
|
108 | Session().commit() |
General Comments 0
You need to be logged in to leave comments.
Login now