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