Changeset - 6a9e5841cc51
[Not reviewed]
default
0 11 0
Mads Kiilerich - 5 years ago 2020-10-29 11:28:36
mads@kiilerich.com
Grafted from: 00f7d546094b
lib: consistently import helpers the same way

Make it easier to grep for any remaining potential layering-violating use of
helpers.
11 files changed with 27 insertions and 37 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/repo_groups.py
Show inline comments
 
@@ -36,7 +36,7 @@ from tg.i18n import ugettext as _
 
from tg.i18n import ungettext
 
from webob.exc import HTTPForbidden, HTTPFound, HTTPInternalServerError, HTTPNotFound
 

	
 
from kallithea.lib import helpers as h
 
import kallithea.lib.helpers as h
 
from kallithea.lib import webutils
 
from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoGroupPermissionLevelDecorator, LoginRequired
 
from kallithea.lib.base import BaseController, render
kallithea/controllers/admin/user_groups.py
Show inline comments
 
@@ -37,7 +37,7 @@ from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 
from webob.exc import HTTPFound, HTTPInternalServerError
 

	
 
from kallithea.lib import helpers as h
 
import kallithea.lib.helpers as h
 
from kallithea.lib import webutils
 
from kallithea.lib.auth import HasPermissionAnyDecorator, HasUserGroupPermissionLevelDecorator, LoginRequired
 
from kallithea.lib.base import BaseController, render
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -37,9 +37,8 @@ from tg.i18n import ugettext as _
 
from webob.exc import HTTPFound, HTTPNotFound
 

	
 
import kallithea
 
from kallithea.lib import auth_modules
 
from kallithea.lib import helpers as h
 
from kallithea.lib import webutils
 
import kallithea.lib.helpers as h
 
from kallithea.lib import auth_modules, webutils
 
from kallithea.lib.auth import AuthUser, HasPermissionAnyDecorator, LoginRequired
 
from kallithea.lib.base import BaseController, IfSshEnabled, render
 
from kallithea.lib.exceptions import DefaultUserException, UserCreationError, UserOwnsReposException
kallithea/controllers/compare.py
Show inline comments
 
@@ -34,9 +34,8 @@ from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 
from webob.exc import HTTPBadRequest, HTTPFound, HTTPNotFound
 

	
 
from kallithea.lib import diffs
 
from kallithea.lib import helpers as h
 
from kallithea.lib import webutils
 
import kallithea.lib.helpers as h
 
from kallithea.lib import diffs, webutils
 
from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
 
from kallithea.lib.base import BaseRepoController, render
 
from kallithea.lib.graphmod import graph_data
kallithea/controllers/feed.py
Show inline comments
 
@@ -34,9 +34,8 @@ from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 

	
 
import kallithea
 
from kallithea.lib import feeds
 
from kallithea.lib import helpers as h
 
from kallithea.lib import webutils
 
import kallithea.lib.helpers as h
 
from kallithea.lib import feeds, webutils
 
from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
 
from kallithea.lib.base import BaseRepoController
 
from kallithea.lib.diffs import DiffProcessor
kallithea/controllers/files.py
Show inline comments
 
@@ -39,9 +39,8 @@ from tg.i18n import ugettext as _
 
from webob.exc import HTTPFound, HTTPNotFound
 

	
 
import kallithea
 
from kallithea.lib import diffs
 
from kallithea.lib import helpers as h
 
from kallithea.lib import webutils
 
import kallithea.lib.helpers as h
 
from kallithea.lib import diffs, webutils
 
from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
 
from kallithea.lib.base import BaseRepoController, jsonify, render
 
from kallithea.lib.exceptions import NonRelativePathError
kallithea/controllers/home.py
Show inline comments
 
@@ -34,7 +34,7 @@ from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 
from webob.exc import HTTPBadRequest
 

	
 
from kallithea.lib import helpers as h
 
import kallithea.lib.helpers as h
 
from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
 
from kallithea.lib.base import BaseController, jsonify, render
 
from kallithea.lib.utils2 import safe_str
kallithea/lib/celerylib/tasks.py
Show inline comments
 
@@ -41,8 +41,8 @@ import celery.utils.log
 
from tg import config
 

	
 
import kallithea
 
import kallithea.lib.helpers as h
 
from kallithea.lib import celerylib, conf, ext_json
 
from kallithea.lib.helpers import person
 
from kallithea.lib.hooks import log_create_repository
 
from kallithea.lib.indexers.daemon import WhooshIndexingDaemon
 
from kallithea.lib.utils import action_logger
 
@@ -72,7 +72,7 @@ def whoosh_index(repo_location, full_ind
 

	
 
# for js data compatibility cleans the key for person from '
 
def akc(k):
 
    return person(k).replace('"', '')
 
    return h.person(k).replace('"', '')
 

	
 

	
 
@celerylib.task
kallithea/tests/functional/test_files.py
Show inline comments
 
@@ -3,6 +3,7 @@ import json
 
import mimetypes
 
import posixpath
 

	
 
import kallithea.lib.helpers
 
from kallithea.model import db, meta
 
from kallithea.tests import base
 
from kallithea.tests.fixture import Fixture
 
@@ -95,7 +96,6 @@ class TestFilesController(base.TestContr
 
    def test_file_source(self):
 
        # Force the global cache to be populated now when we know the right .ini has been loaded.
 
        # (Without this, the test would fail.)
 
        import kallithea.lib.helpers
 
        kallithea.lib.helpers._urlify_issues_f = None
 
        self.log_user()
 
        response = self.app.get(base.url(controller='files', action='index',
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -6,7 +6,7 @@ from tg.util.webtest import test_context
 

	
 
import kallithea.lib.celerylib
 
import kallithea.lib.celerylib.tasks
 
from kallithea.lib import helpers as h
 
import kallithea.lib.helpers as h
 
from kallithea.model import db, meta
 
from kallithea.model.notification import EmailNotificationModel, NotificationModel
 
from kallithea.model.user import UserModel
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -31,6 +31,7 @@ import hashlib
 
import mock
 
from tg.util.webtest import test_context
 

	
 
import kallithea.lib.helpers as h
 
from kallithea.lib import webutils
 
from kallithea.lib.utils2 import AttributeDict, safe_bytes
 
from kallithea.model import db
 
@@ -198,8 +199,7 @@ class TestLibs(base.TestController):
 
            "[requires => url] [lang => python] [just a tag]"
 
            "[,d] [ => ULR ] [obsolete] [desc]]"
 
        )
 
        from kallithea.lib.helpers import urlify_text
 
        res = urlify_text(sample, stylize=True)
 
        res = h.urlify_text(sample, stylize=True)
 
        assert '<div class="label label-meta" data-tag="tag">tag</div>' in res
 
        assert '<div class="label label-meta" data-tag="obsolete">obsolete</div>' in res
 
        assert '<div class="label label-meta" data-tag="stale">stale</div>' in res
 
@@ -208,7 +208,6 @@ class TestLibs(base.TestController):
 
        assert '<div class="label label-meta" data-tag="tag">tag</div>' in res
 

	
 
    def test_alternative_gravatar(self):
 
        from kallithea.lib.helpers import gravatar_url
 
        _md5 = lambda s: hashlib.md5(safe_bytes(s)).hexdigest()
 

	
 
        # mock tg.tmpl_context
 
@@ -225,30 +224,30 @@ class TestLibs(base.TestController):
 
            with mock.patch('tg.tmpl_context', fake):
 
                    from kallithea.lib.webutils import url
 
                    assert url.current() == 'https://example.com'
 
                    grav = gravatar_url(email_address='test@example.com', size=24)
 
                    grav = h.gravatar_url(email_address='test@example.com', size=24)
 
                    assert grav == 'http://example.com/test@example.com'
 

	
 
            fake = fake_tmpl_context(_url='http://example.com/{email}')
 
            with mock.patch('tg.tmpl_context', fake):
 
                grav = gravatar_url(email_address='test@example.com', size=24)
 
                grav = h.gravatar_url(email_address='test@example.com', size=24)
 
                assert grav == 'http://example.com/test@example.com'
 

	
 
            fake = fake_tmpl_context(_url='http://example.com/{md5email}')
 
            with mock.patch('tg.tmpl_context', fake):
 
                em = 'test@example.com'
 
                grav = gravatar_url(email_address=em, size=24)
 
                grav = h.gravatar_url(email_address=em, size=24)
 
                assert grav == 'http://example.com/%s' % (_md5(em))
 

	
 
            fake = fake_tmpl_context(_url='http://example.com/{md5email}/{size}')
 
            with mock.patch('tg.tmpl_context', fake):
 
                em = 'test@example.com'
 
                grav = gravatar_url(email_address=em, size=24)
 
                grav = h.gravatar_url(email_address=em, size=24)
 
                assert grav == 'http://example.com/%s/%s' % (_md5(em), 24)
 

	
 
            fake = fake_tmpl_context(_url='{scheme}://{netloc}/{md5email}/{size}')
 
            with mock.patch('tg.tmpl_context', fake):
 
                em = 'test@example.com'
 
                grav = gravatar_url(email_address=em, size=24)
 
                grav = h.gravatar_url(email_address=em, size=24)
 
                assert grav == 'https://example.com/%s/%s' % (_md5(em), 24)
 

	
 
    @base.parametrize('clone_uri_tmpl,repo_name,username,prefix,expected', [
 
@@ -322,8 +321,7 @@ class TestLibs(base.TestController):
 
        with mock.patch('kallithea.lib.webutils.UrlGenerator.__call__',
 
            lambda self, name, **kwargs: dict(changeset_home='/%(repo_name)s/changeset/%(revision)s')[name] % kwargs,
 
        ):
 
            from kallithea.lib.helpers import urlify_text
 
            assert urlify_text(sample, 'repo_name') == expected
 
            assert h.urlify_text(sample, 'repo_name') == expected
 

	
 
    @base.parametrize('sample,expected,url_', [
 
      ("",
 
@@ -378,8 +376,7 @@ class TestLibs(base.TestController):
 
        with mock.patch('kallithea.lib.webutils.UrlGenerator.__call__',
 
            lambda self, name, **kwargs: dict(changeset_home='/%(repo_name)s/changeset/%(revision)s')[name] % kwargs,
 
        ):
 
            from kallithea.lib.helpers import urlify_text
 
            assert urlify_text(sample, 'repo_name', stylize=True) == expected
 
            assert h.urlify_text(sample, 'repo_name', stylize=True) == expected
 

	
 
    @base.parametrize('sample,expected', [
 
      ("deadbeefcafe @mention, and http://foo.bar/ yo",
 
@@ -392,8 +389,7 @@ class TestLibs(base.TestController):
 
        with mock.patch('kallithea.lib.webutils.UrlGenerator.__call__',
 
            lambda self, name, **kwargs: dict(changeset_home='/%(repo_name)s/changeset/%(revision)s')[name] % kwargs,
 
        ):
 
            from kallithea.lib.helpers import urlify_text
 
            assert urlify_text(sample, 'repo_name', link_='#the-link') == expected
 
            assert h.urlify_text(sample, 'repo_name', link_='#the-link') == expected
 

	
 
    @base.parametrize('issue_pat,issue_server,issue_sub,sample,expected', [
 
        (r'#(\d+)', 'http://foo/{repo}/issue/\\1', '#\\1',
 
@@ -474,7 +470,6 @@ class TestLibs(base.TestController):
 
            """<a class="issue-tracker-link" href="http://foo/BRU/pullrequest/747/">PR-BRU-747</a>"""),
 
    ])
 
    def test_urlify_issues(self, issue_pat, issue_server, issue_sub, sample, expected):
 
        from kallithea.lib.helpers import urlify_text
 
        config_stub = {
 
            'sqlalchemy.url': 'foo',
 
            'issue_pat': issue_pat,
 
@@ -484,7 +479,7 @@ class TestLibs(base.TestController):
 
        # force recreation of lazy function
 
        with mock.patch('kallithea.lib.helpers._urlify_issues_f', None):
 
            with mock.patch('kallithea.CONFIG', config_stub):
 
                assert urlify_text(sample, 'repo_name') == expected
 
                assert h.urlify_text(sample, 'repo_name') == expected
 

	
 
    @base.parametrize('sample,expected', [
 
        ('abc X5', 'abc <a class="issue-tracker-link" href="http://main/repo_name/main/5/">#5</a>'),
 
@@ -496,7 +491,6 @@ class TestLibs(base.TestController):
 
        ('issue FAILMORE89', 'issue FAILMORE89'), # no match because absent prefix
 
    ])
 
    def test_urlify_issues_multiple_issue_patterns(self, sample, expected):
 
        from kallithea.lib.helpers import urlify_text
 
        config_stub = {
 
            'sqlalchemy.url': r'foo',
 
            'issue_pat': r'X(\d+)',
 
@@ -517,7 +511,7 @@ class TestLibs(base.TestController):
 
        # force recreation of lazy function
 
        with mock.patch('kallithea.lib.helpers._urlify_issues_f', None):
 
            with mock.patch('kallithea.CONFIG', config_stub):
 
                assert urlify_text(sample, 'repo_name') == expected
 
                assert h.urlify_text(sample, 'repo_name') == expected
 

	
 
    @base.parametrize('test,expected', [
 
      ("", None),
0 comments (0 inline, 0 general)