##// END OF EJS Templates
core: avoid using rhodecode.test packages inside main packages as tests are removed during build which can cause some problems in some edge case calls
super-admin -
r5618:bdbdb63f default
parent child Browse files
Show More
@@ -0,0 +1,41 b''
1 # Copyright (C) 2010-2024 RhodeCode GmbH
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU Affero General Public License, version 3
5 # (only), as published by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU Affero General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 #
15 # This program is dual-licensed. If you wish to learn more about the
16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18
19 # bootstrap data available for tests and setup clean install
20
21 TEST_USER_ADMIN_LOGIN = 'test_admin'
22 TEST_USER_ADMIN_PASS = 'test12'
23 TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com'
24
25 TEST_USER_REGULAR_LOGIN = 'test_regular'
26 TEST_USER_REGULAR_PASS = 'test12'
27 TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com'
28
29 TEST_USER_REGULAR2_LOGIN = 'test_regular2'
30 TEST_USER_REGULAR2_PASS = 'test12'
31 TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com'
32
33 HG_REPO = 'vcs_test_hg'
34 GIT_REPO = 'vcs_test_git'
35 SVN_REPO = 'vcs_test_svn'
36
37 NEW_HG_REPO = 'vcs_test_hg_new'
38 NEW_GIT_REPO = 'vcs_test_git_new'
39
40 HG_FORK = 'vcs_test_hg_fork'
41 GIT_FORK = 'vcs_test_git_fork'
@@ -21,12 +21,12 b' import pytest'
21 from rhodecode.model.meta import Session
21 from rhodecode.model.meta import Session
22 from rhodecode.model.user import UserModel
22 from rhodecode.model.user import UserModel
23 from rhodecode.model.auth_token import AuthTokenModel
23 from rhodecode.model.auth_token import AuthTokenModel
24 from rhodecode.tests import TEST_USER_ADMIN_LOGIN
25
24
26
25
27 @pytest.fixture(scope="class")
26 @pytest.fixture(scope="class")
28 def testuser_api(request, baseapp):
27 def testuser_api(request, baseapp):
29 cls = request.cls
28 cls = request.cls
29 from rhodecode.tests import TEST_USER_ADMIN_LOGIN
30
30
31 # ADMIN USER
31 # ADMIN USER
32 cls.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
32 cls.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
@@ -213,6 +213,62 b' def rescan_repos(request, apiuser, remov'
213 'Error occurred during rescan repositories action'
213 'Error occurred during rescan repositories action'
214 )
214 )
215
215
216 @jsonrpc_method()
217 def cleanup_repos(request, apiuser, remove_obsolete=Optional(False)):
218 """
219 Triggers a rescan of the specified repositories.
220
221 * If the ``remove_obsolete`` option is set, it also deletes repositories
222 that are found in the database but not on the file system, so called
223 "clean zombies".
224
225 This command can only be run using an |authtoken| with admin rights to
226 the specified repository.
227
228 This command takes the following options:
229
230 :param apiuser: This is filled automatically from the |authtoken|.
231 :type apiuser: AuthUser
232 :param remove_obsolete: Deletes repositories from the database that
233 are not found on the filesystem.
234 :type remove_obsolete: Optional(``True`` | ``False``)
235
236 Example output:
237
238 .. code-block:: bash
239
240 id : <id_given_in_input>
241 result : {
242 'added': [<added repository name>,...]
243 'removed': [<removed repository name>,...]
244 }
245 error : null
246
247 Example error output:
248
249 .. code-block:: bash
250
251 id : <id_given_in_input>
252 result : null
253 error : {
254 'Error occurred during rescan repositories action'
255 }
256
257 """
258 if not has_superadmin_permission(apiuser):
259 raise JSONRPCForbidden()
260
261 try:
262 rm_obsolete = Optional.extract(remove_obsolete)
263 added, removed = repo2db_mapper(ScmModel().repo_scan(),
264 remove_obsolete=rm_obsolete, force_hooks_rebuild=True)
265 return {'added': added, 'removed': removed}
266 except Exception:
267 log.exception('Failed to run repo rescann')
268 raise JSONRPCError(
269 'Error occurred during rescan repositories action'
270 )
271
216
272
217 @jsonrpc_method()
273 @jsonrpc_method()
218 def cleanup_sessions(request, apiuser, older_then=Optional(60)):
274 def cleanup_sessions(request, apiuser, older_then=Optional(60)):
@@ -307,7 +307,7 b' class DbManage(object):'
307
307
308 def create_test_admin_and_users(self):
308 def create_test_admin_and_users(self):
309 log.info('creating admin and regular test users')
309 log.info('creating admin and regular test users')
310 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
310 from rhodecode.bootstrap import TEST_USER_ADMIN_LOGIN, \
311 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
311 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
312 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
312 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
313 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
313 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
@@ -33,49 +33,20 b' from rhodecode.lib import helpers as h'
33 from rhodecode.lib.helpers import flash
33 from rhodecode.lib.helpers import flash
34 from rhodecode.lib.str_utils import safe_str
34 from rhodecode.lib.str_utils import safe_str
35 from rhodecode.lib.hash_utils import sha1_safe
35 from rhodecode.lib.hash_utils import sha1_safe
36 from rhodecode.bootstrap import \
37 TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
38 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, TEST_USER_REGULAR_EMAIL, \
39 TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL,\
40 HG_REPO, GIT_REPO, SVN_REPO,\
41 NEW_HG_REPO, NEW_GIT_REPO,\
42 HG_FORK, GIT_FORK
36
43
37 log = logging.getLogger(__name__)
44 log = logging.getLogger(__name__)
38
45
39 __all__ = [
40 'get_new_dir', 'TestController', 'console_printer',
41 'clear_cache_regions',
42 'assert_session_flash', 'login_user', 'no_newline_id_generator',
43 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'SVN_REPO',
44 'NEW_HG_REPO', 'NEW_GIT_REPO',
45 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS',
46 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS',
47 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN',
48 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO',
49 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO',
50 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'SCM_TESTS',
51 ]
52
53
46
54 # SOME GLOBALS FOR TESTS
47 # SOME GLOBALS FOR TESTS
55 TEST_DIR = tempfile.gettempdir()
48 TEST_DIR = tempfile.gettempdir()
56
49
57 TEST_USER_ADMIN_LOGIN = 'test_admin'
58 TEST_USER_ADMIN_PASS = 'test12'
59 TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com'
60
61 TEST_USER_REGULAR_LOGIN = 'test_regular'
62 TEST_USER_REGULAR_PASS = 'test12'
63 TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com'
64
65 TEST_USER_REGULAR2_LOGIN = 'test_regular2'
66 TEST_USER_REGULAR2_PASS = 'test12'
67 TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com'
68
69 HG_REPO = 'vcs_test_hg'
70 GIT_REPO = 'vcs_test_git'
71 SVN_REPO = 'vcs_test_svn'
72
73 NEW_HG_REPO = 'vcs_test_hg_new'
74 NEW_GIT_REPO = 'vcs_test_git_new'
75
76 HG_FORK = 'vcs_test_hg_fork'
77 GIT_FORK = 'vcs_test_git_fork'
78
79 ## VCS
50 ## VCS
80 SCM_TESTS = ['hg', 'git']
51 SCM_TESTS = ['hg', 'git']
81 uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple())))
52 uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple())))
General Comments 0
You need to be logged in to leave comments. Login now