# HG changeset patch # User Milka Kuzminski # Date 2020-12-26 22:08:12 # Node ID 0e8f3a202204a6be7cbc15f2d3914bed7d1bc785 # Parent 4d6339936fcc6d73c0f06481141dd9b08b1d7902 tests: use common test route generator. diff --git a/rhodecode/apps/my_account/tests/test_my_account_auth_tokens.py b/rhodecode/apps/my_account/tests/test_my_account_auth_tokens.py --- a/rhodecode/apps/my_account/tests/test_my_account_auth_tokens.py +++ b/rhodecode/apps/my_account/tests/test_my_account_auth_tokens.py @@ -23,23 +23,23 @@ import pytest from rhodecode.apps._base import ADMIN_PREFIX from rhodecode.model.db import User from rhodecode.tests import ( - TestController, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, - TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, assert_session_flash) + TestController, route_path_generator, assert_session_flash) from rhodecode.tests.fixture import Fixture from rhodecode.tests.utils import AssertResponse fixture = Fixture() -def route_path(name, **kwargs): - return { +def route_path(name, params=None, **kwargs): + url_defs = { 'my_account_auth_tokens': ADMIN_PREFIX + '/my_account/auth_tokens', 'my_account_auth_tokens_add': ADMIN_PREFIX + '/my_account/auth_tokens/new', 'my_account_auth_tokens_delete': ADMIN_PREFIX + '/my_account/auth_tokens/delete', - }[name].format(**kwargs) + } + return route_path_generator(url_defs, name=name, params=params, **kwargs) class TestMyAccountAuthTokens(TestController): diff --git a/rhodecode/apps/search/tests/test_search.py b/rhodecode/apps/search/tests/test_search.py --- a/rhodecode/apps/search/tests/test_search.py +++ b/rhodecode/apps/search/tests/test_search.py @@ -25,20 +25,20 @@ import pytest from whoosh import query from rhodecode.tests import ( - TestController, HG_REPO, + TestController, route_path_generator, HG_REPO, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) from rhodecode.tests.utils import AssertResponse -def route_path(name, **kwargs): +def route_path(name, params=None, **kwargs): from rhodecode.apps._base import ADMIN_PREFIX - return { + url_defs = { 'search': ADMIN_PREFIX + '/search', 'search_repo': '/{repo_name}/search', - - }[name].format(**kwargs) + } + return route_path_generator(url_defs, name=name, params=params, **kwargs) class TestSearchController(TestController): diff --git a/rhodecode/tests/__init__.py b/rhodecode/tests/__init__.py --- a/rhodecode/tests/__init__.py +++ b/rhodecode/tests/__init__.py @@ -33,15 +33,15 @@ import pytest from rhodecode.model.db import User from rhodecode.lib import auth from rhodecode.lib import helpers as h -from rhodecode.lib.helpers import flash, link_to +from rhodecode.lib.helpers import flash from rhodecode.lib.utils2 import safe_str log = logging.getLogger(__name__) __all__ = [ - 'get_new_dir', 'TestController', - 'link_to', 'clear_cache_regions', + 'get_new_dir', 'TestController', 'route_path_generator', + 'clear_cache_regions', 'assert_session_flash', 'login_user', 'no_newline_id_generator', 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'SVN_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', @@ -243,3 +243,13 @@ def no_newline_id_generator(test_name): .replace(' ', '_S') return test_name or 'test-with-empty-name' + + +def route_path_generator(url_defs, name, params=None, **kwargs): + import urllib + + base_url = url_defs[name].format(**kwargs) + + if params: + base_url = '{}?{}'.format(base_url, urllib.urlencode(params)) + return base_url