Show More
@@ -1,247 +1,236 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2018 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2018 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import os |
|
21 | import os | |
22 | import time |
|
22 | import time | |
23 | import logging |
|
23 | import logging | |
24 | import datetime |
|
24 | import datetime | |
25 | import hashlib |
|
25 | import hashlib | |
26 | import tempfile |
|
26 | import tempfile | |
27 | from os.path import join as jn |
|
27 | from os.path import join as jn | |
28 |
|
28 | |||
29 | from tempfile import _RandomNameSequence |
|
29 | from tempfile import _RandomNameSequence | |
30 |
|
30 | |||
31 | import pytest |
|
31 | import pytest | |
32 |
|
32 | |||
33 | from rhodecode.model.db import User |
|
33 | from rhodecode.model.db import User | |
34 | from rhodecode.lib import auth |
|
34 | from rhodecode.lib import auth | |
35 | from rhodecode.lib import helpers as h |
|
35 | from rhodecode.lib import helpers as h | |
36 | from rhodecode.lib.helpers import flash, link_to |
|
36 | from rhodecode.lib.helpers import flash, link_to | |
37 | from rhodecode.lib.utils2 import safe_str |
|
37 | from rhodecode.lib.utils2 import safe_str | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | log = logging.getLogger(__name__) |
|
40 | log = logging.getLogger(__name__) | |
41 |
|
41 | |||
42 | __all__ = [ |
|
42 | __all__ = [ | |
43 | 'get_new_dir', 'TestController', |
|
43 | 'get_new_dir', 'TestController', | |
44 |
'link_to', ' |
|
44 | 'link_to', 'clear_all_caches', | |
45 | 'assert_session_flash', 'login_user', 'no_newline_id_generator', |
|
45 | 'assert_session_flash', 'login_user', 'no_newline_id_generator', | |
46 | 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'SVN_REPO', |
|
46 | 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'SVN_REPO', | |
47 | 'NEW_HG_REPO', 'NEW_GIT_REPO', |
|
47 | 'NEW_HG_REPO', 'NEW_GIT_REPO', | |
48 | 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', |
|
48 | 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', | |
49 | 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', |
|
49 | 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', | |
50 | 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN', |
|
50 | 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN', | |
51 | 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO', |
|
51 | 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO', | |
52 | 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO', |
|
52 | 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO', | |
53 | 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'SCM_TESTS', |
|
53 | 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'SCM_TESTS', | |
54 | ] |
|
54 | ] | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | # SOME GLOBALS FOR TESTS |
|
57 | # SOME GLOBALS FOR TESTS | |
58 | TEST_DIR = tempfile.gettempdir() |
|
58 | TEST_DIR = tempfile.gettempdir() | |
59 |
|
59 | |||
60 | TESTS_TMP_PATH = jn(TEST_DIR, 'rc_test_%s' % _RandomNameSequence().next()) |
|
60 | TESTS_TMP_PATH = jn(TEST_DIR, 'rc_test_%s' % _RandomNameSequence().next()) | |
61 | TEST_USER_ADMIN_LOGIN = 'test_admin' |
|
61 | TEST_USER_ADMIN_LOGIN = 'test_admin' | |
62 | TEST_USER_ADMIN_PASS = 'test12' |
|
62 | TEST_USER_ADMIN_PASS = 'test12' | |
63 | TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com' |
|
63 | TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com' | |
64 |
|
64 | |||
65 | TEST_USER_REGULAR_LOGIN = 'test_regular' |
|
65 | TEST_USER_REGULAR_LOGIN = 'test_regular' | |
66 | TEST_USER_REGULAR_PASS = 'test12' |
|
66 | TEST_USER_REGULAR_PASS = 'test12' | |
67 | TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com' |
|
67 | TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com' | |
68 |
|
68 | |||
69 | TEST_USER_REGULAR2_LOGIN = 'test_regular2' |
|
69 | TEST_USER_REGULAR2_LOGIN = 'test_regular2' | |
70 | TEST_USER_REGULAR2_PASS = 'test12' |
|
70 | TEST_USER_REGULAR2_PASS = 'test12' | |
71 | TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com' |
|
71 | TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com' | |
72 |
|
72 | |||
73 | HG_REPO = 'vcs_test_hg' |
|
73 | HG_REPO = 'vcs_test_hg' | |
74 | GIT_REPO = 'vcs_test_git' |
|
74 | GIT_REPO = 'vcs_test_git' | |
75 | SVN_REPO = 'vcs_test_svn' |
|
75 | SVN_REPO = 'vcs_test_svn' | |
76 |
|
76 | |||
77 | NEW_HG_REPO = 'vcs_test_hg_new' |
|
77 | NEW_HG_REPO = 'vcs_test_hg_new' | |
78 | NEW_GIT_REPO = 'vcs_test_git_new' |
|
78 | NEW_GIT_REPO = 'vcs_test_git_new' | |
79 |
|
79 | |||
80 | HG_FORK = 'vcs_test_hg_fork' |
|
80 | HG_FORK = 'vcs_test_hg_fork' | |
81 | GIT_FORK = 'vcs_test_git_fork' |
|
81 | GIT_FORK = 'vcs_test_git_fork' | |
82 |
|
82 | |||
83 | ## VCS |
|
83 | ## VCS | |
84 | SCM_TESTS = ['hg', 'git'] |
|
84 | SCM_TESTS = ['hg', 'git'] | |
85 | uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple()))) |
|
85 | uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple()))) | |
86 |
|
86 | |||
87 | TEST_GIT_REPO = jn(TESTS_TMP_PATH, GIT_REPO) |
|
87 | TEST_GIT_REPO = jn(TESTS_TMP_PATH, GIT_REPO) | |
88 | TEST_GIT_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcsgitclone%s' % uniq_suffix) |
|
88 | TEST_GIT_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcsgitclone%s' % uniq_suffix) | |
89 | TEST_GIT_REPO_PULL = jn(TESTS_TMP_PATH, 'vcsgitpull%s' % uniq_suffix) |
|
89 | TEST_GIT_REPO_PULL = jn(TESTS_TMP_PATH, 'vcsgitpull%s' % uniq_suffix) | |
90 |
|
90 | |||
91 | TEST_HG_REPO = jn(TESTS_TMP_PATH, HG_REPO) |
|
91 | TEST_HG_REPO = jn(TESTS_TMP_PATH, HG_REPO) | |
92 | TEST_HG_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcshgclone%s' % uniq_suffix) |
|
92 | TEST_HG_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcshgclone%s' % uniq_suffix) | |
93 | TEST_HG_REPO_PULL = jn(TESTS_TMP_PATH, 'vcshgpull%s' % uniq_suffix) |
|
93 | TEST_HG_REPO_PULL = jn(TESTS_TMP_PATH, 'vcshgpull%s' % uniq_suffix) | |
94 |
|
94 | |||
95 | TEST_REPO_PREFIX = 'vcs-test' |
|
95 | TEST_REPO_PREFIX = 'vcs-test' | |
96 |
|
96 | |||
97 |
|
97 | |||
98 | # skip ldap tests if LDAP lib is not installed |
|
|||
99 | ldap_lib_installed = False |
|
|||
100 | try: |
|
|||
101 | import ldap |
|
|||
102 | ldap_lib_installed = True |
|
|||
103 | except ImportError: |
|
|||
104 | ldap = None |
|
|||
105 | # means that python-ldap is not installed |
|
|||
106 | pass |
|
|||
107 |
|
||||
108 |
|
||||
109 | def clear_all_caches(): |
|
98 | def clear_all_caches(): | |
110 | from beaker.cache import cache_managers |
|
99 | from beaker.cache import cache_managers | |
111 | for _cache in cache_managers.values(): |
|
100 | for _cache in cache_managers.values(): | |
112 | _cache.clear() |
|
101 | _cache.clear() | |
113 |
|
102 | |||
114 |
|
103 | |||
115 | def get_new_dir(title): |
|
104 | def get_new_dir(title): | |
116 | """ |
|
105 | """ | |
117 | Returns always new directory path. |
|
106 | Returns always new directory path. | |
118 | """ |
|
107 | """ | |
119 | from rhodecode.tests.vcs.utils import get_normalized_path |
|
108 | from rhodecode.tests.vcs.utils import get_normalized_path | |
120 | name_parts = [TEST_REPO_PREFIX] |
|
109 | name_parts = [TEST_REPO_PREFIX] | |
121 | if title: |
|
110 | if title: | |
122 | name_parts.append(title) |
|
111 | name_parts.append(title) | |
123 | hex_str = hashlib.sha1('%s %s' % (os.getpid(), time.time())).hexdigest() |
|
112 | hex_str = hashlib.sha1('%s %s' % (os.getpid(), time.time())).hexdigest() | |
124 | name_parts.append(hex_str) |
|
113 | name_parts.append(hex_str) | |
125 | name = '-'.join(name_parts) |
|
114 | name = '-'.join(name_parts) | |
126 | path = os.path.join(TEST_DIR, name) |
|
115 | path = os.path.join(TEST_DIR, name) | |
127 | return get_normalized_path(path) |
|
116 | return get_normalized_path(path) | |
128 |
|
117 | |||
129 |
|
118 | |||
130 | @pytest.mark.usefixtures('app', 'index_location') |
|
119 | @pytest.mark.usefixtures('app', 'index_location') | |
131 | class TestController(object): |
|
120 | class TestController(object): | |
132 |
|
121 | |||
133 | maxDiff = None |
|
122 | maxDiff = None | |
134 |
|
123 | |||
135 | def log_user(self, username=TEST_USER_ADMIN_LOGIN, |
|
124 | def log_user(self, username=TEST_USER_ADMIN_LOGIN, | |
136 | password=TEST_USER_ADMIN_PASS): |
|
125 | password=TEST_USER_ADMIN_PASS): | |
137 | self._logged_username = username |
|
126 | self._logged_username = username | |
138 | self._session = login_user_session(self.app, username, password) |
|
127 | self._session = login_user_session(self.app, username, password) | |
139 | self.csrf_token = auth.get_csrf_token(self._session) |
|
128 | self.csrf_token = auth.get_csrf_token(self._session) | |
140 |
|
129 | |||
141 | return self._session['rhodecode_user'] |
|
130 | return self._session['rhodecode_user'] | |
142 |
|
131 | |||
143 | def logout_user(self): |
|
132 | def logout_user(self): | |
144 | logout_user_session(self.app, auth.get_csrf_token(self._session)) |
|
133 | logout_user_session(self.app, auth.get_csrf_token(self._session)) | |
145 | self.csrf_token = None |
|
134 | self.csrf_token = None | |
146 | self._logged_username = None |
|
135 | self._logged_username = None | |
147 | self._session = None |
|
136 | self._session = None | |
148 |
|
137 | |||
149 | def _get_logged_user(self): |
|
138 | def _get_logged_user(self): | |
150 | return User.get_by_username(self._logged_username) |
|
139 | return User.get_by_username(self._logged_username) | |
151 |
|
140 | |||
152 |
|
141 | |||
153 | def login_user_session( |
|
142 | def login_user_session( | |
154 | app, username=TEST_USER_ADMIN_LOGIN, password=TEST_USER_ADMIN_PASS): |
|
143 | app, username=TEST_USER_ADMIN_LOGIN, password=TEST_USER_ADMIN_PASS): | |
155 |
|
144 | |||
156 | response = app.post( |
|
145 | response = app.post( | |
157 | h.route_path('login'), |
|
146 | h.route_path('login'), | |
158 | {'username': username, 'password': password}) |
|
147 | {'username': username, 'password': password}) | |
159 | if 'invalid user name' in response.body: |
|
148 | if 'invalid user name' in response.body: | |
160 | pytest.fail('could not login using %s %s' % (username, password)) |
|
149 | pytest.fail('could not login using %s %s' % (username, password)) | |
161 |
|
150 | |||
162 | assert response.status == '302 Found' |
|
151 | assert response.status == '302 Found' | |
163 | response = response.follow() |
|
152 | response = response.follow() | |
164 | assert response.status == '200 OK' |
|
153 | assert response.status == '200 OK' | |
165 |
|
154 | |||
166 | session = response.get_session_from_response() |
|
155 | session = response.get_session_from_response() | |
167 | assert 'rhodecode_user' in session |
|
156 | assert 'rhodecode_user' in session | |
168 | rc_user = session['rhodecode_user'] |
|
157 | rc_user = session['rhodecode_user'] | |
169 | assert rc_user.get('username') == username |
|
158 | assert rc_user.get('username') == username | |
170 | assert rc_user.get('is_authenticated') |
|
159 | assert rc_user.get('is_authenticated') | |
171 |
|
160 | |||
172 | return session |
|
161 | return session | |
173 |
|
162 | |||
174 |
|
163 | |||
175 | def logout_user_session(app, csrf_token): |
|
164 | def logout_user_session(app, csrf_token): | |
176 | app.post(h.route_path('logout'), {'csrf_token': csrf_token}, status=302) |
|
165 | app.post(h.route_path('logout'), {'csrf_token': csrf_token}, status=302) | |
177 |
|
166 | |||
178 |
|
167 | |||
179 | def login_user(app, username=TEST_USER_ADMIN_LOGIN, |
|
168 | def login_user(app, username=TEST_USER_ADMIN_LOGIN, | |
180 | password=TEST_USER_ADMIN_PASS): |
|
169 | password=TEST_USER_ADMIN_PASS): | |
181 | return login_user_session(app, username, password)['rhodecode_user'] |
|
170 | return login_user_session(app, username, password)['rhodecode_user'] | |
182 |
|
171 | |||
183 |
|
172 | |||
184 | def assert_session_flash(response, msg=None, category=None, no_=None): |
|
173 | def assert_session_flash(response, msg=None, category=None, no_=None): | |
185 | """ |
|
174 | """ | |
186 | Assert on a flash message in the current session. |
|
175 | Assert on a flash message in the current session. | |
187 |
|
176 | |||
188 | :param response: Response from give calll, it will contain flash |
|
177 | :param response: Response from give calll, it will contain flash | |
189 | messages or bound session with them. |
|
178 | messages or bound session with them. | |
190 | :param msg: The expected message. Will be evaluated if a |
|
179 | :param msg: The expected message. Will be evaluated if a | |
191 | :class:`LazyString` is passed in. |
|
180 | :class:`LazyString` is passed in. | |
192 | :param category: Optional. If passed, the message category will be |
|
181 | :param category: Optional. If passed, the message category will be | |
193 | checked as well. |
|
182 | checked as well. | |
194 | :param no_: Optional. If passed, the message will be checked to NOT |
|
183 | :param no_: Optional. If passed, the message will be checked to NOT | |
195 | be in the flash session |
|
184 | be in the flash session | |
196 | """ |
|
185 | """ | |
197 | if msg is None and no_ is None: |
|
186 | if msg is None and no_ is None: | |
198 | raise ValueError("Parameter msg or no_ is required.") |
|
187 | raise ValueError("Parameter msg or no_ is required.") | |
199 |
|
188 | |||
200 | if msg and no_: |
|
189 | if msg and no_: | |
201 | raise ValueError("Please specify either msg or no_, but not both") |
|
190 | raise ValueError("Please specify either msg or no_, but not both") | |
202 |
|
191 | |||
203 | session = response.get_session_from_response() |
|
192 | session = response.get_session_from_response() | |
204 | messages = flash.pop_messages(session=session) |
|
193 | messages = flash.pop_messages(session=session) | |
205 | msg = _eval_if_lazy(msg) |
|
194 | msg = _eval_if_lazy(msg) | |
206 |
|
195 | |||
207 | if no_: |
|
196 | if no_: | |
208 | error_msg = 'unable to detect no_ message `%s` in empty flash list' % no_ |
|
197 | error_msg = 'unable to detect no_ message `%s` in empty flash list' % no_ | |
209 | else: |
|
198 | else: | |
210 | error_msg = 'unable to find message `%s` in empty flash list' % msg |
|
199 | error_msg = 'unable to find message `%s` in empty flash list' % msg | |
211 | assert messages, error_msg |
|
200 | assert messages, error_msg | |
212 | message = messages[0] |
|
201 | message = messages[0] | |
213 |
|
202 | |||
214 | message_text = _eval_if_lazy(message.message) or '' |
|
203 | message_text = _eval_if_lazy(message.message) or '' | |
215 |
|
204 | |||
216 | if no_: |
|
205 | if no_: | |
217 | if no_ in message_text: |
|
206 | if no_ in message_text: | |
218 | msg = u'msg `%s` found in session flash.' % (no_,) |
|
207 | msg = u'msg `%s` found in session flash.' % (no_,) | |
219 | pytest.fail(safe_str(msg)) |
|
208 | pytest.fail(safe_str(msg)) | |
220 | else: |
|
209 | else: | |
221 | if msg not in message_text: |
|
210 | if msg not in message_text: | |
222 | fail_msg = u'msg `%s` not found in session ' \ |
|
211 | fail_msg = u'msg `%s` not found in session ' \ | |
223 | u'flash: got `%s` (type:%s) instead' % ( |
|
212 | u'flash: got `%s` (type:%s) instead' % ( | |
224 | msg, message_text, type(message_text)) |
|
213 | msg, message_text, type(message_text)) | |
225 |
|
214 | |||
226 | pytest.fail(safe_str(fail_msg)) |
|
215 | pytest.fail(safe_str(fail_msg)) | |
227 | if category: |
|
216 | if category: | |
228 | assert category == message.category |
|
217 | assert category == message.category | |
229 |
|
218 | |||
230 |
|
219 | |||
231 | def _eval_if_lazy(value): |
|
220 | def _eval_if_lazy(value): | |
232 | return value.eval() if hasattr(value, 'eval') else value |
|
221 | return value.eval() if hasattr(value, 'eval') else value | |
233 |
|
222 | |||
234 |
|
223 | |||
235 | def no_newline_id_generator(test_name): |
|
224 | def no_newline_id_generator(test_name): | |
236 | """ |
|
225 | """ | |
237 | Generates a test name without spaces or newlines characters. Used for |
|
226 | Generates a test name without spaces or newlines characters. Used for | |
238 | nicer output of progress of test |
|
227 | nicer output of progress of test | |
239 | """ |
|
228 | """ | |
240 | org_name = test_name |
|
229 | org_name = test_name | |
241 | test_name = test_name\ |
|
230 | test_name = test_name\ | |
242 | .replace('\n', '_N') \ |
|
231 | .replace('\n', '_N') \ | |
243 | .replace('\r', '_N') \ |
|
232 | .replace('\r', '_N') \ | |
244 | .replace('\t', '_T') \ |
|
233 | .replace('\t', '_T') \ | |
245 | .replace(' ', '_S') |
|
234 | .replace(' ', '_S') | |
246 |
|
235 | |||
247 | return test_name or 'test-with-empty-name' |
|
236 | return test_name or 'test-with-empty-name' |
@@ -1,295 +1,294 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2018 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2018 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | import formencode |
|
22 | import formencode | |
23 | import pytest |
|
23 | import pytest | |
24 |
|
24 | |||
25 | from rhodecode.tests import ( |
|
25 | from rhodecode.tests import ( | |
26 | HG_REPO, TEST_USER_REGULAR2_EMAIL, TEST_USER_REGULAR2_LOGIN, |
|
26 | HG_REPO, TEST_USER_REGULAR2_EMAIL, TEST_USER_REGULAR2_LOGIN, | |
27 |
TEST_USER_REGULAR2_PASS, TEST_USER_ADMIN_LOGIN, TESTS_TMP_PATH |
|
27 | TEST_USER_REGULAR2_PASS, TEST_USER_ADMIN_LOGIN, TESTS_TMP_PATH) | |
28 | ldap_lib_installed) |
|
|||
29 |
|
28 | |||
30 | from rhodecode.model import validators as v |
|
29 | from rhodecode.model import validators as v | |
31 | from rhodecode.model.user_group import UserGroupModel |
|
30 | from rhodecode.model.user_group import UserGroupModel | |
32 |
|
31 | |||
33 | from rhodecode.model.meta import Session |
|
32 | from rhodecode.model.meta import Session | |
34 | from rhodecode.model.repo_group import RepoGroupModel |
|
33 | from rhodecode.model.repo_group import RepoGroupModel | |
35 | from rhodecode.model.db import ChangesetStatus, Repository |
|
34 | from rhodecode.model.db import ChangesetStatus, Repository | |
36 | from rhodecode.model.changeset_status import ChangesetStatusModel |
|
35 | from rhodecode.model.changeset_status import ChangesetStatusModel | |
37 | from rhodecode.tests.fixture import Fixture |
|
36 | from rhodecode.tests.fixture import Fixture | |
38 |
|
37 | |||
39 | fixture = Fixture() |
|
38 | fixture = Fixture() | |
40 |
|
39 | |||
41 | pytestmark = pytest.mark.usefixtures('baseapp') |
|
40 | pytestmark = pytest.mark.usefixtures('baseapp') | |
42 |
|
41 | |||
43 |
|
42 | |||
44 | @pytest.fixture |
|
43 | @pytest.fixture | |
45 | def localizer(): |
|
44 | def localizer(): | |
46 | def func(msg): |
|
45 | def func(msg): | |
47 | return msg |
|
46 | return msg | |
48 | return func |
|
47 | return func | |
49 |
|
48 | |||
50 |
|
49 | |||
51 | def test_Message_extractor(localizer): |
|
50 | def test_Message_extractor(localizer): | |
52 | validator = v.ValidUsername(localizer) |
|
51 | validator = v.ValidUsername(localizer) | |
53 | pytest.raises(formencode.Invalid, validator.to_python, 'default') |
|
52 | pytest.raises(formencode.Invalid, validator.to_python, 'default') | |
54 |
|
53 | |||
55 | class StateObj(object): |
|
54 | class StateObj(object): | |
56 | pass |
|
55 | pass | |
57 |
|
56 | |||
58 | pytest.raises( |
|
57 | pytest.raises( | |
59 | formencode.Invalid, validator.to_python, 'default', StateObj) |
|
58 | formencode.Invalid, validator.to_python, 'default', StateObj) | |
60 |
|
59 | |||
61 |
|
60 | |||
62 | def test_ValidUsername(localizer): |
|
61 | def test_ValidUsername(localizer): | |
63 | validator = v.ValidUsername(localizer) |
|
62 | validator = v.ValidUsername(localizer) | |
64 |
|
63 | |||
65 | pytest.raises(formencode.Invalid, validator.to_python, 'default') |
|
64 | pytest.raises(formencode.Invalid, validator.to_python, 'default') | |
66 | pytest.raises(formencode.Invalid, validator.to_python, 'new_user') |
|
65 | pytest.raises(formencode.Invalid, validator.to_python, 'new_user') | |
67 | pytest.raises(formencode.Invalid, validator.to_python, '.,') |
|
66 | pytest.raises(formencode.Invalid, validator.to_python, '.,') | |
68 | pytest.raises( |
|
67 | pytest.raises( | |
69 | formencode.Invalid, validator.to_python, TEST_USER_ADMIN_LOGIN) |
|
68 | formencode.Invalid, validator.to_python, TEST_USER_ADMIN_LOGIN) | |
70 | assert 'test' == validator.to_python('test') |
|
69 | assert 'test' == validator.to_python('test') | |
71 |
|
70 | |||
72 | validator = v.ValidUsername(localizer, edit=True, old_data={'user_id': 1}) |
|
71 | validator = v.ValidUsername(localizer, edit=True, old_data={'user_id': 1}) | |
73 |
|
72 | |||
74 |
|
73 | |||
75 | def test_ValidRepoUser(localizer): |
|
74 | def test_ValidRepoUser(localizer): | |
76 | validator = v.ValidRepoUser(localizer) |
|
75 | validator = v.ValidRepoUser(localizer) | |
77 | pytest.raises(formencode.Invalid, validator.to_python, 'nouser') |
|
76 | pytest.raises(formencode.Invalid, validator.to_python, 'nouser') | |
78 | assert TEST_USER_ADMIN_LOGIN == \ |
|
77 | assert TEST_USER_ADMIN_LOGIN == \ | |
79 | validator.to_python(TEST_USER_ADMIN_LOGIN) |
|
78 | validator.to_python(TEST_USER_ADMIN_LOGIN) | |
80 |
|
79 | |||
81 |
|
80 | |||
82 | def test_ValidUserGroup(localizer): |
|
81 | def test_ValidUserGroup(localizer): | |
83 | validator = v.ValidUserGroup(localizer) |
|
82 | validator = v.ValidUserGroup(localizer) | |
84 | pytest.raises(formencode.Invalid, validator.to_python, 'default') |
|
83 | pytest.raises(formencode.Invalid, validator.to_python, 'default') | |
85 | pytest.raises(formencode.Invalid, validator.to_python, '.,') |
|
84 | pytest.raises(formencode.Invalid, validator.to_python, '.,') | |
86 |
|
85 | |||
87 | gr = fixture.create_user_group('test') |
|
86 | gr = fixture.create_user_group('test') | |
88 | gr2 = fixture.create_user_group('tes2') |
|
87 | gr2 = fixture.create_user_group('tes2') | |
89 | Session().commit() |
|
88 | Session().commit() | |
90 | pytest.raises(formencode.Invalid, validator.to_python, 'test') |
|
89 | pytest.raises(formencode.Invalid, validator.to_python, 'test') | |
91 | assert gr.users_group_id is not None |
|
90 | assert gr.users_group_id is not None | |
92 | validator = v.ValidUserGroup(localizer, |
|
91 | validator = v.ValidUserGroup(localizer, | |
93 | edit=True, |
|
92 | edit=True, | |
94 | old_data={'users_group_id': gr2.users_group_id}) |
|
93 | old_data={'users_group_id': gr2.users_group_id}) | |
95 |
|
94 | |||
96 | pytest.raises(formencode.Invalid, validator.to_python, 'test') |
|
95 | pytest.raises(formencode.Invalid, validator.to_python, 'test') | |
97 | pytest.raises(formencode.Invalid, validator.to_python, 'TesT') |
|
96 | pytest.raises(formencode.Invalid, validator.to_python, 'TesT') | |
98 | pytest.raises(formencode.Invalid, validator.to_python, 'TEST') |
|
97 | pytest.raises(formencode.Invalid, validator.to_python, 'TEST') | |
99 | UserGroupModel().delete(gr) |
|
98 | UserGroupModel().delete(gr) | |
100 | UserGroupModel().delete(gr2) |
|
99 | UserGroupModel().delete(gr2) | |
101 | Session().commit() |
|
100 | Session().commit() | |
102 |
|
101 | |||
103 |
|
102 | |||
104 | @pytest.fixture(scope='function') |
|
103 | @pytest.fixture(scope='function') | |
105 | def repo_group(request): |
|
104 | def repo_group(request): | |
106 | model = RepoGroupModel() |
|
105 | model = RepoGroupModel() | |
107 | gr = model.create( |
|
106 | gr = model.create( | |
108 | group_name='test_gr', group_description='desc', just_db=True, |
|
107 | group_name='test_gr', group_description='desc', just_db=True, | |
109 | owner=TEST_USER_ADMIN_LOGIN) |
|
108 | owner=TEST_USER_ADMIN_LOGIN) | |
110 |
|
109 | |||
111 | def cleanup(): |
|
110 | def cleanup(): | |
112 | model.delete(gr) |
|
111 | model.delete(gr) | |
113 |
|
112 | |||
114 | request.addfinalizer(cleanup) |
|
113 | request.addfinalizer(cleanup) | |
115 |
|
114 | |||
116 | return gr |
|
115 | return gr | |
117 |
|
116 | |||
118 |
|
117 | |||
119 | def test_ValidRepoGroup_same_name_as_repo(localizer): |
|
118 | def test_ValidRepoGroup_same_name_as_repo(localizer): | |
120 | validator = v.ValidRepoGroup(localizer) |
|
119 | validator = v.ValidRepoGroup(localizer) | |
121 | with pytest.raises(formencode.Invalid) as excinfo: |
|
120 | with pytest.raises(formencode.Invalid) as excinfo: | |
122 | validator.to_python({'group_name': HG_REPO}) |
|
121 | validator.to_python({'group_name': HG_REPO}) | |
123 | expected_msg = 'Repository with name "vcs_test_hg" already exists' |
|
122 | expected_msg = 'Repository with name "vcs_test_hg" already exists' | |
124 | assert expected_msg in str(excinfo.value) |
|
123 | assert expected_msg in str(excinfo.value) | |
125 |
|
124 | |||
126 |
|
125 | |||
127 | def test_ValidRepoGroup_group_exists(localizer, repo_group): |
|
126 | def test_ValidRepoGroup_group_exists(localizer, repo_group): | |
128 | validator = v.ValidRepoGroup(localizer) |
|
127 | validator = v.ValidRepoGroup(localizer) | |
129 | with pytest.raises(formencode.Invalid) as excinfo: |
|
128 | with pytest.raises(formencode.Invalid) as excinfo: | |
130 | validator.to_python({'group_name': repo_group.group_name}) |
|
129 | validator.to_python({'group_name': repo_group.group_name}) | |
131 | expected_msg = 'Group "test_gr" already exists' |
|
130 | expected_msg = 'Group "test_gr" already exists' | |
132 | assert expected_msg in str(excinfo.value) |
|
131 | assert expected_msg in str(excinfo.value) | |
133 |
|
132 | |||
134 |
|
133 | |||
135 | def test_ValidRepoGroup_invalid_parent(localizer, repo_group): |
|
134 | def test_ValidRepoGroup_invalid_parent(localizer, repo_group): | |
136 | validator = v.ValidRepoGroup(localizer, edit=True, |
|
135 | validator = v.ValidRepoGroup(localizer, edit=True, | |
137 | old_data={'group_id': repo_group.group_id}) |
|
136 | old_data={'group_id': repo_group.group_id}) | |
138 | with pytest.raises(formencode.Invalid) as excinfo: |
|
137 | with pytest.raises(formencode.Invalid) as excinfo: | |
139 | validator.to_python({ |
|
138 | validator.to_python({ | |
140 | 'group_name': repo_group.group_name + 'n', |
|
139 | 'group_name': repo_group.group_name + 'n', | |
141 | 'group_parent_id': repo_group.group_id, |
|
140 | 'group_parent_id': repo_group.group_id, | |
142 | }) |
|
141 | }) | |
143 | expected_msg = 'Cannot assign this group as parent' |
|
142 | expected_msg = 'Cannot assign this group as parent' | |
144 | assert expected_msg in str(excinfo.value) |
|
143 | assert expected_msg in str(excinfo.value) | |
145 |
|
144 | |||
146 |
|
145 | |||
147 | def test_ValidRepoGroup_edit_group_no_root_permission(localizer, repo_group): |
|
146 | def test_ValidRepoGroup_edit_group_no_root_permission(localizer, repo_group): | |
148 | validator = v.ValidRepoGroup(localizer, |
|
147 | validator = v.ValidRepoGroup(localizer, | |
149 | edit=True, old_data={'group_id': repo_group.group_id}, |
|
148 | edit=True, old_data={'group_id': repo_group.group_id}, | |
150 | can_create_in_root=False) |
|
149 | can_create_in_root=False) | |
151 |
|
150 | |||
152 | # Cannot change parent |
|
151 | # Cannot change parent | |
153 | with pytest.raises(formencode.Invalid) as excinfo: |
|
152 | with pytest.raises(formencode.Invalid) as excinfo: | |
154 | validator.to_python({'group_parent_id': '25'}) |
|
153 | validator.to_python({'group_parent_id': '25'}) | |
155 | expected_msg = 'no permission to store repository group in root location' |
|
154 | expected_msg = 'no permission to store repository group in root location' | |
156 | assert expected_msg in str(excinfo.value) |
|
155 | assert expected_msg in str(excinfo.value) | |
157 |
|
156 | |||
158 | # Chaning all the other fields is allowed |
|
157 | # Chaning all the other fields is allowed | |
159 | validator.to_python({'group_name': 'foo', 'group_parent_id': '-1'}) |
|
158 | validator.to_python({'group_name': 'foo', 'group_parent_id': '-1'}) | |
160 | validator.to_python( |
|
159 | validator.to_python( | |
161 | {'user': TEST_USER_REGULAR2_LOGIN, 'group_parent_id': '-1'}) |
|
160 | {'user': TEST_USER_REGULAR2_LOGIN, 'group_parent_id': '-1'}) | |
162 | validator.to_python({'group_description': 'bar', 'group_parent_id': '-1'}) |
|
161 | validator.to_python({'group_description': 'bar', 'group_parent_id': '-1'}) | |
163 | validator.to_python({'enable_locking': 'true', 'group_parent_id': '-1'}) |
|
162 | validator.to_python({'enable_locking': 'true', 'group_parent_id': '-1'}) | |
164 |
|
163 | |||
165 |
|
164 | |||
166 | def test_ValidPassword(localizer): |
|
165 | def test_ValidPassword(localizer): | |
167 | validator = v.ValidPassword(localizer) |
|
166 | validator = v.ValidPassword(localizer) | |
168 | assert 'lol' == validator.to_python('lol') |
|
167 | assert 'lol' == validator.to_python('lol') | |
169 | assert None == validator.to_python(None) |
|
168 | assert None == validator.to_python(None) | |
170 | pytest.raises(formencode.Invalid, validator.to_python, 'Δ ΔΕΌΕΊ') |
|
169 | pytest.raises(formencode.Invalid, validator.to_python, 'Δ ΔΕΌΕΊ') | |
171 |
|
170 | |||
172 |
|
171 | |||
173 | def test_ValidPasswordsMatch(localizer): |
|
172 | def test_ValidPasswordsMatch(localizer): | |
174 | validator = v.ValidPasswordsMatch(localizer) |
|
173 | validator = v.ValidPasswordsMatch(localizer) | |
175 | pytest.raises( |
|
174 | pytest.raises( | |
176 | formencode.Invalid, |
|
175 | formencode.Invalid, | |
177 | validator.to_python, {'password': 'pass', |
|
176 | validator.to_python, {'password': 'pass', | |
178 | 'password_confirmation': 'pass2'}) |
|
177 | 'password_confirmation': 'pass2'}) | |
179 |
|
178 | |||
180 | pytest.raises( |
|
179 | pytest.raises( | |
181 | formencode.Invalid, |
|
180 | formencode.Invalid, | |
182 | validator.to_python, {'new_password': 'pass', |
|
181 | validator.to_python, {'new_password': 'pass', | |
183 | 'password_confirmation': 'pass2'}) |
|
182 | 'password_confirmation': 'pass2'}) | |
184 |
|
183 | |||
185 | assert {'new_password': 'pass', 'password_confirmation': 'pass'} == \ |
|
184 | assert {'new_password': 'pass', 'password_confirmation': 'pass'} == \ | |
186 | validator.to_python({'new_password': 'pass', |
|
185 | validator.to_python({'new_password': 'pass', | |
187 | 'password_confirmation': 'pass'}) |
|
186 | 'password_confirmation': 'pass'}) | |
188 |
|
187 | |||
189 | assert {'password': 'pass', 'password_confirmation': 'pass'} == \ |
|
188 | assert {'password': 'pass', 'password_confirmation': 'pass'} == \ | |
190 | validator.to_python({'password': 'pass', |
|
189 | validator.to_python({'password': 'pass', | |
191 | 'password_confirmation': 'pass'}) |
|
190 | 'password_confirmation': 'pass'}) | |
192 |
|
191 | |||
193 |
|
192 | |||
194 | def test_ValidAuth(localizer, config_stub): |
|
193 | def test_ValidAuth(localizer, config_stub): | |
195 | config_stub.testing_securitypolicy() |
|
194 | config_stub.testing_securitypolicy() | |
196 | config_stub.include('rhodecode.authentication') |
|
195 | config_stub.include('rhodecode.authentication') | |
197 |
|
196 | |||
198 | validator = v.ValidAuth(localizer) |
|
197 | validator = v.ValidAuth(localizer) | |
199 | valid_creds = { |
|
198 | valid_creds = { | |
200 | 'username': TEST_USER_REGULAR2_LOGIN, |
|
199 | 'username': TEST_USER_REGULAR2_LOGIN, | |
201 | 'password': TEST_USER_REGULAR2_PASS, |
|
200 | 'password': TEST_USER_REGULAR2_PASS, | |
202 | } |
|
201 | } | |
203 | invalid_creds = { |
|
202 | invalid_creds = { | |
204 | 'username': 'err', |
|
203 | 'username': 'err', | |
205 | 'password': 'err', |
|
204 | 'password': 'err', | |
206 | } |
|
205 | } | |
207 | assert valid_creds == validator.to_python(valid_creds) |
|
206 | assert valid_creds == validator.to_python(valid_creds) | |
208 | pytest.raises( |
|
207 | pytest.raises( | |
209 | formencode.Invalid, validator.to_python, invalid_creds) |
|
208 | formencode.Invalid, validator.to_python, invalid_creds) | |
210 |
|
209 | |||
211 |
|
210 | |||
212 | def test_ValidRepoName(localizer): |
|
211 | def test_ValidRepoName(localizer): | |
213 | validator = v.ValidRepoName(localizer) |
|
212 | validator = v.ValidRepoName(localizer) | |
214 |
|
213 | |||
215 | pytest.raises( |
|
214 | pytest.raises( | |
216 | formencode.Invalid, validator.to_python, {'repo_name': ''}) |
|
215 | formencode.Invalid, validator.to_python, {'repo_name': ''}) | |
217 |
|
216 | |||
218 | pytest.raises( |
|
217 | pytest.raises( | |
219 | formencode.Invalid, validator.to_python, {'repo_name': HG_REPO}) |
|
218 | formencode.Invalid, validator.to_python, {'repo_name': HG_REPO}) | |
220 |
|
219 | |||
221 | gr = RepoGroupModel().create(group_name='group_test', |
|
220 | gr = RepoGroupModel().create(group_name='group_test', | |
222 | group_description='desc', |
|
221 | group_description='desc', | |
223 | owner=TEST_USER_ADMIN_LOGIN) |
|
222 | owner=TEST_USER_ADMIN_LOGIN) | |
224 | pytest.raises( |
|
223 | pytest.raises( | |
225 | formencode.Invalid, validator.to_python, {'repo_name': gr.group_name}) |
|
224 | formencode.Invalid, validator.to_python, {'repo_name': gr.group_name}) | |
226 |
|
225 | |||
227 | #TODO: write an error case for that ie. create a repo withinh a group |
|
226 | #TODO: write an error case for that ie. create a repo withinh a group | |
228 | # pytest.raises(formencode.Invalid, |
|
227 | # pytest.raises(formencode.Invalid, | |
229 | # validator.to_python, {'repo_name': 'some', |
|
228 | # validator.to_python, {'repo_name': 'some', | |
230 | # 'repo_group': gr.group_id}) |
|
229 | # 'repo_group': gr.group_id}) | |
231 |
|
230 | |||
232 |
|
231 | |||
233 | def test_ValidForkName(localizer): |
|
232 | def test_ValidForkName(localizer): | |
234 | # this uses ValidRepoName validator |
|
233 | # this uses ValidRepoName validator | |
235 | assert True |
|
234 | assert True | |
236 |
|
235 | |||
237 | @pytest.mark.parametrize("name, expected", [ |
|
236 | @pytest.mark.parametrize("name, expected", [ | |
238 | ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'), |
|
237 | ('test', 'test'), ('lolz!', 'lolz'), (' aavv', 'aavv'), | |
239 | ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'), |
|
238 | ('ala ma kota', 'ala-ma-kota'), ('@nooo', 'nooo'), | |
240 | ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'), |
|
239 | ('$!haha lolz !', 'haha-lolz'), ('$$$$$', ''), ('{}OK!', 'OK'), | |
241 | ('/]re po', 're-po')]) |
|
240 | ('/]re po', 're-po')]) | |
242 | def test_SlugifyName(name, expected, localizer): |
|
241 | def test_SlugifyName(name, expected, localizer): | |
243 | validator = v.SlugifyName(localizer) |
|
242 | validator = v.SlugifyName(localizer) | |
244 | assert expected == validator.to_python(name) |
|
243 | assert expected == validator.to_python(name) | |
245 |
|
244 | |||
246 |
|
245 | |||
247 | def test_ValidForkType(localizer): |
|
246 | def test_ValidForkType(localizer): | |
248 | validator = v.ValidForkType(localizer, old_data={'repo_type': 'hg'}) |
|
247 | validator = v.ValidForkType(localizer, old_data={'repo_type': 'hg'}) | |
249 | assert 'hg' == validator.to_python('hg') |
|
248 | assert 'hg' == validator.to_python('hg') | |
250 | pytest.raises(formencode.Invalid, validator.to_python, 'git') |
|
249 | pytest.raises(formencode.Invalid, validator.to_python, 'git') | |
251 |
|
250 | |||
252 |
|
251 | |||
253 | def test_ValidPath(localizer): |
|
252 | def test_ValidPath(localizer): | |
254 | validator = v.ValidPath(localizer) |
|
253 | validator = v.ValidPath(localizer) | |
255 | assert TESTS_TMP_PATH == validator.to_python(TESTS_TMP_PATH) |
|
254 | assert TESTS_TMP_PATH == validator.to_python(TESTS_TMP_PATH) | |
256 | pytest.raises( |
|
255 | pytest.raises( | |
257 | formencode.Invalid, validator.to_python, '/no_such_dir') |
|
256 | formencode.Invalid, validator.to_python, '/no_such_dir') | |
258 |
|
257 | |||
259 |
|
258 | |||
260 | def test_UniqSystemEmail(localizer): |
|
259 | def test_UniqSystemEmail(localizer): | |
261 | validator = v.UniqSystemEmail(localizer, old_data={}) |
|
260 | validator = v.UniqSystemEmail(localizer, old_data={}) | |
262 |
|
261 | |||
263 | assert 'mail@python.org' == validator.to_python('MaiL@Python.org') |
|
262 | assert 'mail@python.org' == validator.to_python('MaiL@Python.org') | |
264 |
|
263 | |||
265 | email = TEST_USER_REGULAR2_EMAIL |
|
264 | email = TEST_USER_REGULAR2_EMAIL | |
266 | pytest.raises(formencode.Invalid, validator.to_python, email) |
|
265 | pytest.raises(formencode.Invalid, validator.to_python, email) | |
267 |
|
266 | |||
268 |
|
267 | |||
269 | def test_ValidSystemEmail(localizer): |
|
268 | def test_ValidSystemEmail(localizer): | |
270 | validator = v.ValidSystemEmail(localizer) |
|
269 | validator = v.ValidSystemEmail(localizer) | |
271 | email = TEST_USER_REGULAR2_EMAIL |
|
270 | email = TEST_USER_REGULAR2_EMAIL | |
272 |
|
271 | |||
273 | assert email == validator.to_python(email) |
|
272 | assert email == validator.to_python(email) | |
274 | pytest.raises(formencode.Invalid, validator.to_python, 'err') |
|
273 | pytest.raises(formencode.Invalid, validator.to_python, 'err') | |
275 |
|
274 | |||
276 |
|
275 | |||
277 | def test_NotReviewedRevisions(localizer): |
|
276 | def test_NotReviewedRevisions(localizer): | |
278 | repo_id = Repository.get_by_repo_name(HG_REPO).repo_id |
|
277 | repo_id = Repository.get_by_repo_name(HG_REPO).repo_id | |
279 | validator = v.NotReviewedRevisions(localizer, repo_id) |
|
278 | validator = v.NotReviewedRevisions(localizer, repo_id) | |
280 | rev = '0' * 40 |
|
279 | rev = '0' * 40 | |
281 | # add status for a rev, that should throw an error because it is already |
|
280 | # add status for a rev, that should throw an error because it is already | |
282 | # reviewed |
|
281 | # reviewed | |
283 | new_status = ChangesetStatus() |
|
282 | new_status = ChangesetStatus() | |
284 | new_status.author = ChangesetStatusModel()._get_user(TEST_USER_ADMIN_LOGIN) |
|
283 | new_status.author = ChangesetStatusModel()._get_user(TEST_USER_ADMIN_LOGIN) | |
285 | new_status.repo = ChangesetStatusModel()._get_repo(HG_REPO) |
|
284 | new_status.repo = ChangesetStatusModel()._get_repo(HG_REPO) | |
286 | new_status.status = ChangesetStatus.STATUS_APPROVED |
|
285 | new_status.status = ChangesetStatus.STATUS_APPROVED | |
287 | new_status.comment = None |
|
286 | new_status.comment = None | |
288 | new_status.revision = rev |
|
287 | new_status.revision = rev | |
289 | Session().add(new_status) |
|
288 | Session().add(new_status) | |
290 | Session().commit() |
|
289 | Session().commit() | |
291 | try: |
|
290 | try: | |
292 | pytest.raises(formencode.Invalid, validator.to_python, [rev]) |
|
291 | pytest.raises(formencode.Invalid, validator.to_python, [rev]) | |
293 | finally: |
|
292 | finally: | |
294 | Session().delete(new_status) |
|
293 | Session().delete(new_status) | |
295 | Session().commit() |
|
294 | Session().commit() |
General Comments 0
You need to be logged in to leave comments.
Login now