Show More
@@ -1,19 +1,19 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Email message and email sending related helper functions. |
|
2 | Email message and email sending related helper functions. | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | import socket |
|
5 | import socket | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | # Cache the hostname, but do it lazily: socket.getfqdn() can take a couple of |
|
8 | # Cache the hostname, but do it lazily: socket.getfqdn() can take a couple of | |
9 | # seconds, which slows down the restart of the server. |
|
9 | # seconds, which slows down the restart of the server. | |
10 | class CachedDnsName(object): |
|
10 | class CachedDnsName(object): | |
11 | def __str__(self): |
|
11 | def __str__(self): | |
12 | return self.get_fqdn() |
|
12 | return self.get_fqdn() | |
13 |
|
13 | |||
14 | def get_fqdn(self): |
|
14 | def get_fqdn(self): | |
15 | if not hasattr(self, '_fqdn'): |
|
15 | if not hasattr(self, '_fqdn'): | |
16 | self._fqdn = socket.getfqdn() |
|
16 | self._fqdn = socket.getfqdn() | |
17 | return self._fqdn |
|
17 | return self._fqdn | |
18 |
|
18 | |||
19 | DNS_NAME = CachedDnsName() No newline at end of file |
|
19 | DNS_NAME = CachedDnsName() |
@@ -1,46 +1,46 b'' | |||||
1 | <div id='repos_list_wrap' class="yui-skin-sam"> |
|
1 | <div id='repos_list_wrap' class="yui-skin-sam"> | |
2 | <table id="repos_list"> |
|
2 | <table id="repos_list"> | |
3 | <thead> |
|
3 | <thead> | |
4 | <tr> |
|
4 | <tr> | |
5 | <th></th> |
|
5 | <th></th> | |
6 | <th class="left">${_('Name')}</th> |
|
6 | <th class="left">${_('Name')}</th> | |
7 | <th class="left">${_('Revision')}</th> |
|
7 | <th class="left">${_('Revision')}</th> | |
8 | <th class="left">${_('Action')}</th> |
|
8 | <th class="left">${_('Action')}</th> | |
9 | <th class="left">${_('Action')}</th> |
|
9 | <th class="left">${_('Action')}</th> | |
10 | </thead> |
|
10 | </thead> | |
11 | <tbody> |
|
11 | <tbody> | |
12 | <%namespace name="dt" file="/data_table/_dt_elements.html"/> |
|
12 | <%namespace name="dt" file="/data_table/_dt_elements.html"/> | |
13 | %if c.user_repos: |
|
13 | %if c.user_repos: | |
14 | %for repo in c.user_repos: |
|
14 | %for repo in c.user_repos: | |
15 | <tr> |
|
15 | <tr> | |
16 | ##QUICK MENU |
|
16 | ##QUICK MENU | |
17 | <td class="quick_repo_menu"> |
|
17 | <td class="quick_repo_menu"> | |
18 | ${dt.quick_menu(repo['name'])} |
|
18 | ${dt.quick_menu(repo['name'])} | |
19 | </td> |
|
19 | </td> | |
20 | ##REPO NAME AND ICONS |
|
20 | ##REPO NAME AND ICONS | |
21 | <td class="reponame"> |
|
21 | <td class="reponame"> | |
22 | ${dt.repo_name(repo['name'],repo['dbrepo']['repo_type'],repo['dbrepo']['private'],repo['dbrepo_fork'].get('repo_name'))} |
|
22 | ${dt.repo_name(repo['name'],repo['dbrepo']['repo_type'],repo['dbrepo']['private'],repo['dbrepo_fork'].get('repo_name'))} | |
23 | </td> |
|
23 | </td> | |
24 | ##LAST REVISION |
|
24 | ##LAST REVISION | |
25 | <td> |
|
25 | <td> | |
26 | ${dt.revision(repo['name'],repo['rev'],repo['tip'],repo['author'],repo['last_msg'])} |
|
26 | ${dt.revision(repo['name'],repo['rev'],repo['tip'],repo['author'],repo['last_msg'])} | |
27 | </td> |
|
27 | </td> | |
28 | <td><a href="${h.url('repo_settings_home',repo_name=repo['name'])}" title="${_('edit')}"><img class="icon" alt="${_('private')}" src="${h.url('/images/icons/application_form_edit.png')}"/></a></td> |
|
28 | <td><a href="${h.url('repo_settings_home',repo_name=repo['name'])}" title="${_('edit')}"><img class="icon" alt="${_('private')}" src="${h.url('/images/icons/application_form_edit.png')}"/></a></td> | |
29 | <td> |
|
29 | <td> | |
30 | ${h.form(url('repo_settings_delete', repo_name=repo['name']),method='delete')} |
|
30 | ${h.form(url('repo_settings_delete', repo_name=repo['name']),method='delete')} | |
31 | ${h.submit('remove_%s' % repo['name'],'',class_="delete_icon action_button",onclick="return confirm('"+_('Confirm to delete this repository: %s') % repo['name']+"');")} |
|
31 | ${h.submit('remove_%s' % repo['name'],'',class_="delete_icon action_button",onclick="return confirm('"+_('Confirm to delete this repository: %s') % repo['name']+"');")} | |
32 | ${h.end_form()} |
|
32 | ${h.end_form()} | |
33 | </td> |
|
33 | </td> | |
34 | </tr> |
|
34 | </tr> | |
35 | %endfor |
|
35 | %endfor | |
36 | %else: |
|
36 | %else: | |
37 | <div style="padding:5px 0px 10px 0px;"> |
|
37 | <div style="padding:5px 0px 10px 0px;"> | |
38 | ${_('No repositories yet')} |
|
38 | ${_('No repositories yet')} | |
39 | %if h.HasPermissionAny('hg.admin','hg.create.repository')(): |
|
39 | %if h.HasPermissionAny('hg.admin','hg.create.repository')(): | |
40 | ${h.link_to(_('create one now'),h.url('admin_settings_create_repository'),class_="ui-btn")} |
|
40 | ${h.link_to(_('create one now'),h.url('admin_settings_create_repository'),class_="ui-btn")} | |
41 | %endif |
|
41 | %endif | |
42 | </div> |
|
42 | </div> | |
43 | %endif |
|
43 | %endif | |
44 | </tbody> |
|
44 | </tbody> | |
45 | </table> |
|
45 | </table> | |
46 | </div> No newline at end of file |
|
46 | </div> |
@@ -1,991 +1,990 b'' | |||||
1 | from __future__ import with_statement |
|
1 | from __future__ import with_statement | |
2 | import random |
|
2 | import random | |
3 | import mock |
|
3 | import mock | |
4 |
|
4 | |||
5 | from rhodecode.tests import * |
|
5 | from rhodecode.tests import * | |
6 | from rhodecode.lib.compat import json |
|
6 | from rhodecode.lib.compat import json | |
7 | from rhodecode.lib.auth import AuthUser |
|
7 | from rhodecode.lib.auth import AuthUser | |
8 | from rhodecode.model.user import UserModel |
|
8 | from rhodecode.model.user import UserModel | |
9 | from rhodecode.model.users_group import UsersGroupModel |
|
9 | from rhodecode.model.users_group import UsersGroupModel | |
10 | from rhodecode.model.repo import RepoModel |
|
10 | from rhodecode.model.repo import RepoModel | |
11 | from rhodecode.model.meta import Session |
|
11 | from rhodecode.model.meta import Session | |
12 |
|
12 | |||
13 | API_URL = '/_admin/api' |
|
13 | API_URL = '/_admin/api' | |
14 |
|
14 | |||
15 |
|
15 | |||
16 | def _build_data(apikey, method, **kw): |
|
16 | def _build_data(apikey, method, **kw): | |
17 | """ |
|
17 | """ | |
18 | Builds API data with given random ID |
|
18 | Builds API data with given random ID | |
19 |
|
19 | |||
20 | :param random_id: |
|
20 | :param random_id: | |
21 | :type random_id: |
|
21 | :type random_id: | |
22 | """ |
|
22 | """ | |
23 | random_id = random.randrange(1, 9999) |
|
23 | random_id = random.randrange(1, 9999) | |
24 | return random_id, json.dumps({ |
|
24 | return random_id, json.dumps({ | |
25 | "id": random_id, |
|
25 | "id": random_id, | |
26 | "api_key": apikey, |
|
26 | "api_key": apikey, | |
27 | "method": method, |
|
27 | "method": method, | |
28 | "args": kw |
|
28 | "args": kw | |
29 | }) |
|
29 | }) | |
30 |
|
30 | |||
31 | jsonify = lambda obj: json.loads(json.dumps(obj)) |
|
31 | jsonify = lambda obj: json.loads(json.dumps(obj)) | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | def crash(*args, **kwargs): |
|
34 | def crash(*args, **kwargs): | |
35 | raise Exception('Total Crash !') |
|
35 | raise Exception('Total Crash !') | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | TEST_USERS_GROUP = 'test_users_group' |
|
38 | TEST_USERS_GROUP = 'test_users_group' | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | def make_users_group(name=TEST_USERS_GROUP): |
|
41 | def make_users_group(name=TEST_USERS_GROUP): | |
42 | gr = UsersGroupModel().create(name=name) |
|
42 | gr = UsersGroupModel().create(name=name) | |
43 | UsersGroupModel().add_user_to_group(users_group=gr, |
|
43 | UsersGroupModel().add_user_to_group(users_group=gr, | |
44 | user=TEST_USER_ADMIN_LOGIN) |
|
44 | user=TEST_USER_ADMIN_LOGIN) | |
45 | Session().commit() |
|
45 | Session().commit() | |
46 | return gr |
|
46 | return gr | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | def destroy_users_group(name=TEST_USERS_GROUP): |
|
49 | def destroy_users_group(name=TEST_USERS_GROUP): | |
50 | UsersGroupModel().delete(users_group=name, force=True) |
|
50 | UsersGroupModel().delete(users_group=name, force=True) | |
51 | Session().commit() |
|
51 | Session().commit() | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | def create_repo(repo_name, repo_type): |
|
54 | def create_repo(repo_name, repo_type): | |
55 | # create new repo |
|
55 | # create new repo | |
56 | form_data = dict(repo_name=repo_name, |
|
56 | form_data = dict(repo_name=repo_name, | |
57 | repo_name_full=repo_name, |
|
57 | repo_name_full=repo_name, | |
58 | fork_name=None, |
|
58 | fork_name=None, | |
59 | description='description %s' % repo_name, |
|
59 | description='description %s' % repo_name, | |
60 | repo_group=None, |
|
60 | repo_group=None, | |
61 | private=False, |
|
61 | private=False, | |
62 | repo_type=repo_type, |
|
62 | repo_type=repo_type, | |
63 | clone_uri=None, |
|
63 | clone_uri=None, | |
64 | landing_rev='tip') |
|
64 | landing_rev='tip') | |
65 | cur_user = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
65 | cur_user = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
66 | r = RepoModel().create(form_data, cur_user) |
|
66 | r = RepoModel().create(form_data, cur_user) | |
67 | Session().commit() |
|
67 | Session().commit() | |
68 | return r |
|
68 | return r | |
69 |
|
69 | |||
70 |
|
70 | |||
71 | def create_fork(fork_name, fork_type, fork_of): |
|
71 | def create_fork(fork_name, fork_type, fork_of): | |
72 | fork = RepoModel(Session())._get_repo(fork_of) |
|
72 | fork = RepoModel(Session())._get_repo(fork_of) | |
73 | r = create_repo(fork_name, fork_type) |
|
73 | r = create_repo(fork_name, fork_type) | |
74 | r.fork = fork |
|
74 | r.fork = fork | |
75 | Session().add(r) |
|
75 | Session().add(r) | |
76 | Session().commit() |
|
76 | Session().commit() | |
77 | return r |
|
77 | return r | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | def destroy_repo(repo_name): |
|
80 | def destroy_repo(repo_name): | |
81 | RepoModel().delete(repo_name) |
|
81 | RepoModel().delete(repo_name) | |
82 | Session().commit() |
|
82 | Session().commit() | |
83 |
|
83 | |||
84 |
|
84 | |||
85 | class BaseTestApi(object): |
|
85 | class BaseTestApi(object): | |
86 | REPO = None |
|
86 | REPO = None | |
87 | REPO_TYPE = None |
|
87 | REPO_TYPE = None | |
88 |
|
88 | |||
89 | @classmethod |
|
89 | @classmethod | |
90 | def setUpClass(self): |
|
90 | def setUpClass(self): | |
91 | self.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
91 | self.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
92 | self.apikey = self.usr.api_key |
|
92 | self.apikey = self.usr.api_key | |
93 | self.TEST_USER = UserModel().create_or_update( |
|
93 | self.TEST_USER = UserModel().create_or_update( | |
94 | username='test-api', |
|
94 | username='test-api', | |
95 | password='test', |
|
95 | password='test', | |
96 | email='test@api.rhodecode.org', |
|
96 | email='test@api.rhodecode.org', | |
97 | firstname='first', |
|
97 | firstname='first', | |
98 | lastname='last' |
|
98 | lastname='last' | |
99 | ) |
|
99 | ) | |
100 | Session().commit() |
|
100 | Session().commit() | |
101 | self.TEST_USER_LOGIN = self.TEST_USER.username |
|
101 | self.TEST_USER_LOGIN = self.TEST_USER.username | |
102 |
|
102 | |||
103 | @classmethod |
|
103 | @classmethod | |
104 | def teardownClass(self): |
|
104 | def teardownClass(self): | |
105 | pass |
|
105 | pass | |
106 |
|
106 | |||
107 | def setUp(self): |
|
107 | def setUp(self): | |
108 | self.maxDiff = None |
|
108 | self.maxDiff = None | |
109 | make_users_group() |
|
109 | make_users_group() | |
110 |
|
110 | |||
111 | def tearDown(self): |
|
111 | def tearDown(self): | |
112 | destroy_users_group() |
|
112 | destroy_users_group() | |
113 |
|
113 | |||
114 | def _compare_ok(self, id_, expected, given): |
|
114 | def _compare_ok(self, id_, expected, given): | |
115 | expected = jsonify({ |
|
115 | expected = jsonify({ | |
116 | 'id': id_, |
|
116 | 'id': id_, | |
117 | 'error': None, |
|
117 | 'error': None, | |
118 | 'result': expected |
|
118 | 'result': expected | |
119 | }) |
|
119 | }) | |
120 | given = json.loads(given) |
|
120 | given = json.loads(given) | |
121 | self.assertEqual(expected, given) |
|
121 | self.assertEqual(expected, given) | |
122 |
|
122 | |||
123 | def _compare_error(self, id_, expected, given): |
|
123 | def _compare_error(self, id_, expected, given): | |
124 | expected = jsonify({ |
|
124 | expected = jsonify({ | |
125 | 'id': id_, |
|
125 | 'id': id_, | |
126 | 'error': expected, |
|
126 | 'error': expected, | |
127 | 'result': None |
|
127 | 'result': None | |
128 | }) |
|
128 | }) | |
129 | given = json.loads(given) |
|
129 | given = json.loads(given) | |
130 | self.assertEqual(expected, given) |
|
130 | self.assertEqual(expected, given) | |
131 |
|
131 | |||
132 | # def test_Optional(self): |
|
132 | # def test_Optional(self): | |
133 | # from rhodecode.controllers.api.api import Optional |
|
133 | # from rhodecode.controllers.api.api import Optional | |
134 | # option1 = Optional(None) |
|
134 | # option1 = Optional(None) | |
135 | # self.assertEqual('<Optional:%s>' % None, repr(option1)) |
|
135 | # self.assertEqual('<Optional:%s>' % None, repr(option1)) | |
136 | # |
|
136 | # | |
137 | # self.assertEqual(1, Optional.extract(Optional(1))) |
|
137 | # self.assertEqual(1, Optional.extract(Optional(1))) | |
138 | # self.assertEqual('trololo', Optional.extract('trololo')) |
|
138 | # self.assertEqual('trololo', Optional.extract('trololo')) | |
139 |
|
139 | |||
140 | def test_api_wrong_key(self): |
|
140 | def test_api_wrong_key(self): | |
141 | id_, params = _build_data('trololo', 'get_user') |
|
141 | id_, params = _build_data('trololo', 'get_user') | |
142 | response = self.app.post(API_URL, content_type='application/json', |
|
142 | response = self.app.post(API_URL, content_type='application/json', | |
143 | params=params) |
|
143 | params=params) | |
144 |
|
144 | |||
145 | expected = 'Invalid API KEY' |
|
145 | expected = 'Invalid API KEY' | |
146 | self._compare_error(id_, expected, given=response.body) |
|
146 | self._compare_error(id_, expected, given=response.body) | |
147 |
|
147 | |||
148 | def test_api_missing_non_optional_param(self): |
|
148 | def test_api_missing_non_optional_param(self): | |
149 | id_, params = _build_data(self.apikey, 'get_user') |
|
149 | id_, params = _build_data(self.apikey, 'get_user') | |
150 | response = self.app.post(API_URL, content_type='application/json', |
|
150 | response = self.app.post(API_URL, content_type='application/json', | |
151 | params=params) |
|
151 | params=params) | |
152 |
|
152 | |||
153 | expected = 'Missing non optional `userid` arg in JSON DATA' |
|
153 | expected = 'Missing non optional `userid` arg in JSON DATA' | |
154 | self._compare_error(id_, expected, given=response.body) |
|
154 | self._compare_error(id_, expected, given=response.body) | |
155 |
|
155 | |||
156 | def test_api_get_users(self): |
|
156 | def test_api_get_users(self): | |
157 | id_, params = _build_data(self.apikey, 'get_users',) |
|
157 | id_, params = _build_data(self.apikey, 'get_users',) | |
158 | response = self.app.post(API_URL, content_type='application/json', |
|
158 | response = self.app.post(API_URL, content_type='application/json', | |
159 | params=params) |
|
159 | params=params) | |
160 | ret_all = [] |
|
160 | ret_all = [] | |
161 | for usr in UserModel().get_all(): |
|
161 | for usr in UserModel().get_all(): | |
162 | ret = usr.get_api_data() |
|
162 | ret = usr.get_api_data() | |
163 | ret_all.append(jsonify(ret)) |
|
163 | ret_all.append(jsonify(ret)) | |
164 | expected = ret_all |
|
164 | expected = ret_all | |
165 | self._compare_ok(id_, expected, given=response.body) |
|
165 | self._compare_ok(id_, expected, given=response.body) | |
166 |
|
166 | |||
167 | def test_api_get_user(self): |
|
167 | def test_api_get_user(self): | |
168 | id_, params = _build_data(self.apikey, 'get_user', |
|
168 | id_, params = _build_data(self.apikey, 'get_user', | |
169 | userid=TEST_USER_ADMIN_LOGIN) |
|
169 | userid=TEST_USER_ADMIN_LOGIN) | |
170 | response = self.app.post(API_URL, content_type='application/json', |
|
170 | response = self.app.post(API_URL, content_type='application/json', | |
171 | params=params) |
|
171 | params=params) | |
172 |
|
172 | |||
173 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
173 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
174 | ret = usr.get_api_data() |
|
174 | ret = usr.get_api_data() | |
175 | ret['permissions'] = AuthUser(usr.user_id).permissions |
|
175 | ret['permissions'] = AuthUser(usr.user_id).permissions | |
176 |
|
176 | |||
177 | expected = ret |
|
177 | expected = ret | |
178 | self._compare_ok(id_, expected, given=response.body) |
|
178 | self._compare_ok(id_, expected, given=response.body) | |
179 |
|
179 | |||
180 | def test_api_get_user_that_does_not_exist(self): |
|
180 | def test_api_get_user_that_does_not_exist(self): | |
181 | id_, params = _build_data(self.apikey, 'get_user', |
|
181 | id_, params = _build_data(self.apikey, 'get_user', | |
182 | userid='trololo') |
|
182 | userid='trololo') | |
183 | response = self.app.post(API_URL, content_type='application/json', |
|
183 | response = self.app.post(API_URL, content_type='application/json', | |
184 | params=params) |
|
184 | params=params) | |
185 |
|
185 | |||
186 | expected = "user `%s` does not exist" % 'trololo' |
|
186 | expected = "user `%s` does not exist" % 'trololo' | |
187 | self._compare_error(id_, expected, given=response.body) |
|
187 | self._compare_error(id_, expected, given=response.body) | |
188 |
|
188 | |||
189 | def test_api_pull(self): |
|
189 | def test_api_pull(self): | |
190 | #TODO: issues with rhodecode_extras here.. not sure why ! |
|
190 | #TODO: issues with rhodecode_extras here.. not sure why ! | |
191 | pass |
|
191 | pass | |
192 |
|
192 | |||
193 | # repo_name = 'test_pull' |
|
193 | # repo_name = 'test_pull' | |
194 | # r = create_repo(repo_name, self.REPO_TYPE) |
|
194 | # r = create_repo(repo_name, self.REPO_TYPE) | |
195 | # r.clone_uri = TEST_self.REPO |
|
195 | # r.clone_uri = TEST_self.REPO | |
196 | # Session.add(r) |
|
196 | # Session.add(r) | |
197 | # Session.commit() |
|
197 | # Session.commit() | |
198 | # |
|
198 | # | |
199 | # id_, params = _build_data(self.apikey, 'pull', |
|
199 | # id_, params = _build_data(self.apikey, 'pull', | |
200 | # repoid=repo_name,) |
|
200 | # repoid=repo_name,) | |
201 | # response = self.app.post(API_URL, content_type='application/json', |
|
201 | # response = self.app.post(API_URL, content_type='application/json', | |
202 | # params=params) |
|
202 | # params=params) | |
203 | # |
|
203 | # | |
204 | # expected = 'Pulled from `%s`' % repo_name |
|
204 | # expected = 'Pulled from `%s`' % repo_name | |
205 | # self._compare_ok(id_, expected, given=response.body) |
|
205 | # self._compare_ok(id_, expected, given=response.body) | |
206 | # |
|
206 | # | |
207 | # destroy_repo(repo_name) |
|
207 | # destroy_repo(repo_name) | |
208 |
|
208 | |||
209 | def test_api_pull_error(self): |
|
209 | def test_api_pull_error(self): | |
210 | id_, params = _build_data(self.apikey, 'pull', |
|
210 | id_, params = _build_data(self.apikey, 'pull', | |
211 | repoid=self.REPO,) |
|
211 | repoid=self.REPO,) | |
212 | response = self.app.post(API_URL, content_type='application/json', |
|
212 | response = self.app.post(API_URL, content_type='application/json', | |
213 | params=params) |
|
213 | params=params) | |
214 |
|
214 | |||
215 | expected = 'Unable to pull changes from `%s`' % self.REPO |
|
215 | expected = 'Unable to pull changes from `%s`' % self.REPO | |
216 | self._compare_error(id_, expected, given=response.body) |
|
216 | self._compare_error(id_, expected, given=response.body) | |
217 |
|
217 | |||
218 | def test_api_create_existing_user(self): |
|
218 | def test_api_create_existing_user(self): | |
219 | id_, params = _build_data(self.apikey, 'create_user', |
|
219 | id_, params = _build_data(self.apikey, 'create_user', | |
220 | username=TEST_USER_ADMIN_LOGIN, |
|
220 | username=TEST_USER_ADMIN_LOGIN, | |
221 | email='test@foo.com', |
|
221 | email='test@foo.com', | |
222 | password='trololo') |
|
222 | password='trololo') | |
223 | response = self.app.post(API_URL, content_type='application/json', |
|
223 | response = self.app.post(API_URL, content_type='application/json', | |
224 | params=params) |
|
224 | params=params) | |
225 |
|
225 | |||
226 | expected = "user `%s` already exist" % TEST_USER_ADMIN_LOGIN |
|
226 | expected = "user `%s` already exist" % TEST_USER_ADMIN_LOGIN | |
227 | self._compare_error(id_, expected, given=response.body) |
|
227 | self._compare_error(id_, expected, given=response.body) | |
228 |
|
228 | |||
229 | def test_api_create_user_with_existing_email(self): |
|
229 | def test_api_create_user_with_existing_email(self): | |
230 | id_, params = _build_data(self.apikey, 'create_user', |
|
230 | id_, params = _build_data(self.apikey, 'create_user', | |
231 | username=TEST_USER_ADMIN_LOGIN + 'new', |
|
231 | username=TEST_USER_ADMIN_LOGIN + 'new', | |
232 | email=TEST_USER_REGULAR_EMAIL, |
|
232 | email=TEST_USER_REGULAR_EMAIL, | |
233 | password='trololo') |
|
233 | password='trololo') | |
234 | response = self.app.post(API_URL, content_type='application/json', |
|
234 | response = self.app.post(API_URL, content_type='application/json', | |
235 | params=params) |
|
235 | params=params) | |
236 |
|
236 | |||
237 | expected = "email `%s` already exist" % TEST_USER_REGULAR_EMAIL |
|
237 | expected = "email `%s` already exist" % TEST_USER_REGULAR_EMAIL | |
238 | self._compare_error(id_, expected, given=response.body) |
|
238 | self._compare_error(id_, expected, given=response.body) | |
239 |
|
239 | |||
240 | def test_api_create_user(self): |
|
240 | def test_api_create_user(self): | |
241 | username = 'test_new_api_user' |
|
241 | username = 'test_new_api_user' | |
242 | email = username + "@foo.com" |
|
242 | email = username + "@foo.com" | |
243 |
|
243 | |||
244 | id_, params = _build_data(self.apikey, 'create_user', |
|
244 | id_, params = _build_data(self.apikey, 'create_user', | |
245 | username=username, |
|
245 | username=username, | |
246 | email=email, |
|
246 | email=email, | |
247 | password='trololo') |
|
247 | password='trololo') | |
248 | response = self.app.post(API_URL, content_type='application/json', |
|
248 | response = self.app.post(API_URL, content_type='application/json', | |
249 | params=params) |
|
249 | params=params) | |
250 |
|
250 | |||
251 | usr = UserModel().get_by_username(username) |
|
251 | usr = UserModel().get_by_username(username) | |
252 | ret = dict( |
|
252 | ret = dict( | |
253 | msg='created new user `%s`' % username, |
|
253 | msg='created new user `%s`' % username, | |
254 | user=jsonify(usr.get_api_data()) |
|
254 | user=jsonify(usr.get_api_data()) | |
255 | ) |
|
255 | ) | |
256 |
|
256 | |||
257 | expected = ret |
|
257 | expected = ret | |
258 | self._compare_ok(id_, expected, given=response.body) |
|
258 | self._compare_ok(id_, expected, given=response.body) | |
259 |
|
259 | |||
260 | UserModel().delete(usr.user_id) |
|
260 | UserModel().delete(usr.user_id) | |
261 | self.Session().commit() |
|
261 | self.Session().commit() | |
262 |
|
262 | |||
263 | @mock.patch.object(UserModel, 'create_or_update', crash) |
|
263 | @mock.patch.object(UserModel, 'create_or_update', crash) | |
264 | def test_api_create_user_when_exception_happened(self): |
|
264 | def test_api_create_user_when_exception_happened(self): | |
265 |
|
265 | |||
266 | username = 'test_new_api_user' |
|
266 | username = 'test_new_api_user' | |
267 | email = username + "@foo.com" |
|
267 | email = username + "@foo.com" | |
268 |
|
268 | |||
269 | id_, params = _build_data(self.apikey, 'create_user', |
|
269 | id_, params = _build_data(self.apikey, 'create_user', | |
270 | username=username, |
|
270 | username=username, | |
271 | email=email, |
|
271 | email=email, | |
272 | password='trololo') |
|
272 | password='trololo') | |
273 | response = self.app.post(API_URL, content_type='application/json', |
|
273 | response = self.app.post(API_URL, content_type='application/json', | |
274 | params=params) |
|
274 | params=params) | |
275 | expected = 'failed to create user `%s`' % username |
|
275 | expected = 'failed to create user `%s`' % username | |
276 | self._compare_error(id_, expected, given=response.body) |
|
276 | self._compare_error(id_, expected, given=response.body) | |
277 |
|
277 | |||
278 | def test_api_delete_user(self): |
|
278 | def test_api_delete_user(self): | |
279 | usr = UserModel().create_or_update(username=u'test_user', |
|
279 | usr = UserModel().create_or_update(username=u'test_user', | |
280 | password=u'qweqwe', |
|
280 | password=u'qweqwe', | |
281 | email=u'u232@rhodecode.org', |
|
281 | email=u'u232@rhodecode.org', | |
282 | firstname=u'u1', lastname=u'u1') |
|
282 | firstname=u'u1', lastname=u'u1') | |
283 | self.Session().commit() |
|
283 | self.Session().commit() | |
284 | username = usr.username |
|
284 | username = usr.username | |
285 | email = usr.email |
|
285 | email = usr.email | |
286 | usr_id = usr.user_id |
|
286 | usr_id = usr.user_id | |
287 | ## DELETE THIS USER NOW |
|
287 | ## DELETE THIS USER NOW | |
288 |
|
288 | |||
289 | id_, params = _build_data(self.apikey, 'delete_user', |
|
289 | id_, params = _build_data(self.apikey, 'delete_user', | |
290 | userid=username,) |
|
290 | userid=username,) | |
291 | response = self.app.post(API_URL, content_type='application/json', |
|
291 | response = self.app.post(API_URL, content_type='application/json', | |
292 | params=params) |
|
292 | params=params) | |
293 |
|
293 | |||
294 | ret = {'msg': 'deleted user ID:%s %s' % (usr_id, username), |
|
294 | ret = {'msg': 'deleted user ID:%s %s' % (usr_id, username), | |
295 | 'user': None} |
|
295 | 'user': None} | |
296 | expected = ret |
|
296 | expected = ret | |
297 | self._compare_ok(id_, expected, given=response.body) |
|
297 | self._compare_ok(id_, expected, given=response.body) | |
298 |
|
298 | |||
299 | @mock.patch.object(UserModel, 'delete', crash) |
|
299 | @mock.patch.object(UserModel, 'delete', crash) | |
300 | def test_api_delete_user_when_exception_happened(self): |
|
300 | def test_api_delete_user_when_exception_happened(self): | |
301 | usr = UserModel().create_or_update(username=u'test_user', |
|
301 | usr = UserModel().create_or_update(username=u'test_user', | |
302 | password=u'qweqwe', |
|
302 | password=u'qweqwe', | |
303 | email=u'u232@rhodecode.org', |
|
303 | email=u'u232@rhodecode.org', | |
304 | firstname=u'u1', lastname=u'u1') |
|
304 | firstname=u'u1', lastname=u'u1') | |
305 | self.Session().commit() |
|
305 | self.Session().commit() | |
306 | username = usr.username |
|
306 | username = usr.username | |
307 |
|
307 | |||
308 | id_, params = _build_data(self.apikey, 'delete_user', |
|
308 | id_, params = _build_data(self.apikey, 'delete_user', | |
309 | userid=username,) |
|
309 | userid=username,) | |
310 | response = self.app.post(API_URL, content_type='application/json', |
|
310 | response = self.app.post(API_URL, content_type='application/json', | |
311 | params=params) |
|
311 | params=params) | |
312 | ret = 'failed to delete ID:%s %s' % (usr.user_id, |
|
312 | ret = 'failed to delete ID:%s %s' % (usr.user_id, | |
313 | usr.username) |
|
313 | usr.username) | |
314 | expected = ret |
|
314 | expected = ret | |
315 | self._compare_error(id_, expected, given=response.body) |
|
315 | self._compare_error(id_, expected, given=response.body) | |
316 |
|
316 | |||
317 | @parameterized.expand([('firstname', 'new_username'), |
|
317 | @parameterized.expand([('firstname', 'new_username'), | |
318 | ('lastname', 'new_username'), |
|
318 | ('lastname', 'new_username'), | |
319 | ('email', 'new_username'), |
|
319 | ('email', 'new_username'), | |
320 | ('admin', True), |
|
320 | ('admin', True), | |
321 | ('admin', False), |
|
321 | ('admin', False), | |
322 | ('ldap_dn', 'test'), |
|
322 | ('ldap_dn', 'test'), | |
323 | ('ldap_dn', None), |
|
323 | ('ldap_dn', None), | |
324 | ('active', False), |
|
324 | ('active', False), | |
325 | ('active', True), |
|
325 | ('active', True), | |
326 | ('password', 'newpass') |
|
326 | ('password', 'newpass') | |
327 | ]) |
|
327 | ]) | |
328 | def test_api_update_user(self, name, expected): |
|
328 | def test_api_update_user(self, name, expected): | |
329 | usr = UserModel().get_by_username(self.TEST_USER_LOGIN) |
|
329 | usr = UserModel().get_by_username(self.TEST_USER_LOGIN) | |
330 | kw = {name: expected, |
|
330 | kw = {name: expected, | |
331 | 'userid': usr.user_id} |
|
331 | 'userid': usr.user_id} | |
332 | id_, params = _build_data(self.apikey, 'update_user', **kw) |
|
332 | id_, params = _build_data(self.apikey, 'update_user', **kw) | |
333 | response = self.app.post(API_URL, content_type='application/json', |
|
333 | response = self.app.post(API_URL, content_type='application/json', | |
334 | params=params) |
|
334 | params=params) | |
335 |
|
335 | |||
336 | ret = { |
|
336 | ret = { | |
337 | 'msg': 'updated user ID:%s %s' % (usr.user_id, self.TEST_USER_LOGIN), |
|
337 | 'msg': 'updated user ID:%s %s' % (usr.user_id, self.TEST_USER_LOGIN), | |
338 | 'user': jsonify(UserModel()\ |
|
338 | 'user': jsonify(UserModel()\ | |
339 | .get_by_username(self.TEST_USER_LOGIN)\ |
|
339 | .get_by_username(self.TEST_USER_LOGIN)\ | |
340 | .get_api_data()) |
|
340 | .get_api_data()) | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | expected = ret |
|
343 | expected = ret | |
344 | self._compare_ok(id_, expected, given=response.body) |
|
344 | self._compare_ok(id_, expected, given=response.body) | |
345 |
|
345 | |||
346 | def test_api_update_user_no_changed_params(self): |
|
346 | def test_api_update_user_no_changed_params(self): | |
347 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
347 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
348 | ret = jsonify(usr.get_api_data()) |
|
348 | ret = jsonify(usr.get_api_data()) | |
349 | id_, params = _build_data(self.apikey, 'update_user', |
|
349 | id_, params = _build_data(self.apikey, 'update_user', | |
350 | userid=TEST_USER_ADMIN_LOGIN) |
|
350 | userid=TEST_USER_ADMIN_LOGIN) | |
351 |
|
351 | |||
352 | response = self.app.post(API_URL, content_type='application/json', |
|
352 | response = self.app.post(API_URL, content_type='application/json', | |
353 | params=params) |
|
353 | params=params) | |
354 | ret = { |
|
354 | ret = { | |
355 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), |
|
355 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), | |
356 | 'user': ret |
|
356 | 'user': ret | |
357 | } |
|
357 | } | |
358 | expected = ret |
|
358 | expected = ret | |
359 | self._compare_ok(id_, expected, given=response.body) |
|
359 | self._compare_ok(id_, expected, given=response.body) | |
360 |
|
360 | |||
361 | def test_api_update_user_by_user_id(self): |
|
361 | def test_api_update_user_by_user_id(self): | |
362 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
362 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
363 | ret = jsonify(usr.get_api_data()) |
|
363 | ret = jsonify(usr.get_api_data()) | |
364 | id_, params = _build_data(self.apikey, 'update_user', |
|
364 | id_, params = _build_data(self.apikey, 'update_user', | |
365 | userid=usr.user_id) |
|
365 | userid=usr.user_id) | |
366 |
|
366 | |||
367 | response = self.app.post(API_URL, content_type='application/json', |
|
367 | response = self.app.post(API_URL, content_type='application/json', | |
368 | params=params) |
|
368 | params=params) | |
369 | ret = { |
|
369 | ret = { | |
370 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), |
|
370 | 'msg': 'updated user ID:%s %s' % (usr.user_id, TEST_USER_ADMIN_LOGIN), | |
371 | 'user': ret |
|
371 | 'user': ret | |
372 | } |
|
372 | } | |
373 | expected = ret |
|
373 | expected = ret | |
374 | self._compare_ok(id_, expected, given=response.body) |
|
374 | self._compare_ok(id_, expected, given=response.body) | |
375 |
|
375 | |||
376 | @mock.patch.object(UserModel, 'update_user', crash) |
|
376 | @mock.patch.object(UserModel, 'update_user', crash) | |
377 | def test_api_update_user_when_exception_happens(self): |
|
377 | def test_api_update_user_when_exception_happens(self): | |
378 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) |
|
378 | usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) | |
379 | ret = jsonify(usr.get_api_data()) |
|
379 | ret = jsonify(usr.get_api_data()) | |
380 | id_, params = _build_data(self.apikey, 'update_user', |
|
380 | id_, params = _build_data(self.apikey, 'update_user', | |
381 | userid=usr.user_id) |
|
381 | userid=usr.user_id) | |
382 |
|
382 | |||
383 | response = self.app.post(API_URL, content_type='application/json', |
|
383 | response = self.app.post(API_URL, content_type='application/json', | |
384 | params=params) |
|
384 | params=params) | |
385 | ret = 'failed to update user `%s`' % usr.user_id |
|
385 | ret = 'failed to update user `%s`' % usr.user_id | |
386 |
|
386 | |||
387 | expected = ret |
|
387 | expected = ret | |
388 | self._compare_error(id_, expected, given=response.body) |
|
388 | self._compare_error(id_, expected, given=response.body) | |
389 |
|
389 | |||
390 | def test_api_get_repo(self): |
|
390 | def test_api_get_repo(self): | |
391 | new_group = 'some_new_group' |
|
391 | new_group = 'some_new_group' | |
392 | make_users_group(new_group) |
|
392 | make_users_group(new_group) | |
393 | RepoModel().grant_users_group_permission(repo=self.REPO, |
|
393 | RepoModel().grant_users_group_permission(repo=self.REPO, | |
394 | group_name=new_group, |
|
394 | group_name=new_group, | |
395 | perm='repository.read') |
|
395 | perm='repository.read') | |
396 | self.Session().commit() |
|
396 | self.Session().commit() | |
397 | id_, params = _build_data(self.apikey, 'get_repo', |
|
397 | id_, params = _build_data(self.apikey, 'get_repo', | |
398 | repoid=self.REPO) |
|
398 | repoid=self.REPO) | |
399 | response = self.app.post(API_URL, content_type='application/json', |
|
399 | response = self.app.post(API_URL, content_type='application/json', | |
400 | params=params) |
|
400 | params=params) | |
401 |
|
401 | |||
402 | repo = RepoModel().get_by_repo_name(self.REPO) |
|
402 | repo = RepoModel().get_by_repo_name(self.REPO) | |
403 | ret = repo.get_api_data() |
|
403 | ret = repo.get_api_data() | |
404 |
|
404 | |||
405 | members = [] |
|
405 | members = [] | |
406 | for user in repo.repo_to_perm: |
|
406 | for user in repo.repo_to_perm: | |
407 | perm = user.permission.permission_name |
|
407 | perm = user.permission.permission_name | |
408 | user = user.user |
|
408 | user = user.user | |
409 | user_data = user.get_api_data() |
|
409 | user_data = user.get_api_data() | |
410 | user_data['type'] = "user" |
|
410 | user_data['type'] = "user" | |
411 | user_data['permission'] = perm |
|
411 | user_data['permission'] = perm | |
412 | members.append(user_data) |
|
412 | members.append(user_data) | |
413 |
|
413 | |||
414 | for users_group in repo.users_group_to_perm: |
|
414 | for users_group in repo.users_group_to_perm: | |
415 | perm = users_group.permission.permission_name |
|
415 | perm = users_group.permission.permission_name | |
416 | users_group = users_group.users_group |
|
416 | users_group = users_group.users_group | |
417 | users_group_data = users_group.get_api_data() |
|
417 | users_group_data = users_group.get_api_data() | |
418 | users_group_data['type'] = "users_group" |
|
418 | users_group_data['type'] = "users_group" | |
419 | users_group_data['permission'] = perm |
|
419 | users_group_data['permission'] = perm | |
420 | members.append(users_group_data) |
|
420 | members.append(users_group_data) | |
421 |
|
421 | |||
422 | ret['members'] = members |
|
422 | ret['members'] = members | |
423 |
|
423 | |||
424 | expected = ret |
|
424 | expected = ret | |
425 | self._compare_ok(id_, expected, given=response.body) |
|
425 | self._compare_ok(id_, expected, given=response.body) | |
426 | destroy_users_group(new_group) |
|
426 | destroy_users_group(new_group) | |
427 |
|
427 | |||
428 | def test_api_get_repo_that_doesn_not_exist(self): |
|
428 | def test_api_get_repo_that_doesn_not_exist(self): | |
429 | id_, params = _build_data(self.apikey, 'get_repo', |
|
429 | id_, params = _build_data(self.apikey, 'get_repo', | |
430 | repoid='no-such-repo') |
|
430 | repoid='no-such-repo') | |
431 | response = self.app.post(API_URL, content_type='application/json', |
|
431 | response = self.app.post(API_URL, content_type='application/json', | |
432 | params=params) |
|
432 | params=params) | |
433 |
|
433 | |||
434 | ret = 'repository `%s` does not exist' % 'no-such-repo' |
|
434 | ret = 'repository `%s` does not exist' % 'no-such-repo' | |
435 | expected = ret |
|
435 | expected = ret | |
436 | self._compare_error(id_, expected, given=response.body) |
|
436 | self._compare_error(id_, expected, given=response.body) | |
437 |
|
437 | |||
438 | def test_api_get_repos(self): |
|
438 | def test_api_get_repos(self): | |
439 | id_, params = _build_data(self.apikey, 'get_repos') |
|
439 | id_, params = _build_data(self.apikey, 'get_repos') | |
440 | response = self.app.post(API_URL, content_type='application/json', |
|
440 | response = self.app.post(API_URL, content_type='application/json', | |
441 | params=params) |
|
441 | params=params) | |
442 |
|
442 | |||
443 | result = [] |
|
443 | result = [] | |
444 | for repo in RepoModel().get_all(): |
|
444 | for repo in RepoModel().get_all(): | |
445 | result.append(repo.get_api_data()) |
|
445 | result.append(repo.get_api_data()) | |
446 | ret = jsonify(result) |
|
446 | ret = jsonify(result) | |
447 |
|
447 | |||
448 | expected = ret |
|
448 | expected = ret | |
449 | self._compare_ok(id_, expected, given=response.body) |
|
449 | self._compare_ok(id_, expected, given=response.body) | |
450 |
|
450 | |||
451 | @parameterized.expand([('all', 'all'), |
|
451 | @parameterized.expand([('all', 'all'), | |
452 | ('dirs', 'dirs'), |
|
452 | ('dirs', 'dirs'), | |
453 | ('files', 'files'), ]) |
|
453 | ('files', 'files'), ]) | |
454 | def test_api_get_repo_nodes(self, name, ret_type): |
|
454 | def test_api_get_repo_nodes(self, name, ret_type): | |
455 | rev = 'tip' |
|
455 | rev = 'tip' | |
456 | path = '/' |
|
456 | path = '/' | |
457 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
457 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
458 | repoid=self.REPO, revision=rev, |
|
458 | repoid=self.REPO, revision=rev, | |
459 | root_path=path, |
|
459 | root_path=path, | |
460 | ret_type=ret_type) |
|
460 | ret_type=ret_type) | |
461 | response = self.app.post(API_URL, content_type='application/json', |
|
461 | response = self.app.post(API_URL, content_type='application/json', | |
462 | params=params) |
|
462 | params=params) | |
463 |
|
463 | |||
464 | # we don't the actual return types here since it's tested somewhere |
|
464 | # we don't the actual return types here since it's tested somewhere | |
465 | # else |
|
465 | # else | |
466 | expected = json.loads(response.body)['result'] |
|
466 | expected = json.loads(response.body)['result'] | |
467 | self._compare_ok(id_, expected, given=response.body) |
|
467 | self._compare_ok(id_, expected, given=response.body) | |
468 |
|
468 | |||
469 | def test_api_get_repo_nodes_bad_revisions(self): |
|
469 | def test_api_get_repo_nodes_bad_revisions(self): | |
470 | rev = 'i-dont-exist' |
|
470 | rev = 'i-dont-exist' | |
471 | path = '/' |
|
471 | path = '/' | |
472 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
472 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
473 | repoid=self.REPO, revision=rev, |
|
473 | repoid=self.REPO, revision=rev, | |
474 | root_path=path,) |
|
474 | root_path=path,) | |
475 | response = self.app.post(API_URL, content_type='application/json', |
|
475 | response = self.app.post(API_URL, content_type='application/json', | |
476 | params=params) |
|
476 | params=params) | |
477 |
|
477 | |||
478 | expected = 'failed to get repo: `%s` nodes' % self.REPO |
|
478 | expected = 'failed to get repo: `%s` nodes' % self.REPO | |
479 | self._compare_error(id_, expected, given=response.body) |
|
479 | self._compare_error(id_, expected, given=response.body) | |
480 |
|
480 | |||
481 | def test_api_get_repo_nodes_bad_path(self): |
|
481 | def test_api_get_repo_nodes_bad_path(self): | |
482 | rev = 'tip' |
|
482 | rev = 'tip' | |
483 | path = '/idontexits' |
|
483 | path = '/idontexits' | |
484 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
484 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
485 | repoid=self.REPO, revision=rev, |
|
485 | repoid=self.REPO, revision=rev, | |
486 | root_path=path,) |
|
486 | root_path=path,) | |
487 | response = self.app.post(API_URL, content_type='application/json', |
|
487 | response = self.app.post(API_URL, content_type='application/json', | |
488 | params=params) |
|
488 | params=params) | |
489 |
|
489 | |||
490 | expected = 'failed to get repo: `%s` nodes' % self.REPO |
|
490 | expected = 'failed to get repo: `%s` nodes' % self.REPO | |
491 | self._compare_error(id_, expected, given=response.body) |
|
491 | self._compare_error(id_, expected, given=response.body) | |
492 |
|
492 | |||
493 | def test_api_get_repo_nodes_bad_ret_type(self): |
|
493 | def test_api_get_repo_nodes_bad_ret_type(self): | |
494 | rev = 'tip' |
|
494 | rev = 'tip' | |
495 | path = '/' |
|
495 | path = '/' | |
496 | ret_type = 'error' |
|
496 | ret_type = 'error' | |
497 | id_, params = _build_data(self.apikey, 'get_repo_nodes', |
|
497 | id_, params = _build_data(self.apikey, 'get_repo_nodes', | |
498 | repoid=self.REPO, revision=rev, |
|
498 | repoid=self.REPO, revision=rev, | |
499 | root_path=path, |
|
499 | root_path=path, | |
500 | ret_type=ret_type) |
|
500 | ret_type=ret_type) | |
501 | response = self.app.post(API_URL, content_type='application/json', |
|
501 | response = self.app.post(API_URL, content_type='application/json', | |
502 | params=params) |
|
502 | params=params) | |
503 |
|
503 | |||
504 | expected = 'ret_type must be one of %s' % (['files', 'dirs', 'all']) |
|
504 | expected = 'ret_type must be one of %s' % (['files', 'dirs', 'all']) | |
505 | self._compare_error(id_, expected, given=response.body) |
|
505 | self._compare_error(id_, expected, given=response.body) | |
506 |
|
506 | |||
507 | def test_api_create_repo(self): |
|
507 | def test_api_create_repo(self): | |
508 | repo_name = 'api-repo' |
|
508 | repo_name = 'api-repo' | |
509 | id_, params = _build_data(self.apikey, 'create_repo', |
|
509 | id_, params = _build_data(self.apikey, 'create_repo', | |
510 | repo_name=repo_name, |
|
510 | repo_name=repo_name, | |
511 | owner=TEST_USER_ADMIN_LOGIN, |
|
511 | owner=TEST_USER_ADMIN_LOGIN, | |
512 | repo_type='hg', |
|
512 | repo_type='hg', | |
513 | ) |
|
513 | ) | |
514 | response = self.app.post(API_URL, content_type='application/json', |
|
514 | response = self.app.post(API_URL, content_type='application/json', | |
515 | params=params) |
|
515 | params=params) | |
516 |
|
516 | |||
517 | repo = RepoModel().get_by_repo_name(repo_name) |
|
517 | repo = RepoModel().get_by_repo_name(repo_name) | |
518 | ret = { |
|
518 | ret = { | |
519 | 'msg': 'Created new repository `%s`' % repo_name, |
|
519 | 'msg': 'Created new repository `%s`' % repo_name, | |
520 | 'repo': jsonify(repo.get_api_data()) |
|
520 | 'repo': jsonify(repo.get_api_data()) | |
521 | } |
|
521 | } | |
522 | expected = ret |
|
522 | expected = ret | |
523 | self._compare_ok(id_, expected, given=response.body) |
|
523 | self._compare_ok(id_, expected, given=response.body) | |
524 | destroy_repo(repo_name) |
|
524 | destroy_repo(repo_name) | |
525 |
|
525 | |||
526 | def test_api_create_repo_unknown_owner(self): |
|
526 | def test_api_create_repo_unknown_owner(self): | |
527 | repo_name = 'api-repo' |
|
527 | repo_name = 'api-repo' | |
528 | owner = 'i-dont-exist' |
|
528 | owner = 'i-dont-exist' | |
529 | id_, params = _build_data(self.apikey, 'create_repo', |
|
529 | id_, params = _build_data(self.apikey, 'create_repo', | |
530 | repo_name=repo_name, |
|
530 | repo_name=repo_name, | |
531 | owner=owner, |
|
531 | owner=owner, | |
532 | repo_type='hg', |
|
532 | repo_type='hg', | |
533 | ) |
|
533 | ) | |
534 | response = self.app.post(API_URL, content_type='application/json', |
|
534 | response = self.app.post(API_URL, content_type='application/json', | |
535 | params=params) |
|
535 | params=params) | |
536 | expected = 'user `%s` does not exist' % owner |
|
536 | expected = 'user `%s` does not exist' % owner | |
537 | self._compare_error(id_, expected, given=response.body) |
|
537 | self._compare_error(id_, expected, given=response.body) | |
538 |
|
538 | |||
539 | def test_api_create_repo_exists(self): |
|
539 | def test_api_create_repo_exists(self): | |
540 | repo_name = self.REPO |
|
540 | repo_name = self.REPO | |
541 | id_, params = _build_data(self.apikey, 'create_repo', |
|
541 | id_, params = _build_data(self.apikey, 'create_repo', | |
542 | repo_name=repo_name, |
|
542 | repo_name=repo_name, | |
543 | owner=TEST_USER_ADMIN_LOGIN, |
|
543 | owner=TEST_USER_ADMIN_LOGIN, | |
544 | repo_type='hg', |
|
544 | repo_type='hg', | |
545 | ) |
|
545 | ) | |
546 | response = self.app.post(API_URL, content_type='application/json', |
|
546 | response = self.app.post(API_URL, content_type='application/json', | |
547 | params=params) |
|
547 | params=params) | |
548 | expected = "repo `%s` already exist" % repo_name |
|
548 | expected = "repo `%s` already exist" % repo_name | |
549 | self._compare_error(id_, expected, given=response.body) |
|
549 | self._compare_error(id_, expected, given=response.body) | |
550 |
|
550 | |||
551 | @mock.patch.object(RepoModel, 'create_repo', crash) |
|
551 | @mock.patch.object(RepoModel, 'create_repo', crash) | |
552 | def test_api_create_repo_exception_occurred(self): |
|
552 | def test_api_create_repo_exception_occurred(self): | |
553 | repo_name = 'api-repo' |
|
553 | repo_name = 'api-repo' | |
554 | id_, params = _build_data(self.apikey, 'create_repo', |
|
554 | id_, params = _build_data(self.apikey, 'create_repo', | |
555 | repo_name=repo_name, |
|
555 | repo_name=repo_name, | |
556 | owner=TEST_USER_ADMIN_LOGIN, |
|
556 | owner=TEST_USER_ADMIN_LOGIN, | |
557 | repo_type='hg', |
|
557 | repo_type='hg', | |
558 | ) |
|
558 | ) | |
559 | response = self.app.post(API_URL, content_type='application/json', |
|
559 | response = self.app.post(API_URL, content_type='application/json', | |
560 | params=params) |
|
560 | params=params) | |
561 | expected = 'failed to create repository `%s`' % repo_name |
|
561 | expected = 'failed to create repository `%s`' % repo_name | |
562 | self._compare_error(id_, expected, given=response.body) |
|
562 | self._compare_error(id_, expected, given=response.body) | |
563 |
|
563 | |||
564 | def test_api_delete_repo(self): |
|
564 | def test_api_delete_repo(self): | |
565 | repo_name = 'api_delete_me' |
|
565 | repo_name = 'api_delete_me' | |
566 | create_repo(repo_name, self.REPO_TYPE) |
|
566 | create_repo(repo_name, self.REPO_TYPE) | |
567 |
|
567 | |||
568 | id_, params = _build_data(self.apikey, 'delete_repo', |
|
568 | id_, params = _build_data(self.apikey, 'delete_repo', | |
569 | repoid=repo_name,) |
|
569 | repoid=repo_name,) | |
570 | response = self.app.post(API_URL, content_type='application/json', |
|
570 | response = self.app.post(API_URL, content_type='application/json', | |
571 | params=params) |
|
571 | params=params) | |
572 |
|
572 | |||
573 | ret = { |
|
573 | ret = { | |
574 | 'msg': 'Deleted repository `%s`' % repo_name, |
|
574 | 'msg': 'Deleted repository `%s`' % repo_name, | |
575 | 'success': True |
|
575 | 'success': True | |
576 | } |
|
576 | } | |
577 | expected = ret |
|
577 | expected = ret | |
578 | self._compare_ok(id_, expected, given=response.body) |
|
578 | self._compare_ok(id_, expected, given=response.body) | |
579 |
|
579 | |||
580 | def test_api_delete_repo_exception_occurred(self): |
|
580 | def test_api_delete_repo_exception_occurred(self): | |
581 | repo_name = 'api_delete_me' |
|
581 | repo_name = 'api_delete_me' | |
582 | create_repo(repo_name, self.REPO_TYPE) |
|
582 | create_repo(repo_name, self.REPO_TYPE) | |
583 | try: |
|
583 | try: | |
584 | with mock.patch.object(RepoModel, 'delete', crash): |
|
584 | with mock.patch.object(RepoModel, 'delete', crash): | |
585 | id_, params = _build_data(self.apikey, 'delete_repo', |
|
585 | id_, params = _build_data(self.apikey, 'delete_repo', | |
586 | repoid=repo_name,) |
|
586 | repoid=repo_name,) | |
587 | response = self.app.post(API_URL, content_type='application/json', |
|
587 | response = self.app.post(API_URL, content_type='application/json', | |
588 | params=params) |
|
588 | params=params) | |
589 |
|
589 | |||
590 | expected = 'failed to delete repository `%s`' % repo_name |
|
590 | expected = 'failed to delete repository `%s`' % repo_name | |
591 | self._compare_error(id_, expected, given=response.body) |
|
591 | self._compare_error(id_, expected, given=response.body) | |
592 | finally: |
|
592 | finally: | |
593 | destroy_repo(repo_name) |
|
593 | destroy_repo(repo_name) | |
594 |
|
594 | |||
595 | def test_api_fork_repo(self): |
|
595 | def test_api_fork_repo(self): | |
596 | fork_name = 'api-repo-fork' |
|
596 | fork_name = 'api-repo-fork' | |
597 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
597 | id_, params = _build_data(self.apikey, 'fork_repo', | |
598 | repoid=self.REPO, |
|
598 | repoid=self.REPO, | |
599 | fork_name=fork_name, |
|
599 | fork_name=fork_name, | |
600 | owner=TEST_USER_ADMIN_LOGIN, |
|
600 | owner=TEST_USER_ADMIN_LOGIN, | |
601 | ) |
|
601 | ) | |
602 | response = self.app.post(API_URL, content_type='application/json', |
|
602 | response = self.app.post(API_URL, content_type='application/json', | |
603 | params=params) |
|
603 | params=params) | |
604 |
|
604 | |||
605 | ret = { |
|
605 | ret = { | |
606 | 'msg': 'Created fork of `%s` as `%s`' % (self.REPO, |
|
606 | 'msg': 'Created fork of `%s` as `%s`' % (self.REPO, | |
607 | fork_name), |
|
607 | fork_name), | |
608 | 'success': True |
|
608 | 'success': True | |
609 | } |
|
609 | } | |
610 | expected = ret |
|
610 | expected = ret | |
611 | self._compare_ok(id_, expected, given=response.body) |
|
611 | self._compare_ok(id_, expected, given=response.body) | |
612 | destroy_repo(fork_name) |
|
612 | destroy_repo(fork_name) | |
613 |
|
613 | |||
614 | def test_api_fork_repo_unknown_owner(self): |
|
614 | def test_api_fork_repo_unknown_owner(self): | |
615 | fork_name = 'api-repo-fork' |
|
615 | fork_name = 'api-repo-fork' | |
616 | owner = 'i-dont-exist' |
|
616 | owner = 'i-dont-exist' | |
617 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
617 | id_, params = _build_data(self.apikey, 'fork_repo', | |
618 | repoid=self.REPO, |
|
618 | repoid=self.REPO, | |
619 | fork_name=fork_name, |
|
619 | fork_name=fork_name, | |
620 | owner=owner, |
|
620 | owner=owner, | |
621 | ) |
|
621 | ) | |
622 | response = self.app.post(API_URL, content_type='application/json', |
|
622 | response = self.app.post(API_URL, content_type='application/json', | |
623 | params=params) |
|
623 | params=params) | |
624 | expected = 'user `%s` does not exist' % owner |
|
624 | expected = 'user `%s` does not exist' % owner | |
625 | self._compare_error(id_, expected, given=response.body) |
|
625 | self._compare_error(id_, expected, given=response.body) | |
626 |
|
626 | |||
627 | def test_api_fork_repo_fork_exists(self): |
|
627 | def test_api_fork_repo_fork_exists(self): | |
628 | fork_name = 'api-repo-fork' |
|
628 | fork_name = 'api-repo-fork' | |
629 | create_fork(fork_name, self.REPO_TYPE, self.REPO) |
|
629 | create_fork(fork_name, self.REPO_TYPE, self.REPO) | |
630 |
|
630 | |||
631 | try: |
|
631 | try: | |
632 | fork_name = 'api-repo-fork' |
|
632 | fork_name = 'api-repo-fork' | |
633 |
|
633 | |||
634 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
634 | id_, params = _build_data(self.apikey, 'fork_repo', | |
635 | repoid=self.REPO, |
|
635 | repoid=self.REPO, | |
636 | fork_name=fork_name, |
|
636 | fork_name=fork_name, | |
637 | owner=TEST_USER_ADMIN_LOGIN, |
|
637 | owner=TEST_USER_ADMIN_LOGIN, | |
638 | ) |
|
638 | ) | |
639 | response = self.app.post(API_URL, content_type='application/json', |
|
639 | response = self.app.post(API_URL, content_type='application/json', | |
640 | params=params) |
|
640 | params=params) | |
641 |
|
641 | |||
642 | expected = "fork `%s` already exist" % fork_name |
|
642 | expected = "fork `%s` already exist" % fork_name | |
643 | self._compare_error(id_, expected, given=response.body) |
|
643 | self._compare_error(id_, expected, given=response.body) | |
644 | finally: |
|
644 | finally: | |
645 | destroy_repo(fork_name) |
|
645 | destroy_repo(fork_name) | |
646 |
|
646 | |||
647 | def test_api_fork_repo_repo_exists(self): |
|
647 | def test_api_fork_repo_repo_exists(self): | |
648 | fork_name = self.REPO |
|
648 | fork_name = self.REPO | |
649 |
|
649 | |||
650 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
650 | id_, params = _build_data(self.apikey, 'fork_repo', | |
651 | repoid=self.REPO, |
|
651 | repoid=self.REPO, | |
652 | fork_name=fork_name, |
|
652 | fork_name=fork_name, | |
653 | owner=TEST_USER_ADMIN_LOGIN, |
|
653 | owner=TEST_USER_ADMIN_LOGIN, | |
654 | ) |
|
654 | ) | |
655 | response = self.app.post(API_URL, content_type='application/json', |
|
655 | response = self.app.post(API_URL, content_type='application/json', | |
656 | params=params) |
|
656 | params=params) | |
657 |
|
657 | |||
658 | expected = "repo `%s` already exist" % fork_name |
|
658 | expected = "repo `%s` already exist" % fork_name | |
659 | self._compare_error(id_, expected, given=response.body) |
|
659 | self._compare_error(id_, expected, given=response.body) | |
660 |
|
660 | |||
661 | @mock.patch.object(RepoModel, 'create_fork', crash) |
|
661 | @mock.patch.object(RepoModel, 'create_fork', crash) | |
662 | def test_api_fork_repo_exception_occurred(self): |
|
662 | def test_api_fork_repo_exception_occurred(self): | |
663 | fork_name = 'api-repo-fork' |
|
663 | fork_name = 'api-repo-fork' | |
664 | id_, params = _build_data(self.apikey, 'fork_repo', |
|
664 | id_, params = _build_data(self.apikey, 'fork_repo', | |
665 | repoid=self.REPO, |
|
665 | repoid=self.REPO, | |
666 | fork_name=fork_name, |
|
666 | fork_name=fork_name, | |
667 | owner=TEST_USER_ADMIN_LOGIN, |
|
667 | owner=TEST_USER_ADMIN_LOGIN, | |
668 | ) |
|
668 | ) | |
669 | response = self.app.post(API_URL, content_type='application/json', |
|
669 | response = self.app.post(API_URL, content_type='application/json', | |
670 | params=params) |
|
670 | params=params) | |
671 |
|
671 | |||
672 | expected = 'failed to fork repository `%s` as `%s`' % (self.REPO, |
|
672 | expected = 'failed to fork repository `%s` as `%s`' % (self.REPO, | |
673 | fork_name) |
|
673 | fork_name) | |
674 | self._compare_error(id_, expected, given=response.body) |
|
674 | self._compare_error(id_, expected, given=response.body) | |
675 |
|
675 | |||
676 | def test_api_get_users_group(self): |
|
676 | def test_api_get_users_group(self): | |
677 | id_, params = _build_data(self.apikey, 'get_users_group', |
|
677 | id_, params = _build_data(self.apikey, 'get_users_group', | |
678 | usersgroupid=TEST_USERS_GROUP) |
|
678 | usersgroupid=TEST_USERS_GROUP) | |
679 | response = self.app.post(API_URL, content_type='application/json', |
|
679 | response = self.app.post(API_URL, content_type='application/json', | |
680 | params=params) |
|
680 | params=params) | |
681 |
|
681 | |||
682 | users_group = UsersGroupModel().get_group(TEST_USERS_GROUP) |
|
682 | users_group = UsersGroupModel().get_group(TEST_USERS_GROUP) | |
683 | members = [] |
|
683 | members = [] | |
684 | for user in users_group.members: |
|
684 | for user in users_group.members: | |
685 | user = user.user |
|
685 | user = user.user | |
686 | members.append(user.get_api_data()) |
|
686 | members.append(user.get_api_data()) | |
687 |
|
687 | |||
688 | ret = users_group.get_api_data() |
|
688 | ret = users_group.get_api_data() | |
689 | ret['members'] = members |
|
689 | ret['members'] = members | |
690 | expected = ret |
|
690 | expected = ret | |
691 | self._compare_ok(id_, expected, given=response.body) |
|
691 | self._compare_ok(id_, expected, given=response.body) | |
692 |
|
692 | |||
693 | def test_api_get_users_groups(self): |
|
693 | def test_api_get_users_groups(self): | |
694 |
|
694 | |||
695 | make_users_group('test_users_group2') |
|
695 | make_users_group('test_users_group2') | |
696 |
|
696 | |||
697 | id_, params = _build_data(self.apikey, 'get_users_groups',) |
|
697 | id_, params = _build_data(self.apikey, 'get_users_groups',) | |
698 | response = self.app.post(API_URL, content_type='application/json', |
|
698 | response = self.app.post(API_URL, content_type='application/json', | |
699 | params=params) |
|
699 | params=params) | |
700 |
|
700 | |||
701 | expected = [] |
|
701 | expected = [] | |
702 | for gr_name in [TEST_USERS_GROUP, 'test_users_group2']: |
|
702 | for gr_name in [TEST_USERS_GROUP, 'test_users_group2']: | |
703 | users_group = UsersGroupModel().get_group(gr_name) |
|
703 | users_group = UsersGroupModel().get_group(gr_name) | |
704 | ret = users_group.get_api_data() |
|
704 | ret = users_group.get_api_data() | |
705 | expected.append(ret) |
|
705 | expected.append(ret) | |
706 | self._compare_ok(id_, expected, given=response.body) |
|
706 | self._compare_ok(id_, expected, given=response.body) | |
707 |
|
707 | |||
708 | UsersGroupModel().delete(users_group='test_users_group2') |
|
708 | UsersGroupModel().delete(users_group='test_users_group2') | |
709 | self.Session().commit() |
|
709 | self.Session().commit() | |
710 |
|
710 | |||
711 | def test_api_create_users_group(self): |
|
711 | def test_api_create_users_group(self): | |
712 | group_name = 'some_new_group' |
|
712 | group_name = 'some_new_group' | |
713 | id_, params = _build_data(self.apikey, 'create_users_group', |
|
713 | id_, params = _build_data(self.apikey, 'create_users_group', | |
714 | group_name=group_name) |
|
714 | group_name=group_name) | |
715 | response = self.app.post(API_URL, content_type='application/json', |
|
715 | response = self.app.post(API_URL, content_type='application/json', | |
716 | params=params) |
|
716 | params=params) | |
717 |
|
717 | |||
718 | ret = { |
|
718 | ret = { | |
719 | 'msg': 'created new users group `%s`' % group_name, |
|
719 | 'msg': 'created new users group `%s`' % group_name, | |
720 | 'users_group': jsonify(UsersGroupModel()\ |
|
720 | 'users_group': jsonify(UsersGroupModel()\ | |
721 | .get_by_name(group_name)\ |
|
721 | .get_by_name(group_name)\ | |
722 | .get_api_data()) |
|
722 | .get_api_data()) | |
723 | } |
|
723 | } | |
724 | expected = ret |
|
724 | expected = ret | |
725 | self._compare_ok(id_, expected, given=response.body) |
|
725 | self._compare_ok(id_, expected, given=response.body) | |
726 |
|
726 | |||
727 | destroy_users_group(group_name) |
|
727 | destroy_users_group(group_name) | |
728 |
|
728 | |||
729 | def test_api_get_users_group_that_exist(self): |
|
729 | def test_api_get_users_group_that_exist(self): | |
730 | id_, params = _build_data(self.apikey, 'create_users_group', |
|
730 | id_, params = _build_data(self.apikey, 'create_users_group', | |
731 | group_name=TEST_USERS_GROUP) |
|
731 | group_name=TEST_USERS_GROUP) | |
732 | response = self.app.post(API_URL, content_type='application/json', |
|
732 | response = self.app.post(API_URL, content_type='application/json', | |
733 | params=params) |
|
733 | params=params) | |
734 |
|
734 | |||
735 | expected = "users group `%s` already exist" % TEST_USERS_GROUP |
|
735 | expected = "users group `%s` already exist" % TEST_USERS_GROUP | |
736 | self._compare_error(id_, expected, given=response.body) |
|
736 | self._compare_error(id_, expected, given=response.body) | |
737 |
|
737 | |||
738 | @mock.patch.object(UsersGroupModel, 'create', crash) |
|
738 | @mock.patch.object(UsersGroupModel, 'create', crash) | |
739 | def test_api_get_users_group_exception_occurred(self): |
|
739 | def test_api_get_users_group_exception_occurred(self): | |
740 | group_name = 'exception_happens' |
|
740 | group_name = 'exception_happens' | |
741 | id_, params = _build_data(self.apikey, 'create_users_group', |
|
741 | id_, params = _build_data(self.apikey, 'create_users_group', | |
742 | group_name=group_name) |
|
742 | group_name=group_name) | |
743 | response = self.app.post(API_URL, content_type='application/json', |
|
743 | response = self.app.post(API_URL, content_type='application/json', | |
744 | params=params) |
|
744 | params=params) | |
745 |
|
745 | |||
746 | expected = 'failed to create group `%s`' % group_name |
|
746 | expected = 'failed to create group `%s`' % group_name | |
747 | self._compare_error(id_, expected, given=response.body) |
|
747 | self._compare_error(id_, expected, given=response.body) | |
748 |
|
748 | |||
749 | def test_api_add_user_to_users_group(self): |
|
749 | def test_api_add_user_to_users_group(self): | |
750 | gr_name = 'test_group' |
|
750 | gr_name = 'test_group' | |
751 | UsersGroupModel().create(gr_name) |
|
751 | UsersGroupModel().create(gr_name) | |
752 | self.Session().commit() |
|
752 | self.Session().commit() | |
753 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
753 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', | |
754 | usersgroupid=gr_name, |
|
754 | usersgroupid=gr_name, | |
755 | userid=TEST_USER_ADMIN_LOGIN) |
|
755 | userid=TEST_USER_ADMIN_LOGIN) | |
756 | response = self.app.post(API_URL, content_type='application/json', |
|
756 | response = self.app.post(API_URL, content_type='application/json', | |
757 | params=params) |
|
757 | params=params) | |
758 |
|
758 | |||
759 | expected = { |
|
759 | expected = { | |
760 | 'msg': 'added member `%s` to users group `%s`' % ( |
|
760 | 'msg': 'added member `%s` to users group `%s`' % ( | |
761 | TEST_USER_ADMIN_LOGIN, gr_name |
|
761 | TEST_USER_ADMIN_LOGIN, gr_name | |
762 | ), |
|
762 | ), | |
763 | 'success': True} |
|
763 | 'success': True} | |
764 | self._compare_ok(id_, expected, given=response.body) |
|
764 | self._compare_ok(id_, expected, given=response.body) | |
765 |
|
765 | |||
766 | UsersGroupModel().delete(users_group=gr_name) |
|
766 | UsersGroupModel().delete(users_group=gr_name) | |
767 | self.Session().commit() |
|
767 | self.Session().commit() | |
768 |
|
768 | |||
769 | def test_api_add_user_to_users_group_that_doesnt_exist(self): |
|
769 | def test_api_add_user_to_users_group_that_doesnt_exist(self): | |
770 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
770 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', | |
771 | usersgroupid='false-group', |
|
771 | usersgroupid='false-group', | |
772 | userid=TEST_USER_ADMIN_LOGIN) |
|
772 | userid=TEST_USER_ADMIN_LOGIN) | |
773 | response = self.app.post(API_URL, content_type='application/json', |
|
773 | response = self.app.post(API_URL, content_type='application/json', | |
774 | params=params) |
|
774 | params=params) | |
775 |
|
775 | |||
776 | expected = 'users group `%s` does not exist' % 'false-group' |
|
776 | expected = 'users group `%s` does not exist' % 'false-group' | |
777 | self._compare_error(id_, expected, given=response.body) |
|
777 | self._compare_error(id_, expected, given=response.body) | |
778 |
|
778 | |||
779 | @mock.patch.object(UsersGroupModel, 'add_user_to_group', crash) |
|
779 | @mock.patch.object(UsersGroupModel, 'add_user_to_group', crash) | |
780 | def test_api_add_user_to_users_group_exception_occurred(self): |
|
780 | def test_api_add_user_to_users_group_exception_occurred(self): | |
781 | gr_name = 'test_group' |
|
781 | gr_name = 'test_group' | |
782 | UsersGroupModel().create(gr_name) |
|
782 | UsersGroupModel().create(gr_name) | |
783 | self.Session().commit() |
|
783 | self.Session().commit() | |
784 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', |
|
784 | id_, params = _build_data(self.apikey, 'add_user_to_users_group', | |
785 | usersgroupid=gr_name, |
|
785 | usersgroupid=gr_name, | |
786 | userid=TEST_USER_ADMIN_LOGIN) |
|
786 | userid=TEST_USER_ADMIN_LOGIN) | |
787 | response = self.app.post(API_URL, content_type='application/json', |
|
787 | response = self.app.post(API_URL, content_type='application/json', | |
788 | params=params) |
|
788 | params=params) | |
789 |
|
789 | |||
790 | expected = 'failed to add member to users group `%s`' % gr_name |
|
790 | expected = 'failed to add member to users group `%s`' % gr_name | |
791 | self._compare_error(id_, expected, given=response.body) |
|
791 | self._compare_error(id_, expected, given=response.body) | |
792 |
|
792 | |||
793 | UsersGroupModel().delete(users_group=gr_name) |
|
793 | UsersGroupModel().delete(users_group=gr_name) | |
794 | self.Session().commit() |
|
794 | self.Session().commit() | |
795 |
|
795 | |||
796 | def test_api_remove_user_from_users_group(self): |
|
796 | def test_api_remove_user_from_users_group(self): | |
797 | gr_name = 'test_group_3' |
|
797 | gr_name = 'test_group_3' | |
798 | gr = UsersGroupModel().create(gr_name) |
|
798 | gr = UsersGroupModel().create(gr_name) | |
799 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) |
|
799 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) | |
800 | self.Session().commit() |
|
800 | self.Session().commit() | |
801 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', |
|
801 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', | |
802 | usersgroupid=gr_name, |
|
802 | usersgroupid=gr_name, | |
803 | userid=TEST_USER_ADMIN_LOGIN) |
|
803 | userid=TEST_USER_ADMIN_LOGIN) | |
804 | response = self.app.post(API_URL, content_type='application/json', |
|
804 | response = self.app.post(API_URL, content_type='application/json', | |
805 | params=params) |
|
805 | params=params) | |
806 |
|
806 | |||
807 | expected = { |
|
807 | expected = { | |
808 | 'msg': 'removed member `%s` from users group `%s`' % ( |
|
808 | 'msg': 'removed member `%s` from users group `%s`' % ( | |
809 | TEST_USER_ADMIN_LOGIN, gr_name |
|
809 | TEST_USER_ADMIN_LOGIN, gr_name | |
810 | ), |
|
810 | ), | |
811 | 'success': True} |
|
811 | 'success': True} | |
812 | self._compare_ok(id_, expected, given=response.body) |
|
812 | self._compare_ok(id_, expected, given=response.body) | |
813 |
|
813 | |||
814 | UsersGroupModel().delete(users_group=gr_name) |
|
814 | UsersGroupModel().delete(users_group=gr_name) | |
815 | self.Session().commit() |
|
815 | self.Session().commit() | |
816 |
|
816 | |||
817 | @mock.patch.object(UsersGroupModel, 'remove_user_from_group', crash) |
|
817 | @mock.patch.object(UsersGroupModel, 'remove_user_from_group', crash) | |
818 | def test_api_remove_user_from_users_group_exception_occurred(self): |
|
818 | def test_api_remove_user_from_users_group_exception_occurred(self): | |
819 | gr_name = 'test_group_3' |
|
819 | gr_name = 'test_group_3' | |
820 | gr = UsersGroupModel().create(gr_name) |
|
820 | gr = UsersGroupModel().create(gr_name) | |
821 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) |
|
821 | UsersGroupModel().add_user_to_group(gr, user=TEST_USER_ADMIN_LOGIN) | |
822 | self.Session().commit() |
|
822 | self.Session().commit() | |
823 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', |
|
823 | id_, params = _build_data(self.apikey, 'remove_user_from_users_group', | |
824 | usersgroupid=gr_name, |
|
824 | usersgroupid=gr_name, | |
825 | userid=TEST_USER_ADMIN_LOGIN) |
|
825 | userid=TEST_USER_ADMIN_LOGIN) | |
826 | response = self.app.post(API_URL, content_type='application/json', |
|
826 | response = self.app.post(API_URL, content_type='application/json', | |
827 | params=params) |
|
827 | params=params) | |
828 |
|
828 | |||
829 | expected = 'failed to remove member from users group `%s`' % gr_name |
|
829 | expected = 'failed to remove member from users group `%s`' % gr_name | |
830 | self._compare_error(id_, expected, given=response.body) |
|
830 | self._compare_error(id_, expected, given=response.body) | |
831 |
|
831 | |||
832 | UsersGroupModel().delete(users_group=gr_name) |
|
832 | UsersGroupModel().delete(users_group=gr_name) | |
833 | self.Session().commit() |
|
833 | self.Session().commit() | |
834 |
|
834 | |||
835 | @parameterized.expand([('none', 'repository.none'), |
|
835 | @parameterized.expand([('none', 'repository.none'), | |
836 | ('read', 'repository.read'), |
|
836 | ('read', 'repository.read'), | |
837 | ('write', 'repository.write'), |
|
837 | ('write', 'repository.write'), | |
838 | ('admin', 'repository.admin')]) |
|
838 | ('admin', 'repository.admin')]) | |
839 | def test_api_grant_user_permission(self, name, perm): |
|
839 | def test_api_grant_user_permission(self, name, perm): | |
840 | id_, params = _build_data(self.apikey, 'grant_user_permission', |
|
840 | id_, params = _build_data(self.apikey, 'grant_user_permission', | |
841 | repoid=self.REPO, |
|
841 | repoid=self.REPO, | |
842 | userid=TEST_USER_ADMIN_LOGIN, |
|
842 | userid=TEST_USER_ADMIN_LOGIN, | |
843 | perm=perm) |
|
843 | perm=perm) | |
844 | response = self.app.post(API_URL, content_type='application/json', |
|
844 | response = self.app.post(API_URL, content_type='application/json', | |
845 | params=params) |
|
845 | params=params) | |
846 |
|
846 | |||
847 | ret = { |
|
847 | ret = { | |
848 | 'msg': 'Granted perm: `%s` for user: `%s` in repo: `%s`' % ( |
|
848 | 'msg': 'Granted perm: `%s` for user: `%s` in repo: `%s`' % ( | |
849 | perm, TEST_USER_ADMIN_LOGIN, self.REPO |
|
849 | perm, TEST_USER_ADMIN_LOGIN, self.REPO | |
850 | ), |
|
850 | ), | |
851 | 'success': True |
|
851 | 'success': True | |
852 | } |
|
852 | } | |
853 | expected = ret |
|
853 | expected = ret | |
854 | self._compare_ok(id_, expected, given=response.body) |
|
854 | self._compare_ok(id_, expected, given=response.body) | |
855 |
|
855 | |||
856 | def test_api_grant_user_permission_wrong_permission(self): |
|
856 | def test_api_grant_user_permission_wrong_permission(self): | |
857 | perm = 'haha.no.permission' |
|
857 | perm = 'haha.no.permission' | |
858 | id_, params = _build_data(self.apikey, 'grant_user_permission', |
|
858 | id_, params = _build_data(self.apikey, 'grant_user_permission', | |
859 | repoid=self.REPO, |
|
859 | repoid=self.REPO, | |
860 | userid=TEST_USER_ADMIN_LOGIN, |
|
860 | userid=TEST_USER_ADMIN_LOGIN, | |
861 | perm=perm) |
|
861 | perm=perm) | |
862 | response = self.app.post(API_URL, content_type='application/json', |
|
862 | response = self.app.post(API_URL, content_type='application/json', | |
863 | params=params) |
|
863 | params=params) | |
864 |
|
864 | |||
865 | expected = 'permission `%s` does not exist' % perm |
|
865 | expected = 'permission `%s` does not exist' % perm | |
866 | self._compare_error(id_, expected, given=response.body) |
|
866 | self._compare_error(id_, expected, given=response.body) | |
867 |
|
867 | |||
868 | @mock.patch.object(RepoModel, 'grant_user_permission', crash) |
|
868 | @mock.patch.object(RepoModel, 'grant_user_permission', crash) | |
869 | def test_api_grant_user_permission_exception_when_adding(self): |
|
869 | def test_api_grant_user_permission_exception_when_adding(self): | |
870 | perm = 'repository.read' |
|
870 | perm = 'repository.read' | |
871 | id_, params = _build_data(self.apikey, 'grant_user_permission', |
|
871 | id_, params = _build_data(self.apikey, 'grant_user_permission', | |
872 | repoid=self.REPO, |
|
872 | repoid=self.REPO, | |
873 | userid=TEST_USER_ADMIN_LOGIN, |
|
873 | userid=TEST_USER_ADMIN_LOGIN, | |
874 | perm=perm) |
|
874 | perm=perm) | |
875 | response = self.app.post(API_URL, content_type='application/json', |
|
875 | response = self.app.post(API_URL, content_type='application/json', | |
876 | params=params) |
|
876 | params=params) | |
877 |
|
877 | |||
878 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
|
878 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( | |
879 | TEST_USER_ADMIN_LOGIN, self.REPO |
|
879 | TEST_USER_ADMIN_LOGIN, self.REPO | |
880 | ) |
|
880 | ) | |
881 | self._compare_error(id_, expected, given=response.body) |
|
881 | self._compare_error(id_, expected, given=response.body) | |
882 |
|
882 | |||
883 | def test_api_revoke_user_permission(self): |
|
883 | def test_api_revoke_user_permission(self): | |
884 | id_, params = _build_data(self.apikey, 'revoke_user_permission', |
|
884 | id_, params = _build_data(self.apikey, 'revoke_user_permission', | |
885 | repoid=self.REPO, |
|
885 | repoid=self.REPO, | |
886 | userid=TEST_USER_ADMIN_LOGIN,) |
|
886 | userid=TEST_USER_ADMIN_LOGIN,) | |
887 | response = self.app.post(API_URL, content_type='application/json', |
|
887 | response = self.app.post(API_URL, content_type='application/json', | |
888 | params=params) |
|
888 | params=params) | |
889 |
|
889 | |||
890 | expected = { |
|
890 | expected = { | |
891 | 'msg': 'Revoked perm for user: `%s` in repo: `%s`' % ( |
|
891 | 'msg': 'Revoked perm for user: `%s` in repo: `%s`' % ( | |
892 | TEST_USER_ADMIN_LOGIN, self.REPO |
|
892 | TEST_USER_ADMIN_LOGIN, self.REPO | |
893 | ), |
|
893 | ), | |
894 | 'success': True |
|
894 | 'success': True | |
895 | } |
|
895 | } | |
896 | self._compare_ok(id_, expected, given=response.body) |
|
896 | self._compare_ok(id_, expected, given=response.body) | |
897 |
|
897 | |||
898 | @mock.patch.object(RepoModel, 'revoke_user_permission', crash) |
|
898 | @mock.patch.object(RepoModel, 'revoke_user_permission', crash) | |
899 | def test_api_revoke_user_permission_exception_when_adding(self): |
|
899 | def test_api_revoke_user_permission_exception_when_adding(self): | |
900 | id_, params = _build_data(self.apikey, 'revoke_user_permission', |
|
900 | id_, params = _build_data(self.apikey, 'revoke_user_permission', | |
901 | repoid=self.REPO, |
|
901 | repoid=self.REPO, | |
902 | userid=TEST_USER_ADMIN_LOGIN,) |
|
902 | userid=TEST_USER_ADMIN_LOGIN,) | |
903 | response = self.app.post(API_URL, content_type='application/json', |
|
903 | response = self.app.post(API_URL, content_type='application/json', | |
904 | params=params) |
|
904 | params=params) | |
905 |
|
905 | |||
906 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( |
|
906 | expected = 'failed to edit permission for user: `%s` in repo: `%s`' % ( | |
907 | TEST_USER_ADMIN_LOGIN, self.REPO |
|
907 | TEST_USER_ADMIN_LOGIN, self.REPO | |
908 | ) |
|
908 | ) | |
909 | self._compare_error(id_, expected, given=response.body) |
|
909 | self._compare_error(id_, expected, given=response.body) | |
910 |
|
910 | |||
911 | @parameterized.expand([('none', 'repository.none'), |
|
911 | @parameterized.expand([('none', 'repository.none'), | |
912 | ('read', 'repository.read'), |
|
912 | ('read', 'repository.read'), | |
913 | ('write', 'repository.write'), |
|
913 | ('write', 'repository.write'), | |
914 | ('admin', 'repository.admin')]) |
|
914 | ('admin', 'repository.admin')]) | |
915 | def test_api_grant_users_group_permission(self, name, perm): |
|
915 | def test_api_grant_users_group_permission(self, name, perm): | |
916 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
916 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', | |
917 | repoid=self.REPO, |
|
917 | repoid=self.REPO, | |
918 | usersgroupid=TEST_USERS_GROUP, |
|
918 | usersgroupid=TEST_USERS_GROUP, | |
919 | perm=perm) |
|
919 | perm=perm) | |
920 | response = self.app.post(API_URL, content_type='application/json', |
|
920 | response = self.app.post(API_URL, content_type='application/json', | |
921 | params=params) |
|
921 | params=params) | |
922 |
|
922 | |||
923 | ret = { |
|
923 | ret = { | |
924 | 'msg': 'Granted perm: `%s` for users group: `%s` in repo: `%s`' % ( |
|
924 | 'msg': 'Granted perm: `%s` for users group: `%s` in repo: `%s`' % ( | |
925 | perm, TEST_USERS_GROUP, self.REPO |
|
925 | perm, TEST_USERS_GROUP, self.REPO | |
926 | ), |
|
926 | ), | |
927 | 'success': True |
|
927 | 'success': True | |
928 | } |
|
928 | } | |
929 | expected = ret |
|
929 | expected = ret | |
930 | self._compare_ok(id_, expected, given=response.body) |
|
930 | self._compare_ok(id_, expected, given=response.body) | |
931 |
|
931 | |||
932 | def test_api_grant_users_group_permission_wrong_permission(self): |
|
932 | def test_api_grant_users_group_permission_wrong_permission(self): | |
933 | perm = 'haha.no.permission' |
|
933 | perm = 'haha.no.permission' | |
934 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
934 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', | |
935 | repoid=self.REPO, |
|
935 | repoid=self.REPO, | |
936 | usersgroupid=TEST_USERS_GROUP, |
|
936 | usersgroupid=TEST_USERS_GROUP, | |
937 | perm=perm) |
|
937 | perm=perm) | |
938 | response = self.app.post(API_URL, content_type='application/json', |
|
938 | response = self.app.post(API_URL, content_type='application/json', | |
939 | params=params) |
|
939 | params=params) | |
940 |
|
940 | |||
941 | expected = 'permission `%s` does not exist' % perm |
|
941 | expected = 'permission `%s` does not exist' % perm | |
942 | self._compare_error(id_, expected, given=response.body) |
|
942 | self._compare_error(id_, expected, given=response.body) | |
943 |
|
943 | |||
944 | @mock.patch.object(RepoModel, 'grant_users_group_permission', crash) |
|
944 | @mock.patch.object(RepoModel, 'grant_users_group_permission', crash) | |
945 | def test_api_grant_users_group_permission_exception_when_adding(self): |
|
945 | def test_api_grant_users_group_permission_exception_when_adding(self): | |
946 | perm = 'repository.read' |
|
946 | perm = 'repository.read' | |
947 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', |
|
947 | id_, params = _build_data(self.apikey, 'grant_users_group_permission', | |
948 | repoid=self.REPO, |
|
948 | repoid=self.REPO, | |
949 | usersgroupid=TEST_USERS_GROUP, |
|
949 | usersgroupid=TEST_USERS_GROUP, | |
950 | perm=perm) |
|
950 | perm=perm) | |
951 | response = self.app.post(API_URL, content_type='application/json', |
|
951 | response = self.app.post(API_URL, content_type='application/json', | |
952 | params=params) |
|
952 | params=params) | |
953 |
|
953 | |||
954 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( |
|
954 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( | |
955 | TEST_USERS_GROUP, self.REPO |
|
955 | TEST_USERS_GROUP, self.REPO | |
956 | ) |
|
956 | ) | |
957 | self._compare_error(id_, expected, given=response.body) |
|
957 | self._compare_error(id_, expected, given=response.body) | |
958 |
|
958 | |||
959 | def test_api_revoke_users_group_permission(self): |
|
959 | def test_api_revoke_users_group_permission(self): | |
960 | RepoModel().grant_users_group_permission(repo=self.REPO, |
|
960 | RepoModel().grant_users_group_permission(repo=self.REPO, | |
961 | group_name=TEST_USERS_GROUP, |
|
961 | group_name=TEST_USERS_GROUP, | |
962 | perm='repository.read') |
|
962 | perm='repository.read') | |
963 | self.Session().commit() |
|
963 | self.Session().commit() | |
964 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', |
|
964 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', | |
965 | repoid=self.REPO, |
|
965 | repoid=self.REPO, | |
966 | usersgroupid=TEST_USERS_GROUP,) |
|
966 | usersgroupid=TEST_USERS_GROUP,) | |
967 | response = self.app.post(API_URL, content_type='application/json', |
|
967 | response = self.app.post(API_URL, content_type='application/json', | |
968 | params=params) |
|
968 | params=params) | |
969 |
|
969 | |||
970 | expected = { |
|
970 | expected = { | |
971 | 'msg': 'Revoked perm for users group: `%s` in repo: `%s`' % ( |
|
971 | 'msg': 'Revoked perm for users group: `%s` in repo: `%s`' % ( | |
972 | TEST_USERS_GROUP, self.REPO |
|
972 | TEST_USERS_GROUP, self.REPO | |
973 | ), |
|
973 | ), | |
974 | 'success': True |
|
974 | 'success': True | |
975 | } |
|
975 | } | |
976 | self._compare_ok(id_, expected, given=response.body) |
|
976 | self._compare_ok(id_, expected, given=response.body) | |
977 |
|
977 | |||
978 | @mock.patch.object(RepoModel, 'revoke_users_group_permission', crash) |
|
978 | @mock.patch.object(RepoModel, 'revoke_users_group_permission', crash) | |
979 | def test_api_revoke_users_group_permission_exception_when_adding(self): |
|
979 | def test_api_revoke_users_group_permission_exception_when_adding(self): | |
980 |
|
980 | |||
981 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', |
|
981 | id_, params = _build_data(self.apikey, 'revoke_users_group_permission', | |
982 | repoid=self.REPO, |
|
982 | repoid=self.REPO, | |
983 | usersgroupid=TEST_USERS_GROUP,) |
|
983 | usersgroupid=TEST_USERS_GROUP,) | |
984 | response = self.app.post(API_URL, content_type='application/json', |
|
984 | response = self.app.post(API_URL, content_type='application/json', | |
985 | params=params) |
|
985 | params=params) | |
986 |
|
986 | |||
987 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( |
|
987 | expected = 'failed to edit permission for users group: `%s` in repo: `%s`' % ( | |
988 | TEST_USERS_GROUP, self.REPO |
|
988 | TEST_USERS_GROUP, self.REPO | |
989 | ) |
|
989 | ) | |
990 | self._compare_error(id_, expected, given=response.body) |
|
990 | self._compare_error(id_, expected, given=response.body) | |
991 |
|
@@ -1,7 +1,7 b'' | |||||
1 | from rhodecode.tests import * |
|
1 | from rhodecode.tests import * | |
2 | from rhodecode.tests.api.api_base import BaseTestApi |
|
2 | from rhodecode.tests.api.api_base import BaseTestApi | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | class TestHgApi(BaseTestApi, TestController): |
|
5 | class TestHgApi(BaseTestApi, TestController): | |
6 | REPO = HG_REPO |
|
6 | REPO = HG_REPO | |
7 | REPO_TYPE = 'hg' No newline at end of file |
|
7 | REPO_TYPE = 'hg' |
@@ -1,266 +1,266 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | from rhodecode.lib.auth import get_crypt_password, check_password |
|
3 | from rhodecode.lib.auth import get_crypt_password, check_password | |
4 | from rhodecode.model.db import User, RhodeCodeSetting, Repository |
|
4 | from rhodecode.model.db import User, RhodeCodeSetting, Repository | |
5 | from rhodecode.tests import * |
|
5 | from rhodecode.tests import * | |
6 | from rhodecode.lib import helpers as h |
|
6 | from rhodecode.lib import helpers as h | |
7 | from rhodecode.model.user import UserModel |
|
7 | from rhodecode.model.user import UserModel | |
8 | from rhodecode.model.scm import ScmModel |
|
8 | from rhodecode.model.scm import ScmModel | |
9 |
|
9 | |||
10 |
|
10 | |||
11 | class TestAdminSettingsController(TestController): |
|
11 | class TestAdminSettingsController(TestController): | |
12 |
|
12 | |||
13 | def test_index(self): |
|
13 | def test_index(self): | |
14 | response = self.app.get(url('admin_settings')) |
|
14 | response = self.app.get(url('admin_settings')) | |
15 | # Test response... |
|
15 | # Test response... | |
16 |
|
16 | |||
17 | def test_index_as_xml(self): |
|
17 | def test_index_as_xml(self): | |
18 | response = self.app.get(url('formatted_admin_settings', format='xml')) |
|
18 | response = self.app.get(url('formatted_admin_settings', format='xml')) | |
19 |
|
19 | |||
20 | def test_create(self): |
|
20 | def test_create(self): | |
21 | response = self.app.post(url('admin_settings')) |
|
21 | response = self.app.post(url('admin_settings')) | |
22 |
|
22 | |||
23 | def test_new(self): |
|
23 | def test_new(self): | |
24 | response = self.app.get(url('admin_new_setting')) |
|
24 | response = self.app.get(url('admin_new_setting')) | |
25 |
|
25 | |||
26 | def test_new_as_xml(self): |
|
26 | def test_new_as_xml(self): | |
27 | response = self.app.get(url('formatted_admin_new_setting', format='xml')) |
|
27 | response = self.app.get(url('formatted_admin_new_setting', format='xml')) | |
28 |
|
28 | |||
29 | def test_update(self): |
|
29 | def test_update(self): | |
30 | response = self.app.put(url('admin_setting', setting_id=1)) |
|
30 | response = self.app.put(url('admin_setting', setting_id=1)) | |
31 |
|
31 | |||
32 | def test_update_browser_fakeout(self): |
|
32 | def test_update_browser_fakeout(self): | |
33 | response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='put')) |
|
33 | response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='put')) | |
34 |
|
34 | |||
35 | def test_delete(self): |
|
35 | def test_delete(self): | |
36 | response = self.app.delete(url('admin_setting', setting_id=1)) |
|
36 | response = self.app.delete(url('admin_setting', setting_id=1)) | |
37 |
|
37 | |||
38 | def test_delete_browser_fakeout(self): |
|
38 | def test_delete_browser_fakeout(self): | |
39 | response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='delete')) |
|
39 | response = self.app.post(url('admin_setting', setting_id=1), params=dict(_method='delete')) | |
40 |
|
40 | |||
41 | def test_show(self): |
|
41 | def test_show(self): | |
42 | response = self.app.get(url('admin_setting', setting_id=1)) |
|
42 | response = self.app.get(url('admin_setting', setting_id=1)) | |
43 |
|
43 | |||
44 | def test_show_as_xml(self): |
|
44 | def test_show_as_xml(self): | |
45 | response = self.app.get(url('formatted_admin_setting', setting_id=1, format='xml')) |
|
45 | response = self.app.get(url('formatted_admin_setting', setting_id=1, format='xml')) | |
46 |
|
46 | |||
47 | def test_edit(self): |
|
47 | def test_edit(self): | |
48 | response = self.app.get(url('admin_edit_setting', setting_id=1)) |
|
48 | response = self.app.get(url('admin_edit_setting', setting_id=1)) | |
49 |
|
49 | |||
50 | def test_edit_as_xml(self): |
|
50 | def test_edit_as_xml(self): | |
51 | response = self.app.get(url('formatted_admin_edit_setting', |
|
51 | response = self.app.get(url('formatted_admin_edit_setting', | |
52 | setting_id=1, format='xml')) |
|
52 | setting_id=1, format='xml')) | |
53 |
|
53 | |||
54 | def test_ga_code_active(self): |
|
54 | def test_ga_code_active(self): | |
55 | self.log_user() |
|
55 | self.log_user() | |
56 | old_title = 'RhodeCode' |
|
56 | old_title = 'RhodeCode' | |
57 | old_realm = 'RhodeCode authentication' |
|
57 | old_realm = 'RhodeCode authentication' | |
58 | new_ga_code = 'ga-test-123456789' |
|
58 | new_ga_code = 'ga-test-123456789' | |
59 | response = self.app.post(url('admin_setting', setting_id='global'), |
|
59 | response = self.app.post(url('admin_setting', setting_id='global'), | |
60 | params=dict( |
|
60 | params=dict( | |
61 | _method='put', |
|
61 | _method='put', | |
62 | rhodecode_title=old_title, |
|
62 | rhodecode_title=old_title, | |
63 | rhodecode_realm=old_realm, |
|
63 | rhodecode_realm=old_realm, | |
64 | rhodecode_ga_code=new_ga_code |
|
64 | rhodecode_ga_code=new_ga_code | |
65 | )) |
|
65 | )) | |
66 |
|
66 | |||
67 | self.checkSessionFlash(response, 'Updated application settings') |
|
67 | self.checkSessionFlash(response, 'Updated application settings') | |
68 |
|
68 | |||
69 | self.assertEqual(RhodeCodeSetting |
|
69 | self.assertEqual(RhodeCodeSetting | |
70 | .get_app_settings()['rhodecode_ga_code'], new_ga_code) |
|
70 | .get_app_settings()['rhodecode_ga_code'], new_ga_code) | |
71 |
|
71 | |||
72 | response = response.follow() |
|
72 | response = response.follow() | |
73 | response.mustcontain("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code) |
|
73 | response.mustcontain("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code) | |
74 |
|
74 | |||
75 | def test_ga_code_inactive(self): |
|
75 | def test_ga_code_inactive(self): | |
76 | self.log_user() |
|
76 | self.log_user() | |
77 | old_title = 'RhodeCode' |
|
77 | old_title = 'RhodeCode' | |
78 | old_realm = 'RhodeCode authentication' |
|
78 | old_realm = 'RhodeCode authentication' | |
79 | new_ga_code = '' |
|
79 | new_ga_code = '' | |
80 | response = self.app.post(url('admin_setting', setting_id='global'), |
|
80 | response = self.app.post(url('admin_setting', setting_id='global'), | |
81 | params=dict( |
|
81 | params=dict( | |
82 | _method='put', |
|
82 | _method='put', | |
83 | rhodecode_title=old_title, |
|
83 | rhodecode_title=old_title, | |
84 | rhodecode_realm=old_realm, |
|
84 | rhodecode_realm=old_realm, | |
85 | rhodecode_ga_code=new_ga_code |
|
85 | rhodecode_ga_code=new_ga_code | |
86 | )) |
|
86 | )) | |
87 |
|
87 | |||
88 | self.assertTrue('Updated application settings' in |
|
88 | self.assertTrue('Updated application settings' in | |
89 | response.session['flash'][0][1]) |
|
89 | response.session['flash'][0][1]) | |
90 | self.assertEqual(RhodeCodeSetting |
|
90 | self.assertEqual(RhodeCodeSetting | |
91 | .get_app_settings()['rhodecode_ga_code'], new_ga_code) |
|
91 | .get_app_settings()['rhodecode_ga_code'], new_ga_code) | |
92 |
|
92 | |||
93 | response = response.follow() |
|
93 | response = response.follow() | |
94 | self.assertFalse("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code |
|
94 | self.assertFalse("""_gaq.push(['_setAccount', '%s']);""" % new_ga_code | |
95 | in response.body) |
|
95 | in response.body) | |
96 |
|
96 | |||
97 | def test_title_change(self): |
|
97 | def test_title_change(self): | |
98 | self.log_user() |
|
98 | self.log_user() | |
99 | old_title = 'RhodeCode' |
|
99 | old_title = 'RhodeCode' | |
100 | new_title = old_title + '_changed' |
|
100 | new_title = old_title + '_changed' | |
101 | old_realm = 'RhodeCode authentication' |
|
101 | old_realm = 'RhodeCode authentication' | |
102 |
|
102 | |||
103 | for new_title in ['Changed', 'Ε»Γ³Εwik', old_title]: |
|
103 | for new_title in ['Changed', 'Ε»Γ³Εwik', old_title]: | |
104 | response = self.app.post(url('admin_setting', setting_id='global'), |
|
104 | response = self.app.post(url('admin_setting', setting_id='global'), | |
105 | params=dict( |
|
105 | params=dict( | |
106 | _method='put', |
|
106 | _method='put', | |
107 | rhodecode_title=new_title, |
|
107 | rhodecode_title=new_title, | |
108 | rhodecode_realm=old_realm, |
|
108 | rhodecode_realm=old_realm, | |
109 | rhodecode_ga_code='' |
|
109 | rhodecode_ga_code='' | |
110 | )) |
|
110 | )) | |
111 |
|
111 | |||
112 | self.checkSessionFlash(response, 'Updated application settings') |
|
112 | self.checkSessionFlash(response, 'Updated application settings') | |
113 | self.assertEqual(RhodeCodeSetting |
|
113 | self.assertEqual(RhodeCodeSetting | |
114 | .get_app_settings()['rhodecode_title'], |
|
114 | .get_app_settings()['rhodecode_title'], | |
115 | new_title.decode('utf-8')) |
|
115 | new_title.decode('utf-8')) | |
116 |
|
116 | |||
117 | response = response.follow() |
|
117 | response = response.follow() | |
118 | response.mustcontain("""<h1><a href="/">%s</a></h1>""" % new_title) |
|
118 | response.mustcontain("""<h1><a href="/">%s</a></h1>""" % new_title) | |
119 |
|
119 | |||
120 | def test_my_account(self): |
|
120 | def test_my_account(self): | |
121 | self.log_user() |
|
121 | self.log_user() | |
122 | response = self.app.get(url('admin_settings_my_account')) |
|
122 | response = self.app.get(url('admin_settings_my_account')) | |
123 |
|
123 | |||
124 | self.assertTrue('value="test_admin' in response.body) |
|
124 | self.assertTrue('value="test_admin' in response.body) | |
125 |
|
125 | |||
126 | @parameterized.expand([('firstname', 'new_username'), |
|
126 | @parameterized.expand([('firstname', 'new_username'), | |
127 | ('lastname', 'new_username'), |
|
127 | ('lastname', 'new_username'), | |
128 | ('admin', True), |
|
128 | ('admin', True), | |
129 | ('admin', False), |
|
129 | ('admin', False), | |
130 | ('ldap_dn', 'test'), |
|
130 | ('ldap_dn', 'test'), | |
131 | ('ldap_dn', None), |
|
131 | ('ldap_dn', None), | |
132 | ('active', False), |
|
132 | ('active', False), | |
133 | ('active', True), |
|
133 | ('active', True), | |
134 | ('email', 'some@email.com'), |
|
134 | ('email', 'some@email.com'), | |
135 | ]) |
|
135 | ]) | |
136 | def test_my_account_update(self, name, expected): |
|
136 | def test_my_account_update(self, name, expected): | |
137 | uname = 'testme' |
|
137 | uname = 'testme' | |
138 | usr = UserModel().create_or_update(username=uname, password='qweqwe', |
|
138 | usr = UserModel().create_or_update(username=uname, password='qweqwe', | |
139 | email='testme@rhodecod.org') |
|
139 | email='testme@rhodecod.org') | |
140 | self.Session().commit() |
|
140 | self.Session().commit() | |
141 | params = usr.get_api_data() |
|
141 | params = usr.get_api_data() | |
142 | user_id = usr.user_id |
|
142 | user_id = usr.user_id | |
143 | self.log_user(username=uname, password='qweqwe') |
|
143 | self.log_user(username=uname, password='qweqwe') | |
144 | params.update({name: expected}) |
|
144 | params.update({name: expected}) | |
145 | params.update({'password_confirmation': ''}) |
|
145 | params.update({'password_confirmation': ''}) | |
146 | params.update({'new_password': ''}) |
|
146 | params.update({'new_password': ''}) | |
147 |
|
147 | |||
148 | try: |
|
148 | try: | |
149 | response = self.app.put(url('admin_settings_my_account_update', |
|
149 | response = self.app.put(url('admin_settings_my_account_update', | |
150 | id=user_id), params) |
|
150 | id=user_id), params) | |
151 |
|
151 | |||
152 | self.checkSessionFlash(response, |
|
152 | self.checkSessionFlash(response, | |
153 | 'Your account was updated successfully') |
|
153 | 'Your account was updated successfully') | |
154 |
|
154 | |||
155 | updated_user = User.get_by_username(uname) |
|
155 | updated_user = User.get_by_username(uname) | |
156 | updated_params = updated_user.get_api_data() |
|
156 | updated_params = updated_user.get_api_data() | |
157 | updated_params.update({'password_confirmation': ''}) |
|
157 | updated_params.update({'password_confirmation': ''}) | |
158 | updated_params.update({'new_password': ''}) |
|
158 | updated_params.update({'new_password': ''}) | |
159 |
|
159 | |||
160 | params['last_login'] = updated_params['last_login'] |
|
160 | params['last_login'] = updated_params['last_login'] | |
161 | if name == 'email': |
|
161 | if name == 'email': | |
162 | params['emails'] = [expected] |
|
162 | params['emails'] = [expected] | |
163 | if name == 'ldap_dn': |
|
163 | if name == 'ldap_dn': | |
164 | #cannot update this via form |
|
164 | #cannot update this via form | |
165 | params['ldap_dn'] = None |
|
165 | params['ldap_dn'] = None | |
166 | if name == 'active': |
|
166 | if name == 'active': | |
167 | #my account cannot deactivate account |
|
167 | #my account cannot deactivate account | |
168 | params['active'] = True |
|
168 | params['active'] = True | |
169 | if name == 'admin': |
|
169 | if name == 'admin': | |
170 | #my account cannot make you an admin ! |
|
170 | #my account cannot make you an admin ! | |
171 | params['admin'] = False |
|
171 | params['admin'] = False | |
172 |
|
172 | |||
173 | self.assertEqual(params, updated_params) |
|
173 | self.assertEqual(params, updated_params) | |
174 |
|
174 | |||
175 | finally: |
|
175 | finally: | |
176 | UserModel().delete('testme') |
|
176 | UserModel().delete('testme') | |
177 |
|
177 | |||
178 | def test_my_account_update_err_email_exists(self): |
|
178 | def test_my_account_update_err_email_exists(self): | |
179 | self.log_user() |
|
179 | self.log_user() | |
180 |
|
180 | |||
181 | new_email = 'test_regular@mail.com' # already exisitn email |
|
181 | new_email = 'test_regular@mail.com' # already exisitn email | |
182 | response = self.app.put(url('admin_settings_my_account_update'), |
|
182 | response = self.app.put(url('admin_settings_my_account_update'), | |
183 | params=dict( |
|
183 | params=dict( | |
184 | username='test_admin', |
|
184 | username='test_admin', | |
185 | new_password='test12', |
|
185 | new_password='test12', | |
186 | password_confirmation='test122', |
|
186 | password_confirmation='test122', | |
187 | firstname='NewName', |
|
187 | firstname='NewName', | |
188 | lastname='NewLastname', |
|
188 | lastname='NewLastname', | |
189 | email=new_email,) |
|
189 | email=new_email,) | |
190 | ) |
|
190 | ) | |
191 |
|
191 | |||
192 | response.mustcontain('This e-mail address is already taken') |
|
192 | response.mustcontain('This e-mail address is already taken') | |
193 |
|
193 | |||
194 | def test_my_account_update_err(self): |
|
194 | def test_my_account_update_err(self): | |
195 | self.log_user('test_regular2', 'test12') |
|
195 | self.log_user('test_regular2', 'test12') | |
196 |
|
196 | |||
197 | new_email = 'newmail.pl' |
|
197 | new_email = 'newmail.pl' | |
198 | response = self.app.post(url('admin_settings_my_account_update'), |
|
198 | response = self.app.post(url('admin_settings_my_account_update'), | |
199 | params=dict( |
|
199 | params=dict( | |
200 | _method='put', |
|
200 | _method='put', | |
201 | username='test_admin', |
|
201 | username='test_admin', | |
202 | new_password='test12', |
|
202 | new_password='test12', | |
203 | password_confirmation='test122', |
|
203 | password_confirmation='test122', | |
204 | firstname='NewName', |
|
204 | firstname='NewName', | |
205 | lastname='NewLastname', |
|
205 | lastname='NewLastname', | |
206 | email=new_email,) |
|
206 | email=new_email,) | |
207 | ) |
|
207 | ) | |
208 |
|
208 | |||
209 | response.mustcontain('An email address must contain a single @') |
|
209 | response.mustcontain('An email address must contain a single @') | |
210 | from rhodecode.model import validators |
|
210 | from rhodecode.model import validators | |
211 | msg = validators.ValidUsername(edit=False, |
|
211 | msg = validators.ValidUsername(edit=False, | |
212 | old_data={})._messages['username_exists'] |
|
212 | old_data={})._messages['username_exists'] | |
213 | msg = h.html_escape(msg % {'username': 'test_admin'}) |
|
213 | msg = h.html_escape(msg % {'username': 'test_admin'}) | |
214 | response.mustcontain(u"%s" % msg) |
|
214 | response.mustcontain(u"%s" % msg) | |
215 |
|
215 | |||
216 | def test_set_repo_fork_has_no_self_id(self): |
|
216 | def test_set_repo_fork_has_no_self_id(self): | |
217 | self.log_user() |
|
217 | self.log_user() | |
218 | repo = Repository.get_by_repo_name(HG_REPO) |
|
218 | repo = Repository.get_by_repo_name(HG_REPO) | |
219 | response = self.app.get(url('edit_repo', repo_name=HG_REPO)) |
|
219 | response = self.app.get(url('edit_repo', repo_name=HG_REPO)) | |
220 | opt = """<option value="%s">vcs_test_git</option>""" % repo.repo_id |
|
220 | opt = """<option value="%s">vcs_test_git</option>""" % repo.repo_id | |
221 | assert opt not in response.body |
|
221 | assert opt not in response.body | |
222 |
|
222 | |||
223 | def test_set_fork_of_repo(self): |
|
223 | def test_set_fork_of_repo(self): | |
224 | self.log_user() |
|
224 | self.log_user() | |
225 | repo = Repository.get_by_repo_name(HG_REPO) |
|
225 | repo = Repository.get_by_repo_name(HG_REPO) | |
226 | repo2 = Repository.get_by_repo_name(GIT_REPO) |
|
226 | repo2 = Repository.get_by_repo_name(GIT_REPO) | |
227 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), |
|
227 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), | |
228 | params=dict( |
|
228 | params=dict( | |
229 | id_fork_of=repo2.repo_id |
|
229 | id_fork_of=repo2.repo_id | |
230 | )) |
|
230 | )) | |
231 | repo = Repository.get_by_repo_name(HG_REPO) |
|
231 | repo = Repository.get_by_repo_name(HG_REPO) | |
232 | repo2 = Repository.get_by_repo_name(GIT_REPO) |
|
232 | repo2 = Repository.get_by_repo_name(GIT_REPO) | |
233 | self.checkSessionFlash(response, |
|
233 | self.checkSessionFlash(response, | |
234 | 'Marked repo %s as fork of %s' % (repo.repo_name, repo2.repo_name)) |
|
234 | 'Marked repo %s as fork of %s' % (repo.repo_name, repo2.repo_name)) | |
235 |
|
235 | |||
236 | assert repo.fork == repo2 |
|
236 | assert repo.fork == repo2 | |
237 | response = response.follow() |
|
237 | response = response.follow() | |
238 | # check if given repo is selected |
|
238 | # check if given repo is selected | |
239 |
|
239 | |||
240 | opt = """<option value="%s" selected="selected">%s</option>""" % ( |
|
240 | opt = """<option value="%s" selected="selected">%s</option>""" % ( | |
241 | repo2.repo_id, repo2.repo_name) |
|
241 | repo2.repo_id, repo2.repo_name) | |
242 | response.mustcontain(opt) |
|
242 | response.mustcontain(opt) | |
243 |
|
243 | |||
244 | # clean session flash |
|
244 | # clean session flash | |
245 | #response = self.app.get(url('edit_repo', repo_name=HG_REPO)) |
|
245 | #response = self.app.get(url('edit_repo', repo_name=HG_REPO)) | |
246 |
|
246 | |||
247 | ## mark it as None |
|
247 | ## mark it as None | |
248 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), |
|
248 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), | |
249 | params=dict( |
|
249 | params=dict( | |
250 | id_fork_of=None |
|
250 | id_fork_of=None | |
251 | )) |
|
251 | )) | |
252 | repo = Repository.get_by_repo_name(HG_REPO) |
|
252 | repo = Repository.get_by_repo_name(HG_REPO) | |
253 | repo2 = Repository.get_by_repo_name(GIT_REPO) |
|
253 | repo2 = Repository.get_by_repo_name(GIT_REPO) | |
254 | self.checkSessionFlash(response, |
|
254 | self.checkSessionFlash(response, | |
255 | 'Marked repo %s as fork of %s' % (repo.repo_name, "Nothing")) |
|
255 | 'Marked repo %s as fork of %s' % (repo.repo_name, "Nothing")) | |
256 | assert repo.fork == None |
|
256 | assert repo.fork == None | |
257 |
|
257 | |||
258 | def test_set_fork_of_same_repo(self): |
|
258 | def test_set_fork_of_same_repo(self): | |
259 | self.log_user() |
|
259 | self.log_user() | |
260 | repo = Repository.get_by_repo_name(HG_REPO) |
|
260 | repo = Repository.get_by_repo_name(HG_REPO) | |
261 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), |
|
261 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), | |
262 | params=dict( |
|
262 | params=dict( | |
263 | id_fork_of=repo.repo_id |
|
263 | id_fork_of=repo.repo_id | |
264 | )) |
|
264 | )) | |
265 | self.checkSessionFlash(response, |
|
265 | self.checkSessionFlash(response, | |
266 | 'An error occurred during this operation') No newline at end of file |
|
266 | 'An error occurred during this operation') |
@@ -1,191 +1,187 b'' | |||||
1 | import os |
|
1 | import os | |
2 | import unittest |
|
2 | import unittest | |
3 | from rhodecode.tests import * |
|
3 | from rhodecode.tests import * | |
4 |
|
4 | |||
5 | from rhodecode.model.db import User, Notification, UserNotification |
|
5 | from rhodecode.model.db import User, Notification, UserNotification | |
6 | from rhodecode.model.user import UserModel |
|
6 | from rhodecode.model.user import UserModel | |
7 |
|
7 | |||
8 | from rhodecode.model.meta import Session |
|
8 | from rhodecode.model.meta import Session | |
9 | from rhodecode.model.notification import NotificationModel |
|
9 | from rhodecode.model.notification import NotificationModel | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | class TestNotifications(unittest.TestCase): |
|
12 | class TestNotifications(unittest.TestCase): | |
13 |
|
13 | |||
14 | def __init__(self, methodName='runTest'): |
|
14 | def __init__(self, methodName='runTest'): | |
15 | Session.remove() |
|
15 | Session.remove() | |
16 | self.u1 = UserModel().create_or_update(username=u'u1', |
|
16 | self.u1 = UserModel().create_or_update(username=u'u1', | |
17 | password=u'qweqwe', |
|
17 | password=u'qweqwe', | |
18 | email=u'u1@rhodecode.org', |
|
18 | email=u'u1@rhodecode.org', | |
19 | firstname=u'u1', lastname=u'u1') |
|
19 | firstname=u'u1', lastname=u'u1') | |
20 | Session().commit() |
|
20 | Session().commit() | |
21 | self.u1 = self.u1.user_id |
|
21 | self.u1 = self.u1.user_id | |
22 |
|
22 | |||
23 | self.u2 = UserModel().create_or_update(username=u'u2', |
|
23 | self.u2 = UserModel().create_or_update(username=u'u2', | |
24 | password=u'qweqwe', |
|
24 | password=u'qweqwe', | |
25 | email=u'u2@rhodecode.org', |
|
25 | email=u'u2@rhodecode.org', | |
26 | firstname=u'u2', lastname=u'u3') |
|
26 | firstname=u'u2', lastname=u'u3') | |
27 | Session().commit() |
|
27 | Session().commit() | |
28 | self.u2 = self.u2.user_id |
|
28 | self.u2 = self.u2.user_id | |
29 |
|
29 | |||
30 | self.u3 = UserModel().create_or_update(username=u'u3', |
|
30 | self.u3 = UserModel().create_or_update(username=u'u3', | |
31 | password=u'qweqwe', |
|
31 | password=u'qweqwe', | |
32 | email=u'u3@rhodecode.org', |
|
32 | email=u'u3@rhodecode.org', | |
33 | firstname=u'u3', lastname=u'u3') |
|
33 | firstname=u'u3', lastname=u'u3') | |
34 | Session().commit() |
|
34 | Session().commit() | |
35 | self.u3 = self.u3.user_id |
|
35 | self.u3 = self.u3.user_id | |
36 |
|
36 | |||
37 | super(TestNotifications, self).__init__(methodName=methodName) |
|
37 | super(TestNotifications, self).__init__(methodName=methodName) | |
38 |
|
38 | |||
39 | def _clean_notifications(self): |
|
39 | def _clean_notifications(self): | |
40 | for n in Notification.query().all(): |
|
40 | for n in Notification.query().all(): | |
41 | Session().delete(n) |
|
41 | Session().delete(n) | |
42 |
|
42 | |||
43 | Session().commit() |
|
43 | Session().commit() | |
44 | self.assertEqual(Notification.query().all(), []) |
|
44 | self.assertEqual(Notification.query().all(), []) | |
45 |
|
45 | |||
46 | def tearDown(self): |
|
46 | def tearDown(self): | |
47 | self._clean_notifications() |
|
47 | self._clean_notifications() | |
48 |
|
48 | |||
49 | def test_create_notification(self): |
|
49 | def test_create_notification(self): | |
50 | self.assertEqual([], Notification.query().all()) |
|
50 | self.assertEqual([], Notification.query().all()) | |
51 | self.assertEqual([], UserNotification.query().all()) |
|
51 | self.assertEqual([], UserNotification.query().all()) | |
52 |
|
52 | |||
53 | usrs = [self.u1, self.u2] |
|
53 | usrs = [self.u1, self.u2] | |
54 | notification = NotificationModel().create(created_by=self.u1, |
|
54 | notification = NotificationModel().create(created_by=self.u1, | |
55 | subject=u'subj', body=u'hi there', |
|
55 | subject=u'subj', body=u'hi there', | |
56 | recipients=usrs) |
|
56 | recipients=usrs) | |
57 | Session().commit() |
|
57 | Session().commit() | |
58 | u1 = User.get(self.u1) |
|
58 | u1 = User.get(self.u1) | |
59 | u2 = User.get(self.u2) |
|
59 | u2 = User.get(self.u2) | |
60 | u3 = User.get(self.u3) |
|
60 | u3 = User.get(self.u3) | |
61 | notifications = Notification.query().all() |
|
61 | notifications = Notification.query().all() | |
62 | self.assertEqual(len(notifications), 1) |
|
62 | self.assertEqual(len(notifications), 1) | |
63 |
|
63 | |||
64 | self.assertEqual(notifications[0].recipients, [u1, u2]) |
|
64 | self.assertEqual(notifications[0].recipients, [u1, u2]) | |
65 | self.assertEqual(notification.notification_id, |
|
65 | self.assertEqual(notification.notification_id, | |
66 | notifications[0].notification_id) |
|
66 | notifications[0].notification_id) | |
67 |
|
67 | |||
68 | unotification = UserNotification.query()\ |
|
68 | unotification = UserNotification.query()\ | |
69 | .filter(UserNotification.notification == notification).all() |
|
69 | .filter(UserNotification.notification == notification).all() | |
70 |
|
70 | |||
71 | self.assertEqual(len(unotification), len(usrs)) |
|
71 | self.assertEqual(len(unotification), len(usrs)) | |
72 | self.assertEqual(set([x.user.user_id for x in unotification]), |
|
72 | self.assertEqual(set([x.user.user_id for x in unotification]), | |
73 | set(usrs)) |
|
73 | set(usrs)) | |
74 |
|
74 | |||
75 | def test_user_notifications(self): |
|
75 | def test_user_notifications(self): | |
76 | self.assertEqual([], Notification.query().all()) |
|
76 | self.assertEqual([], Notification.query().all()) | |
77 | self.assertEqual([], UserNotification.query().all()) |
|
77 | self.assertEqual([], UserNotification.query().all()) | |
78 |
|
78 | |||
79 | notification1 = NotificationModel().create(created_by=self.u1, |
|
79 | notification1 = NotificationModel().create(created_by=self.u1, | |
80 | subject=u'subj', body=u'hi there1', |
|
80 | subject=u'subj', body=u'hi there1', | |
81 | recipients=[self.u3]) |
|
81 | recipients=[self.u3]) | |
82 | Session().commit() |
|
82 | Session().commit() | |
83 | notification2 = NotificationModel().create(created_by=self.u1, |
|
83 | notification2 = NotificationModel().create(created_by=self.u1, | |
84 | subject=u'subj', body=u'hi there2', |
|
84 | subject=u'subj', body=u'hi there2', | |
85 | recipients=[self.u3]) |
|
85 | recipients=[self.u3]) | |
86 | Session().commit() |
|
86 | Session().commit() | |
87 | u3 = Session().query(User).get(self.u3) |
|
87 | u3 = Session().query(User).get(self.u3) | |
88 |
|
88 | |||
89 | self.assertEqual(sorted([x.notification for x in u3.notifications]), |
|
89 | self.assertEqual(sorted([x.notification for x in u3.notifications]), | |
90 | sorted([notification2, notification1])) |
|
90 | sorted([notification2, notification1])) | |
91 |
|
91 | |||
92 | def test_delete_notifications(self): |
|
92 | def test_delete_notifications(self): | |
93 | self.assertEqual([], Notification.query().all()) |
|
93 | self.assertEqual([], Notification.query().all()) | |
94 | self.assertEqual([], UserNotification.query().all()) |
|
94 | self.assertEqual([], UserNotification.query().all()) | |
95 |
|
95 | |||
96 | notification = NotificationModel().create(created_by=self.u1, |
|
96 | notification = NotificationModel().create(created_by=self.u1, | |
97 | subject=u'title', body=u'hi there3', |
|
97 | subject=u'title', body=u'hi there3', | |
98 | recipients=[self.u3, self.u1, self.u2]) |
|
98 | recipients=[self.u3, self.u1, self.u2]) | |
99 | Session().commit() |
|
99 | Session().commit() | |
100 | notifications = Notification.query().all() |
|
100 | notifications = Notification.query().all() | |
101 | self.assertTrue(notification in notifications) |
|
101 | self.assertTrue(notification in notifications) | |
102 |
|
102 | |||
103 | Notification.delete(notification.notification_id) |
|
103 | Notification.delete(notification.notification_id) | |
104 | Session().commit() |
|
104 | Session().commit() | |
105 |
|
105 | |||
106 | notifications = Notification.query().all() |
|
106 | notifications = Notification.query().all() | |
107 | self.assertFalse(notification in notifications) |
|
107 | self.assertFalse(notification in notifications) | |
108 |
|
108 | |||
109 | un = UserNotification.query().filter(UserNotification.notification |
|
109 | un = UserNotification.query().filter(UserNotification.notification | |
110 | == notification).all() |
|
110 | == notification).all() | |
111 | self.assertEqual(un, []) |
|
111 | self.assertEqual(un, []) | |
112 |
|
112 | |||
113 | def test_delete_association(self): |
|
113 | def test_delete_association(self): | |
114 |
|
114 | |||
115 | self.assertEqual([], Notification.query().all()) |
|
115 | self.assertEqual([], Notification.query().all()) | |
116 | self.assertEqual([], UserNotification.query().all()) |
|
116 | self.assertEqual([], UserNotification.query().all()) | |
117 |
|
117 | |||
118 | notification = NotificationModel().create(created_by=self.u1, |
|
118 | notification = NotificationModel().create(created_by=self.u1, | |
119 | subject=u'title', body=u'hi there3', |
|
119 | subject=u'title', body=u'hi there3', | |
120 | recipients=[self.u3, self.u1, self.u2]) |
|
120 | recipients=[self.u3, self.u1, self.u2]) | |
121 | Session().commit() |
|
121 | Session().commit() | |
122 |
|
122 | |||
123 | unotification = UserNotification.query()\ |
|
123 | unotification = UserNotification.query()\ | |
124 | .filter(UserNotification.notification == |
|
124 | .filter(UserNotification.notification == | |
125 | notification)\ |
|
125 | notification)\ | |
126 | .filter(UserNotification.user_id == self.u3)\ |
|
126 | .filter(UserNotification.user_id == self.u3)\ | |
127 | .scalar() |
|
127 | .scalar() | |
128 |
|
128 | |||
129 | self.assertEqual(unotification.user_id, self.u3) |
|
129 | self.assertEqual(unotification.user_id, self.u3) | |
130 |
|
130 | |||
131 | NotificationModel().delete(self.u3, |
|
131 | NotificationModel().delete(self.u3, | |
132 | notification.notification_id) |
|
132 | notification.notification_id) | |
133 | Session().commit() |
|
133 | Session().commit() | |
134 |
|
134 | |||
135 | u3notification = UserNotification.query()\ |
|
135 | u3notification = UserNotification.query()\ | |
136 | .filter(UserNotification.notification == |
|
136 | .filter(UserNotification.notification == | |
137 | notification)\ |
|
137 | notification)\ | |
138 | .filter(UserNotification.user_id == self.u3)\ |
|
138 | .filter(UserNotification.user_id == self.u3)\ | |
139 | .scalar() |
|
139 | .scalar() | |
140 |
|
140 | |||
141 | self.assertEqual(u3notification, None) |
|
141 | self.assertEqual(u3notification, None) | |
142 |
|
142 | |||
143 | # notification object is still there |
|
143 | # notification object is still there | |
144 | self.assertEqual(Notification.query().all(), [notification]) |
|
144 | self.assertEqual(Notification.query().all(), [notification]) | |
145 |
|
145 | |||
146 | #u1 and u2 still have assignments |
|
146 | #u1 and u2 still have assignments | |
147 | u1notification = UserNotification.query()\ |
|
147 | u1notification = UserNotification.query()\ | |
148 | .filter(UserNotification.notification == |
|
148 | .filter(UserNotification.notification == | |
149 | notification)\ |
|
149 | notification)\ | |
150 | .filter(UserNotification.user_id == self.u1)\ |
|
150 | .filter(UserNotification.user_id == self.u1)\ | |
151 | .scalar() |
|
151 | .scalar() | |
152 | self.assertNotEqual(u1notification, None) |
|
152 | self.assertNotEqual(u1notification, None) | |
153 | u2notification = UserNotification.query()\ |
|
153 | u2notification = UserNotification.query()\ | |
154 | .filter(UserNotification.notification == |
|
154 | .filter(UserNotification.notification == | |
155 | notification)\ |
|
155 | notification)\ | |
156 | .filter(UserNotification.user_id == self.u2)\ |
|
156 | .filter(UserNotification.user_id == self.u2)\ | |
157 | .scalar() |
|
157 | .scalar() | |
158 | self.assertNotEqual(u2notification, None) |
|
158 | self.assertNotEqual(u2notification, None) | |
159 |
|
159 | |||
160 | def test_notification_counter(self): |
|
160 | def test_notification_counter(self): | |
161 | self._clean_notifications() |
|
161 | self._clean_notifications() | |
162 | self.assertEqual([], Notification.query().all()) |
|
162 | self.assertEqual([], Notification.query().all()) | |
163 | self.assertEqual([], UserNotification.query().all()) |
|
163 | self.assertEqual([], UserNotification.query().all()) | |
164 |
|
164 | |||
165 | NotificationModel().create(created_by=self.u1, |
|
165 | NotificationModel().create(created_by=self.u1, | |
166 | subject=u'title', body=u'hi there_delete', |
|
166 | subject=u'title', body=u'hi there_delete', | |
167 | recipients=[self.u3, self.u1]) |
|
167 | recipients=[self.u3, self.u1]) | |
168 | Session().commit() |
|
168 | Session().commit() | |
169 |
|
169 | |||
170 | self.assertEqual(NotificationModel() |
|
170 | self.assertEqual(NotificationModel() | |
171 | .get_unread_cnt_for_user(self.u1), 1) |
|
171 | .get_unread_cnt_for_user(self.u1), 1) | |
172 | self.assertEqual(NotificationModel() |
|
172 | self.assertEqual(NotificationModel() | |
173 | .get_unread_cnt_for_user(self.u2), 0) |
|
173 | .get_unread_cnt_for_user(self.u2), 0) | |
174 | self.assertEqual(NotificationModel() |
|
174 | self.assertEqual(NotificationModel() | |
175 | .get_unread_cnt_for_user(self.u3), 1) |
|
175 | .get_unread_cnt_for_user(self.u3), 1) | |
176 |
|
176 | |||
177 | notification = NotificationModel().create(created_by=self.u1, |
|
177 | notification = NotificationModel().create(created_by=self.u1, | |
178 | subject=u'title', body=u'hi there3', |
|
178 | subject=u'title', body=u'hi there3', | |
179 | recipients=[self.u3, self.u1, self.u2]) |
|
179 | recipients=[self.u3, self.u1, self.u2]) | |
180 | Session().commit() |
|
180 | Session().commit() | |
181 |
|
181 | |||
182 | self.assertEqual(NotificationModel() |
|
182 | self.assertEqual(NotificationModel() | |
183 | .get_unread_cnt_for_user(self.u1), 2) |
|
183 | .get_unread_cnt_for_user(self.u1), 2) | |
184 | self.assertEqual(NotificationModel() |
|
184 | self.assertEqual(NotificationModel() | |
185 | .get_unread_cnt_for_user(self.u2), 1) |
|
185 | .get_unread_cnt_for_user(self.u2), 1) | |
186 | self.assertEqual(NotificationModel() |
|
186 | self.assertEqual(NotificationModel() | |
187 | .get_unread_cnt_for_user(self.u3), 2) |
|
187 | .get_unread_cnt_for_user(self.u3), 2) | |
188 |
|
||||
189 |
|
||||
190 |
|
||||
191 |
|
@@ -1,170 +1,170 b'' | |||||
1 | import os |
|
1 | import os | |
2 | import unittest |
|
2 | import unittest | |
3 | from rhodecode.tests import * |
|
3 | from rhodecode.tests import * | |
4 |
|
4 | |||
5 | from rhodecode.model.repos_group import ReposGroupModel |
|
5 | from rhodecode.model.repos_group import ReposGroupModel | |
6 | from rhodecode.model.repo import RepoModel |
|
6 | from rhodecode.model.repo import RepoModel | |
7 | from rhodecode.model.db import RepoGroup, User |
|
7 | from rhodecode.model.db import RepoGroup, User | |
8 | from rhodecode.model.meta import Session |
|
8 | from rhodecode.model.meta import Session | |
9 | from sqlalchemy.exc import IntegrityError |
|
9 | from sqlalchemy.exc import IntegrityError | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def _make_group(path, desc='desc', parent_id=None, |
|
12 | def _make_group(path, desc='desc', parent_id=None, | |
13 | skip_if_exists=False): |
|
13 | skip_if_exists=False): | |
14 |
|
14 | |||
15 | gr = RepoGroup.get_by_group_name(path) |
|
15 | gr = RepoGroup.get_by_group_name(path) | |
16 | if gr and skip_if_exists: |
|
16 | if gr and skip_if_exists: | |
17 | return gr |
|
17 | return gr | |
18 |
|
18 | |||
19 | gr = ReposGroupModel().create(path, desc, parent_id) |
|
19 | gr = ReposGroupModel().create(path, desc, parent_id) | |
20 | return gr |
|
20 | return gr | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | class TestReposGroups(unittest.TestCase): |
|
23 | class TestReposGroups(unittest.TestCase): | |
24 |
|
24 | |||
25 | def setUp(self): |
|
25 | def setUp(self): | |
26 | self.g1 = _make_group('test1', skip_if_exists=True) |
|
26 | self.g1 = _make_group('test1', skip_if_exists=True) | |
27 | Session().commit() |
|
27 | Session().commit() | |
28 | self.g2 = _make_group('test2', skip_if_exists=True) |
|
28 | self.g2 = _make_group('test2', skip_if_exists=True) | |
29 | Session().commit() |
|
29 | Session().commit() | |
30 | self.g3 = _make_group('test3', skip_if_exists=True) |
|
30 | self.g3 = _make_group('test3', skip_if_exists=True) | |
31 | Session().commit() |
|
31 | Session().commit() | |
32 |
|
32 | |||
33 | def tearDown(self): |
|
33 | def tearDown(self): | |
34 | print 'out' |
|
34 | print 'out' | |
35 |
|
35 | |||
36 | def __check_path(self, *path): |
|
36 | def __check_path(self, *path): | |
37 | """ |
|
37 | """ | |
38 | Checks the path for existance ! |
|
38 | Checks the path for existance ! | |
39 | """ |
|
39 | """ | |
40 | path = [TESTS_TMP_PATH] + list(path) |
|
40 | path = [TESTS_TMP_PATH] + list(path) | |
41 | path = os.path.join(*path) |
|
41 | path = os.path.join(*path) | |
42 | return os.path.isdir(path) |
|
42 | return os.path.isdir(path) | |
43 |
|
43 | |||
44 | def _check_folders(self): |
|
44 | def _check_folders(self): | |
45 | print os.listdir(TESTS_TMP_PATH) |
|
45 | print os.listdir(TESTS_TMP_PATH) | |
46 |
|
46 | |||
47 | def __delete_group(self, id_): |
|
47 | def __delete_group(self, id_): | |
48 | ReposGroupModel().delete(id_) |
|
48 | ReposGroupModel().delete(id_) | |
49 |
|
49 | |||
50 | def __update_group(self, id_, path, desc='desc', parent_id=None): |
|
50 | def __update_group(self, id_, path, desc='desc', parent_id=None): | |
51 | form_data = dict( |
|
51 | form_data = dict( | |
52 | group_name=path, |
|
52 | group_name=path, | |
53 | group_description=desc, |
|
53 | group_description=desc, | |
54 | group_parent_id=parent_id, |
|
54 | group_parent_id=parent_id, | |
55 | perms_updates=[], |
|
55 | perms_updates=[], | |
56 | perms_new=[] |
|
56 | perms_new=[] | |
57 | ) |
|
57 | ) | |
58 | gr = ReposGroupModel().update(id_, form_data) |
|
58 | gr = ReposGroupModel().update(id_, form_data) | |
59 | return gr |
|
59 | return gr | |
60 |
|
60 | |||
61 | def test_create_group(self): |
|
61 | def test_create_group(self): | |
62 | g = _make_group('newGroup') |
|
62 | g = _make_group('newGroup') | |
63 | self.assertEqual(g.full_path, 'newGroup') |
|
63 | self.assertEqual(g.full_path, 'newGroup') | |
64 |
|
64 | |||
65 | self.assertTrue(self.__check_path('newGroup')) |
|
65 | self.assertTrue(self.__check_path('newGroup')) | |
66 |
|
66 | |||
67 | def test_create_same_name_group(self): |
|
67 | def test_create_same_name_group(self): | |
68 | self.assertRaises(IntegrityError, lambda: _make_group('newGroup')) |
|
68 | self.assertRaises(IntegrityError, lambda: _make_group('newGroup')) | |
69 | Session().rollback() |
|
69 | Session().rollback() | |
70 |
|
70 | |||
71 | def test_same_subgroup(self): |
|
71 | def test_same_subgroup(self): | |
72 | sg1 = _make_group('sub1', parent_id=self.g1.group_id) |
|
72 | sg1 = _make_group('sub1', parent_id=self.g1.group_id) | |
73 | self.assertEqual(sg1.parent_group, self.g1) |
|
73 | self.assertEqual(sg1.parent_group, self.g1) | |
74 | self.assertEqual(sg1.full_path, 'test1/sub1') |
|
74 | self.assertEqual(sg1.full_path, 'test1/sub1') | |
75 | self.assertTrue(self.__check_path('test1', 'sub1')) |
|
75 | self.assertTrue(self.__check_path('test1', 'sub1')) | |
76 |
|
76 | |||
77 | ssg1 = _make_group('subsub1', parent_id=sg1.group_id) |
|
77 | ssg1 = _make_group('subsub1', parent_id=sg1.group_id) | |
78 | self.assertEqual(ssg1.parent_group, sg1) |
|
78 | self.assertEqual(ssg1.parent_group, sg1) | |
79 | self.assertEqual(ssg1.full_path, 'test1/sub1/subsub1') |
|
79 | self.assertEqual(ssg1.full_path, 'test1/sub1/subsub1') | |
80 | self.assertTrue(self.__check_path('test1', 'sub1', 'subsub1')) |
|
80 | self.assertTrue(self.__check_path('test1', 'sub1', 'subsub1')) | |
81 |
|
81 | |||
82 | def test_remove_group(self): |
|
82 | def test_remove_group(self): | |
83 | sg1 = _make_group('deleteme') |
|
83 | sg1 = _make_group('deleteme') | |
84 | self.__delete_group(sg1.group_id) |
|
84 | self.__delete_group(sg1.group_id) | |
85 |
|
85 | |||
86 | self.assertEqual(RepoGroup.get(sg1.group_id), None) |
|
86 | self.assertEqual(RepoGroup.get(sg1.group_id), None) | |
87 | self.assertFalse(self.__check_path('deteteme')) |
|
87 | self.assertFalse(self.__check_path('deteteme')) | |
88 |
|
88 | |||
89 | sg1 = _make_group('deleteme', parent_id=self.g1.group_id) |
|
89 | sg1 = _make_group('deleteme', parent_id=self.g1.group_id) | |
90 | self.__delete_group(sg1.group_id) |
|
90 | self.__delete_group(sg1.group_id) | |
91 |
|
91 | |||
92 | self.assertEqual(RepoGroup.get(sg1.group_id), None) |
|
92 | self.assertEqual(RepoGroup.get(sg1.group_id), None) | |
93 | self.assertFalse(self.__check_path('test1', 'deteteme')) |
|
93 | self.assertFalse(self.__check_path('test1', 'deteteme')) | |
94 |
|
94 | |||
95 | def test_rename_single_group(self): |
|
95 | def test_rename_single_group(self): | |
96 | sg1 = _make_group('initial') |
|
96 | sg1 = _make_group('initial') | |
97 |
|
97 | |||
98 | new_sg1 = self.__update_group(sg1.group_id, 'after') |
|
98 | new_sg1 = self.__update_group(sg1.group_id, 'after') | |
99 | self.assertTrue(self.__check_path('after')) |
|
99 | self.assertTrue(self.__check_path('after')) | |
100 | self.assertEqual(RepoGroup.get_by_group_name('initial'), None) |
|
100 | self.assertEqual(RepoGroup.get_by_group_name('initial'), None) | |
101 |
|
101 | |||
102 | def test_update_group_parent(self): |
|
102 | def test_update_group_parent(self): | |
103 |
|
103 | |||
104 | sg1 = _make_group('initial', parent_id=self.g1.group_id) |
|
104 | sg1 = _make_group('initial', parent_id=self.g1.group_id) | |
105 |
|
105 | |||
106 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id) |
|
106 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id) | |
107 | self.assertTrue(self.__check_path('test1', 'after')) |
|
107 | self.assertTrue(self.__check_path('test1', 'after')) | |
108 | self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None) |
|
108 | self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None) | |
109 |
|
109 | |||
110 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id) |
|
110 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id) | |
111 | self.assertTrue(self.__check_path('test3', 'after')) |
|
111 | self.assertTrue(self.__check_path('test3', 'after')) | |
112 | self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None) |
|
112 | self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None) | |
113 |
|
113 | |||
114 | new_sg1 = self.__update_group(sg1.group_id, 'hello') |
|
114 | new_sg1 = self.__update_group(sg1.group_id, 'hello') | |
115 | self.assertTrue(self.__check_path('hello')) |
|
115 | self.assertTrue(self.__check_path('hello')) | |
116 |
|
116 | |||
117 | self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1) |
|
117 | self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1) | |
118 |
|
118 | |||
119 | def test_subgrouping_with_repo(self): |
|
119 | def test_subgrouping_with_repo(self): | |
120 |
|
120 | |||
121 | g1 = _make_group('g1') |
|
121 | g1 = _make_group('g1') | |
122 | g2 = _make_group('g2') |
|
122 | g2 = _make_group('g2') | |
123 |
|
123 | |||
124 | # create new repo |
|
124 | # create new repo | |
125 | form_data = dict(repo_name='john', |
|
125 | form_data = dict(repo_name='john', | |
126 | repo_name_full='john', |
|
126 | repo_name_full='john', | |
127 | fork_name=None, |
|
127 | fork_name=None, | |
128 | description=None, |
|
128 | description=None, | |
129 | repo_group=None, |
|
129 | repo_group=None, | |
130 | private=False, |
|
130 | private=False, | |
131 | repo_type='hg', |
|
131 | repo_type='hg', | |
132 | clone_uri=None, |
|
132 | clone_uri=None, | |
133 | landing_rev='tip') |
|
133 | landing_rev='tip') | |
134 | cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN) |
|
134 | cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN) | |
135 | r = RepoModel().create(form_data, cur_user) |
|
135 | r = RepoModel().create(form_data, cur_user) | |
136 |
|
136 | |||
137 | self.assertEqual(r.repo_name, 'john') |
|
137 | self.assertEqual(r.repo_name, 'john') | |
138 |
|
138 | |||
139 | # put repo into group |
|
139 | # put repo into group | |
140 | form_data = form_data |
|
140 | form_data = form_data | |
141 | form_data['repo_group'] = g1.group_id |
|
141 | form_data['repo_group'] = g1.group_id | |
142 | form_data['perms_new'] = [] |
|
142 | form_data['perms_new'] = [] | |
143 | form_data['perms_updates'] = [] |
|
143 | form_data['perms_updates'] = [] | |
144 | RepoModel().update(r.repo_name, form_data) |
|
144 | RepoModel().update(r.repo_name, form_data) | |
145 | self.assertEqual(r.repo_name, 'g1/john') |
|
145 | self.assertEqual(r.repo_name, 'g1/john') | |
146 |
|
146 | |||
147 | self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id) |
|
147 | self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id) | |
148 | self.assertTrue(self.__check_path('g2', 'g1')) |
|
148 | self.assertTrue(self.__check_path('g2', 'g1')) | |
149 |
|
149 | |||
150 | # test repo |
|
150 | # test repo | |
151 | self.assertEqual(r.repo_name, RepoGroup.url_sep().join(['g2', 'g1', |
|
151 | self.assertEqual(r.repo_name, RepoGroup.url_sep().join(['g2', 'g1', | |
152 | r.just_name])) |
|
152 | r.just_name])) | |
153 |
|
153 | |||
154 | def test_move_to_root(self): |
|
154 | def test_move_to_root(self): | |
155 | g1 = _make_group('t11') |
|
155 | g1 = _make_group('t11') | |
156 | Session().commit() |
|
156 | Session().commit() | |
157 | g2 = _make_group('t22', parent_id=g1.group_id) |
|
157 | g2 = _make_group('t22', parent_id=g1.group_id) | |
158 | Session().commit() |
|
158 | Session().commit() | |
159 |
|
159 | |||
160 | self.assertEqual(g2.full_path, 't11/t22') |
|
160 | self.assertEqual(g2.full_path, 't11/t22') | |
161 | self.assertTrue(self.__check_path('t11', 't22')) |
|
161 | self.assertTrue(self.__check_path('t11', 't22')) | |
162 |
|
162 | |||
163 | g2 = self.__update_group(g2.group_id, 'g22', parent_id=None) |
|
163 | g2 = self.__update_group(g2.group_id, 'g22', parent_id=None) | |
164 | Session().commit() |
|
164 | Session().commit() | |
165 |
|
165 | |||
166 | self.assertEqual(g2.group_name, 'g22') |
|
166 | self.assertEqual(g2.group_name, 'g22') | |
167 | # we moved out group from t1 to '' so it's full path should be 'g2' |
|
167 | # we moved out group from t1 to '' so it's full path should be 'g2' | |
168 | self.assertEqual(g2.full_path, 'g22') |
|
168 | self.assertEqual(g2.full_path, 'g22') | |
169 | self.assertFalse(self.__check_path('t11', 't22')) |
|
169 | self.assertFalse(self.__check_path('t11', 't22')) | |
170 | self.assertTrue(self.__check_path('g22')) No newline at end of file |
|
170 | self.assertTrue(self.__check_path('g22')) |
General Comments 0
You need to be logged in to leave comments.
Login now