Show More
@@ -36,7 +36,7 b' from webob import Request, Response, exc' | |||
|
36 | 36 | |
|
37 | 37 | import kallithea |
|
38 | 38 | from kallithea.lib.utils2 import ascii_bytes |
|
39 | from kallithea.lib.vcs import subprocessio | |
|
39 | from kallithea.lib.vcs import get_repo, subprocessio | |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | log = logging.getLogger(__name__) |
@@ -170,8 +170,6 b' class GitRepository(object):' | |||
|
170 | 170 | if git_command in ['git-receive-pack']: |
|
171 | 171 | # updating refs manually after each push. |
|
172 | 172 | # Needed for pre-1.7.0.4 git clients using regular HTTP mode. |
|
173 | ||
|
174 | from kallithea.lib.vcs import get_repo | |
|
175 | 173 | repo = get_repo(self.content_path) |
|
176 | 174 | if repo: |
|
177 | 175 | update_server_info(repo._repo) |
@@ -35,6 +35,7 b' from tg import tmpl_context as c' | |||
|
35 | 35 | from tg.i18n import ugettext as _ |
|
36 | 36 | from webob.exc import HTTPFound |
|
37 | 37 | |
|
38 | import kallithea | |
|
38 | 39 | from kallithea.lib import webutils |
|
39 | 40 | from kallithea.lib.auth import HasPermissionAnyDecorator, LoginRequired |
|
40 | 41 | from kallithea.lib.base import BaseController, render |
@@ -309,7 +310,6 b' class SettingsController(BaseController)' | |||
|
309 | 310 | defaults = db.Setting.get_app_settings() |
|
310 | 311 | defaults.update(self._get_hg_ui_settings()) |
|
311 | 312 | |
|
312 | import kallithea | |
|
313 | 313 | c.ini = kallithea.CONFIG |
|
314 | 314 | |
|
315 | 315 | return htmlfill.render( |
@@ -399,7 +399,6 b' class SettingsController(BaseController)' | |||
|
399 | 399 | defaults = db.Setting.get_app_settings() |
|
400 | 400 | defaults.update(self._get_hg_ui_settings()) |
|
401 | 401 | |
|
402 | import kallithea | |
|
403 | 402 | c.ini = kallithea.CONFIG |
|
404 | 403 | server_info = db.Setting.get_server_info() |
|
405 | 404 | for key, val in server_info.items(): |
@@ -40,6 +40,7 b' from kallithea.lib import webutils' | |||
|
40 | 40 | from kallithea.lib.auth import AuthUser, HasPermissionAnyDecorator |
|
41 | 41 | from kallithea.lib.base import BaseController, log_in_user, render |
|
42 | 42 | from kallithea.lib.exceptions import UserCreationError |
|
43 | from kallithea.lib.recaptcha import submit | |
|
43 | 44 | from kallithea.lib.webutils import url |
|
44 | 45 | from kallithea.model import db, meta |
|
45 | 46 | from kallithea.model.forms import LoginForm, PasswordResetConfirmationForm, PasswordResetRequestForm, RegisterForm |
@@ -132,7 +133,6 b' class LoginController(BaseController):' | |||
|
132 | 133 | form_result['active'] = c.auto_active |
|
133 | 134 | |
|
134 | 135 | if c.captcha_active: |
|
135 | from kallithea.lib.recaptcha import submit | |
|
136 | 136 | response = submit(request.POST.get('g-recaptcha-response'), |
|
137 | 137 | private_key=captcha_private_key, |
|
138 | 138 | remoteip=request.ip_addr) |
@@ -177,7 +177,6 b' class LoginController(BaseController):' | |||
|
177 | 177 | try: |
|
178 | 178 | form_result = password_reset_form.to_python(dict(request.POST)) |
|
179 | 179 | if c.captcha_active: |
|
180 | from kallithea.lib.recaptcha import submit | |
|
181 | 180 | response = submit(request.POST.get('g-recaptcha-response'), |
|
182 | 181 | private_key=captcha_private_key, |
|
183 | 182 | remoteip=request.ip_addr) |
@@ -22,6 +22,7 b' refer to the routes manual at http://rou' | |||
|
22 | 22 | import routes |
|
23 | 23 | |
|
24 | 24 | import kallithea |
|
25 | from kallithea.lib.utils import is_valid_repo, is_valid_repo_group | |
|
25 | 26 | from kallithea.lib.utils2 import safe_str |
|
26 | 27 | |
|
27 | 28 | |
@@ -50,8 +51,6 b' def make_map(config):' | |||
|
50 | 51 | rmap.minimization = False |
|
51 | 52 | rmap.explicit = False |
|
52 | 53 | |
|
53 | from kallithea.lib.utils import is_valid_repo, is_valid_repo_group | |
|
54 | ||
|
55 | 54 | def check_repo(environ, match_dict): |
|
56 | 55 | """ |
|
57 | 56 | Check for valid repository for proper 404 handling. |
@@ -27,6 +27,7 b' import urllib.parse' | |||
|
27 | 27 | from beaker.cache import cache_region |
|
28 | 28 | from pygments import highlight as code_highlight |
|
29 | 29 | from pygments.formatters.html import HtmlFormatter |
|
30 | from tg import tmpl_context as c | |
|
30 | 31 | from tg.i18n import ugettext as _ |
|
31 | 32 | |
|
32 | 33 | import kallithea |
@@ -771,7 +772,6 b" def gravatar_div(email_address, cls='', " | |||
|
771 | 772 | and '_' changed to '-' and be used as attributes on the div. The default |
|
772 | 773 | class is 'gravatar'. |
|
773 | 774 | """ |
|
774 | from tg import tmpl_context as c | |
|
775 | 775 | if not c.visual.use_gravatar: |
|
776 | 776 | return '' |
|
777 | 777 | if 'div_class' not in div_attributes: |
@@ -793,7 +793,6 b" def gravatar(email_address, cls='', size" | |||
|
793 | 793 | empty then we fallback to using an icon. |
|
794 | 794 | |
|
795 | 795 | """ |
|
796 | from tg import tmpl_context as c | |
|
797 | 796 | if not c.visual.use_gravatar: |
|
798 | 797 | return '' |
|
799 | 798 | |
@@ -815,8 +814,6 b" def gravatar(email_address, cls='', size" | |||
|
815 | 814 | |
|
816 | 815 | |
|
817 | 816 | def gravatar_url(email_address, size=30, default=''): |
|
818 | from tg import tmpl_context as c | |
|
819 | ||
|
820 | 817 | if not c.visual.use_gravatar: |
|
821 | 818 | return "" |
|
822 | 819 |
@@ -30,6 +30,7 b' import sys' | |||
|
30 | 30 | import time |
|
31 | 31 | |
|
32 | 32 | import mercurial.scmutil |
|
33 | import paste.deploy | |
|
33 | 34 | |
|
34 | 35 | import kallithea |
|
35 | 36 | from kallithea.lib import webutils |
@@ -301,8 +302,6 b' def _hook_environment(repo_path):' | |||
|
301 | 302 | they thus need enough info to be able to create an app environment and |
|
302 | 303 | connect to the database. |
|
303 | 304 | """ |
|
304 | import paste.deploy | |
|
305 | ||
|
306 | 305 | import kallithea.config.application |
|
307 | 306 | |
|
308 | 307 | extras = get_hook_environment() |
@@ -39,6 +39,7 b' import urlobject' | |||
|
39 | 39 | from dateutil import relativedelta |
|
40 | 40 | from sqlalchemy.engine import url as sa_url |
|
41 | 41 | from sqlalchemy.exc import ArgumentError |
|
42 | from tg import tmpl_context | |
|
42 | 43 | from tg.i18n import ugettext as _ |
|
43 | 44 | from tg.i18n import ungettext |
|
44 | 45 | from tg.support.converters import asbool, aslist |
@@ -491,7 +492,6 b' def get_current_authuser():' | |||
|
491 | 492 | Gets kallithea user from threadlocal tmpl_context variable if it's |
|
492 | 493 | defined, else returns None. |
|
493 | 494 | """ |
|
494 | from tg import tmpl_context | |
|
495 | 495 | try: |
|
496 | 496 | return getattr(tmpl_context, 'authuser', None) |
|
497 | 497 | except TypeError: # No object (name: context) has been registered for this thread |
@@ -9,6 +9,8 b' from kallithea.lib.vcs.backends.base imp' | |||
|
9 | 9 | from kallithea.lib.vcs.exceptions import RepositoryError |
|
10 | 10 | from kallithea.lib.vcs.utils import ascii_str, safe_bytes |
|
11 | 11 | |
|
12 | from . import repository | |
|
13 | ||
|
12 | 14 | |
|
13 | 15 | class GitInMemoryChangeset(BaseInMemoryChangeset): |
|
14 | 16 | |
@@ -32,9 +34,8 b' class GitInMemoryChangeset(BaseInMemoryC' | |||
|
32 | 34 | """ |
|
33 | 35 | self.check_integrity(parents) |
|
34 | 36 | |
|
35 | from .repository import GitRepository | |
|
36 | 37 | if branch is None: |
|
37 | branch = GitRepository.DEFAULT_BRANCH_NAME | |
|
38 | branch = repository.GitRepository.DEFAULT_BRANCH_NAME | |
|
38 | 39 | |
|
39 | 40 | repo = self.repository._repo |
|
40 | 41 | object_store = repo.object_store |
@@ -36,9 +36,7 b' from kallithea.lib.vcs.utils.helpers imp' | |||
|
36 | 36 | from kallithea.lib.vcs.utils.lazy import LazyProperty |
|
37 | 37 | from kallithea.lib.vcs.utils.paths import abspath, get_user_home |
|
38 | 38 | |
|
39 | from .changeset import GitChangeset | |
|
40 | from .inmemory import GitInMemoryChangeset | |
|
41 | from .workdir import GitWorkdir | |
|
39 | from . import changeset, inmemory, workdir | |
|
42 | 40 | |
|
43 | 41 | |
|
44 | 42 | SHA_PATTERN = re.compile(r'^([0-9a-fA-F]{12}|[0-9a-fA-F]{40})$') |
@@ -467,9 +465,9 b' class GitRepository(BaseRepository):' | |||
|
467 | 465 | Returns ``GitChangeset`` object representing commit from git repository |
|
468 | 466 | at the given revision or head (most recent commit) if None given. |
|
469 | 467 | """ |
|
470 | if isinstance(revision, GitChangeset): | |
|
468 | if isinstance(revision, changeset.GitChangeset): | |
|
471 | 469 | return revision |
|
472 | return GitChangeset(repository=self, revision=self._get_revision(revision)) | |
|
470 | return changeset.GitChangeset(repository=self, revision=self._get_revision(revision)) | |
|
473 | 471 | |
|
474 | 472 | def get_changesets(self, start=None, end=None, start_date=None, |
|
475 | 473 | end_date=None, branch_name=None, reverse=False, max_revisions=None): |
@@ -669,7 +667,7 b' class GitRepository(BaseRepository):' | |||
|
669 | 667 | """ |
|
670 | 668 | Returns ``GitInMemoryChangeset`` object for this repository. |
|
671 | 669 | """ |
|
672 | return GitInMemoryChangeset(self) | |
|
670 | return inmemory.GitInMemoryChangeset(self) | |
|
673 | 671 | |
|
674 | 672 | def clone(self, url, update_after_clone=True, bare=False): |
|
675 | 673 | """ |
@@ -728,7 +726,7 b' class GitRepository(BaseRepository):' | |||
|
728 | 726 | """ |
|
729 | 727 | Returns ``Workdir`` instance for this repository. |
|
730 | 728 | """ |
|
731 | return GitWorkdir(self) | |
|
729 | return workdir.GitWorkdir(self) | |
|
732 | 730 | |
|
733 | 731 | def get_config_value(self, section, name, config_file=None): |
|
734 | 732 | """ |
@@ -7,6 +7,8 b' from kallithea.lib.vcs.backends.base imp' | |||
|
7 | 7 | from kallithea.lib.vcs.exceptions import RepositoryError |
|
8 | 8 | from kallithea.lib.vcs.utils import ascii_str, safe_bytes, safe_str |
|
9 | 9 | |
|
10 | from . import repository | |
|
11 | ||
|
10 | 12 | |
|
11 | 13 | class MercurialInMemoryChangeset(BaseInMemoryChangeset): |
|
12 | 14 | |
@@ -35,9 +37,8 b' class MercurialInMemoryChangeset(BaseInM' | |||
|
35 | 37 | if not isinstance(author, str): |
|
36 | 38 | raise RepositoryError('author must be a str - got %r' % type(author)) |
|
37 | 39 | |
|
38 | from .repository import MercurialRepository | |
|
39 | 40 | if branch is None: |
|
40 | branch = MercurialRepository.DEFAULT_BRANCH_NAME | |
|
41 | branch = repository.MercurialRepository.DEFAULT_BRANCH_NAME | |
|
41 | 42 | kwargs[b'branch'] = safe_bytes(branch) |
|
42 | 43 | |
|
43 | 44 | def filectxfn(_repo, memctx, bytes_path): |
@@ -44,9 +44,7 b' from kallithea.lib.vcs.utils.helpers imp' | |||
|
44 | 44 | from kallithea.lib.vcs.utils.lazy import LazyProperty |
|
45 | 45 | from kallithea.lib.vcs.utils.paths import abspath |
|
46 | 46 | |
|
47 | from .changeset import MercurialChangeset | |
|
48 | from .inmemory import MercurialInMemoryChangeset | |
|
49 | from .workdir import MercurialWorkdir | |
|
47 | from . import changeset, inmemory, workdir | |
|
50 | 48 | |
|
51 | 49 | |
|
52 | 50 | log = logging.getLogger(__name__) |
@@ -380,7 +378,7 b' class MercurialRepository(BaseRepository' | |||
|
380 | 378 | |
|
381 | 379 | @LazyProperty |
|
382 | 380 | def in_memory_changeset(self): |
|
383 | return MercurialInMemoryChangeset(self) | |
|
381 | return inmemory.MercurialInMemoryChangeset(self) | |
|
384 | 382 | |
|
385 | 383 | @LazyProperty |
|
386 | 384 | def description(self): |
@@ -490,7 +488,7 b' class MercurialRepository(BaseRepository' | |||
|
490 | 488 | Returns ``MercurialChangeset`` object representing repository's |
|
491 | 489 | changeset at the given ``revision``. |
|
492 | 490 | """ |
|
493 | return MercurialChangeset(repository=self, revision=self._get_revision(revision)) | |
|
491 | return changeset.MercurialChangeset(repository=self, revision=self._get_revision(revision)) | |
|
494 | 492 | |
|
495 | 493 | def get_changesets(self, start=None, end=None, start_date=None, |
|
496 | 494 | end_date=None, branch_name=None, reverse=False, max_revisions=None): |
@@ -616,7 +614,7 b' class MercurialRepository(BaseRepository' | |||
|
616 | 614 | """ |
|
617 | 615 | Returns ``Workdir`` instance for this repository. |
|
618 | 616 | """ |
|
619 | return MercurialWorkdir(self) | |
|
617 | return workdir.MercurialWorkdir(self) | |
|
620 | 618 | |
|
621 | 619 | def get_config_value(self, section, name=None, config_file=None): |
|
622 | 620 | """ |
@@ -14,6 +14,7 b' from pygments import highlight' | |||
|
14 | 14 | from pygments.formatters import TerminalFormatter |
|
15 | 15 | from pygments.lexers import ClassNotFound, guess_lexer_for_filename |
|
16 | 16 | |
|
17 | from kallithea.lib.vcs import backends | |
|
17 | 18 | from kallithea.lib.vcs.exceptions import RepositoryError, VCSError |
|
18 | 19 | from kallithea.lib.vcs.utils import safe_str |
|
19 | 20 | from kallithea.lib.vcs.utils.paths import abspath |
@@ -71,7 +72,6 b' def get_scms_for_path(path):' | |||
|
71 | 72 | |
|
72 | 73 | :raises VCSError: if given ``path`` is not a directory |
|
73 | 74 | """ |
|
74 | from kallithea.lib.vcs.backends import get_backend | |
|
75 | 75 | if hasattr(path, '__call__'): |
|
76 | 76 | path = path() |
|
77 | 77 | if not os.path.isdir(path): |
@@ -91,7 +91,7 b' def get_scms_for_path(path):' | |||
|
91 | 91 | # We still need to check if it's not bare repository as |
|
92 | 92 | # bare repos don't have working directories |
|
93 | 93 | try: |
|
94 | get_backend(key)(path) | |
|
94 | backends.get_backend(key)(path) | |
|
95 | 95 | result.append(key) |
|
96 | 96 | continue |
|
97 | 97 | except RepositoryError: |
@@ -37,6 +37,7 b' import traceback' | |||
|
37 | 37 | |
|
38 | 38 | import ipaddr |
|
39 | 39 | import sqlalchemy |
|
40 | import urlobject | |
|
40 | 41 | from sqlalchemy import Boolean, Column, DateTime, Float, ForeignKey, Index, Integer, LargeBinary, String, Unicode, UnicodeText, UniqueConstraint |
|
41 | 42 | from sqlalchemy.ext.hybrid import hybrid_property |
|
42 | 43 | from sqlalchemy.orm import class_mapper, joinedload, relationship, validates |
@@ -48,7 +49,7 b' from kallithea.lib import ext_json, ssh,' | |||
|
48 | 49 | from kallithea.lib.exceptions import DefaultUserException |
|
49 | 50 | from kallithea.lib.utils2 import asbool, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, urlreadable |
|
50 | 51 | from kallithea.lib.vcs import get_backend, get_repo |
|
51 | from kallithea.lib.vcs.backends.base import EmptyChangeset | |
|
52 | from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset | |
|
52 | 53 | from kallithea.lib.vcs.utils import author_email, author_name |
|
53 | 54 | from kallithea.lib.vcs.utils.helpers import get_scm |
|
54 | 55 | from kallithea.model import meta |
@@ -1171,7 +1172,6 b' class Repository(meta.Base, BaseDbModel)' | |||
|
1171 | 1172 | def clone_uri_hidden(self): |
|
1172 | 1173 | clone_uri = self.clone_uri |
|
1173 | 1174 | if clone_uri: |
|
1174 | import urlobject | |
|
1175 | 1175 | url_obj = urlobject.URLObject(self.clone_uri) |
|
1176 | 1176 | if url_obj.password: |
|
1177 | 1177 | clone_uri = url_obj.with_password('*****') |
@@ -1226,7 +1226,6 b' class Repository(meta.Base, BaseDbModel)' | |||
|
1226 | 1226 | |
|
1227 | 1227 | :param cs_cache: |
|
1228 | 1228 | """ |
|
1229 | from kallithea.lib.vcs.backends.base import BaseChangeset | |
|
1230 | 1229 | if cs_cache is None: |
|
1231 | 1230 | cs_cache = EmptyChangeset() |
|
1232 | 1231 | # use no-cache version here |
@@ -39,7 +39,7 b' from tg.i18n import ugettext as _' | |||
|
39 | 39 | from kallithea.lib import webutils |
|
40 | 40 | from kallithea.lib.exceptions import DefaultUserException, UserOwnsReposException |
|
41 | 41 | from kallithea.lib.utils2 import generate_api_key, get_current_authuser |
|
42 | from kallithea.model import db, meta | |
|
42 | from kallithea.model import db, forms, meta | |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | log = logging.getLogger(__name__) |
@@ -451,7 +451,6 b' class UserModel(object):' | |||
|
451 | 451 | :param user: |
|
452 | 452 | :param email: |
|
453 | 453 | """ |
|
454 | from kallithea.model import forms | |
|
455 | 454 | form = forms.UserExtraEmailForm()() |
|
456 | 455 | data = form.to_python(dict(email=email)) |
|
457 | 456 | user = db.User.guess_instance(user) |
@@ -481,7 +480,6 b' class UserModel(object):' | |||
|
481 | 480 | :param user: |
|
482 | 481 | :param ip: |
|
483 | 482 | """ |
|
484 | from kallithea.model import forms | |
|
485 | 483 | form = forms.UserExtraIpForm()() |
|
486 | 484 | data = form.to_python(dict(ip=ip)) |
|
487 | 485 | user = db.User.guess_instance(user) |
@@ -28,7 +28,7 b' from sqlalchemy import func' | |||
|
28 | 28 | from tg.i18n import ugettext as _ |
|
29 | 29 | |
|
30 | 30 | import kallithea |
|
31 | from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel | |
|
31 | from kallithea.lib import auth | |
|
32 | 32 | from kallithea.lib.compat import OrderedSet |
|
33 | 33 | from kallithea.lib.exceptions import InvalidCloneUriException, LdapImportError |
|
34 | 34 | from kallithea.lib.utils import is_valid_repo_uri |
@@ -455,12 +455,12 b' def CanWriteGroup(old_data=None):' | |||
|
455 | 455 | gr_name = gr.group_name if gr is not None else None # None means ROOT location |
|
456 | 456 | |
|
457 | 457 | # create repositories with write permission on group is set to true |
|
458 | group_admin = HasRepoGroupPermissionLevel('admin')(gr_name, | |
|
458 | group_admin = auth.HasRepoGroupPermissionLevel('admin')(gr_name, | |
|
459 | 459 | 'can write into group validator') |
|
460 | group_write = HasRepoGroupPermissionLevel('write')(gr_name, | |
|
460 | group_write = auth.HasRepoGroupPermissionLevel('write')(gr_name, | |
|
461 | 461 | 'can write into group validator') |
|
462 | 462 | forbidden = not (group_admin or group_write) |
|
463 | can_create_repos = HasPermissionAny('hg.admin', 'hg.create.repository') | |
|
463 | can_create_repos = auth.HasPermissionAny('hg.admin', 'hg.create.repository') | |
|
464 | 464 | gid = (old_data['repo_group'].get('group_id') |
|
465 | 465 | if (old_data and 'repo_group' in old_data) else None) |
|
466 | 466 | value_changed = gid != value |
@@ -508,7 +508,7 b' def CanCreateGroup(can_create_in_root=Fa' | |||
|
508 | 508 | return |
|
509 | 509 | |
|
510 | 510 | forbidden_in_root = gr is None and not can_create_in_root |
|
511 | forbidden = not HasRepoGroupPermissionLevel('admin')(gr_name, 'can create group validator') | |
|
511 | forbidden = not auth.HasRepoGroupPermissionLevel('admin')(gr_name, 'can create group validator') | |
|
512 | 512 | if forbidden_in_root or forbidden: |
|
513 | 513 | msg = self.message('permission_denied', state) |
|
514 | 514 | raise formencode.Invalid(msg, value, state, |
@@ -19,6 +19,7 b' Tests for the JSON-RPC web api.' | |||
|
19 | 19 | import os |
|
20 | 20 | import random |
|
21 | 21 | import re |
|
22 | import string | |
|
22 | 23 | |
|
23 | 24 | import mock |
|
24 | 25 | import pytest |
@@ -177,7 +178,6 b' class _BaseTestApi(object):' | |||
|
177 | 178 | assert response.status == '200 OK' |
|
178 | 179 | |
|
179 | 180 | def test_api_args_different_args(self): |
|
180 | import string | |
|
181 | 181 | expected = { |
|
182 | 182 | 'ascii_letters': string.ascii_letters, |
|
183 | 183 | 'ws': string.whitespace, |
@@ -20,6 +20,7 b' import tempfile' | |||
|
20 | 20 | import time |
|
21 | 21 | |
|
22 | 22 | import pytest |
|
23 | from beaker.cache import cache_managers | |
|
23 | 24 | from webtest import TestApp |
|
24 | 25 | |
|
25 | 26 | from kallithea.lib.utils2 import ascii_str |
@@ -126,7 +127,6 b' def invalidate_all_caches():' | |||
|
126 | 127 | effect immediately. |
|
127 | 128 | Note: Any use of this function is probably a workaround - it should be |
|
128 | 129 | replaced with a more specific cache invalidation in code or test.""" |
|
129 | from beaker.cache import cache_managers | |
|
130 | 130 | for cache in cache_managers.values(): |
|
131 | 131 | cache.clear() |
|
132 | 132 |
@@ -19,6 +19,7 b' from kallithea.model import db, meta' | |||
|
19 | 19 | from kallithea.model.scm import ScmModel |
|
20 | 20 | from kallithea.model.user import UserModel |
|
21 | 21 | from kallithea.tests.base import TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_REGULAR_LOGIN, TESTS_TMP_PATH, invalidate_all_caches |
|
22 | from kallithea.tests.fixture import create_test_env, create_test_index | |
|
22 | 23 | |
|
23 | 24 | |
|
24 | 25 | def pytest_configure(): |
@@ -69,7 +70,6 b' def pytest_configure():' | |||
|
69 | 70 | inifile.create(test_ini_file, None, ini_settings) |
|
70 | 71 | |
|
71 | 72 | context = loadwsgi.loadcontext(loadwsgi.APP, 'config:%s' % test_ini_file) |
|
72 | from kallithea.tests.fixture import create_test_env, create_test_index | |
|
73 | 73 | |
|
74 | 74 | # set KALLITHEA_NO_TMP_PATH=1 to disable re-creating the database and test repos |
|
75 | 75 | if not int(os.environ.get('KALLITHEA_NO_TMP_PATH', 0)): |
@@ -27,6 +27,8 b' from tg.util.webtest import test_context' | |||
|
27 | 27 | |
|
28 | 28 | from kallithea.lib.auth import AuthUser |
|
29 | 29 | from kallithea.lib.db_manage import DbManage |
|
30 | from kallithea.lib.indexers.daemon import WhooshIndexingDaemon | |
|
31 | from kallithea.lib.pidlock import DaemonLock | |
|
30 | 32 | from kallithea.lib.vcs.backends.base import EmptyChangeset |
|
31 | 33 | from kallithea.model import db, meta |
|
32 | 34 | from kallithea.model.changeset_status import ChangesetStatusModel |
@@ -41,6 +43,7 b' from kallithea.model.user_group import U' | |||
|
41 | 43 | from kallithea.tests.base import (GIT_REPO, HG_REPO, IP_ADDR, TEST_USER_ADMIN_EMAIL, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_REGULAR2_EMAIL, |
|
42 | 44 | TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, |
|
43 | 45 | TESTS_TMP_PATH, invalidate_all_caches) |
|
46 | from kallithea.tests.vcs import setup_package | |
|
44 | 47 | |
|
45 | 48 | |
|
46 | 49 | log = logging.getLogger(__name__) |
@@ -404,7 +407,6 b' def create_test_env(repos_test_path, con' | |||
|
404 | 407 | tar.close() |
|
405 | 408 | |
|
406 | 409 | # LOAD VCS test stuff |
|
407 | from kallithea.tests.vcs import setup_package | |
|
408 | 410 | setup_package() |
|
409 | 411 | |
|
410 | 412 | |
@@ -413,9 +415,6 b' def create_test_index(repo_location, con' | |||
|
413 | 415 | Makes default test index |
|
414 | 416 | """ |
|
415 | 417 | |
|
416 | from kallithea.lib.indexers.daemon import WhooshIndexingDaemon | |
|
417 | from kallithea.lib.pidlock import DaemonLock | |
|
418 | ||
|
419 | 418 | index_location = os.path.join(config['index_dir']) |
|
420 | 419 | if not os.path.exists(index_location): |
|
421 | 420 | os.makedirs(index_location) |
@@ -3,7 +3,7 b'' | |||
|
3 | 3 | from tg.util.webtest import test_context |
|
4 | 4 | |
|
5 | 5 | from kallithea.lib import webutils |
|
6 | from kallithea.model import db, meta | |
|
6 | from kallithea.model import db, meta, validators | |
|
7 | 7 | from kallithea.model.user import UserModel |
|
8 | 8 | from kallithea.tests import base |
|
9 | 9 | from kallithea.tests.fixture import Fixture |
@@ -182,7 +182,6 b' class TestMyAccountController(base.TestC' | |||
|
182 | 182 | _session_csrf_secret_token=self.session_csrf_secret_token())) |
|
183 | 183 | |
|
184 | 184 | response.mustcontain('An email address must contain a single @') |
|
185 | from kallithea.model import validators | |
|
186 | 185 | with test_context(self.app): |
|
187 | 186 | msg = validators.ValidUsername(edit=False, old_data={}) \ |
|
188 | 187 | ._messages['username_exists'] |
@@ -27,13 +27,17 b' Original author and date, and relevant c' | |||
|
27 | 27 | |
|
28 | 28 | import datetime |
|
29 | 29 | import hashlib |
|
30 | import re | |
|
30 | 31 | |
|
31 | 32 | import mock |
|
33 | import routes | |
|
34 | from dateutil import relativedelta | |
|
35 | from tg import request | |
|
32 | 36 | from tg.util.webtest import test_context |
|
33 | 37 | |
|
34 | 38 | import kallithea.lib.helpers as h |
|
35 | 39 | from kallithea.lib import webutils |
|
36 | from kallithea.lib.utils2 import AttributeDict, safe_bytes | |
|
40 | from kallithea.lib.utils2 import AttributeDict, get_clone_url, safe_bytes | |
|
37 | 41 | from kallithea.model import db |
|
38 | 42 | from kallithea.tests import base |
|
39 | 43 | |
@@ -138,8 +142,6 b' class TestLibs(base.TestController):' | |||
|
138 | 142 | (dict(years= -3, months= -2), '3 years and 2 months ago'), |
|
139 | 143 | ]) |
|
140 | 144 | def test_age(self, age_args, expected): |
|
141 | from dateutil import relativedelta | |
|
142 | ||
|
143 | 145 | from kallithea.lib.utils2 import age |
|
144 | 146 | with test_context(self.app): |
|
145 | 147 | n = datetime.datetime(year=2012, month=5, day=17) |
@@ -164,8 +166,6 b' class TestLibs(base.TestController):' | |||
|
164 | 166 | (dict(years= -4, months= -8), '5 years ago'), |
|
165 | 167 | ]) |
|
166 | 168 | def test_age_short(self, age_args, expected): |
|
167 | from dateutil import relativedelta | |
|
168 | ||
|
169 | 169 | from kallithea.lib.utils2 import age |
|
170 | 170 | with test_context(self.app): |
|
171 | 171 | n = datetime.datetime(year=2012, month=5, day=17) |
@@ -184,8 +184,6 b' class TestLibs(base.TestController):' | |||
|
184 | 184 | (dict(years=1, months=1), 'in 1 year and 1 month') |
|
185 | 185 | ]) |
|
186 | 186 | def test_age_in_future(self, age_args, expected): |
|
187 | from dateutil import relativedelta | |
|
188 | ||
|
189 | 187 | from kallithea.lib.utils2 import age |
|
190 | 188 | with test_context(self.app): |
|
191 | 189 | n = datetime.datetime(year=2012, month=5, day=17) |
@@ -221,31 +219,30 b' class TestLibs(base.TestController):' | |||
|
221 | 219 | |
|
222 | 220 | with mock.patch('kallithea.lib.webutils.url.current', lambda *a, **b: 'https://example.com'): |
|
223 | 221 | fake = fake_tmpl_context(_url='http://example.com/{email}') |
|
224 |
with mock.patch(' |
|
|
225 | from kallithea.lib.webutils import url | |
|
226 | assert url.current() == 'https://example.com' | |
|
222 | with mock.patch('kallithea.lib.helpers.c', fake): | |
|
223 | assert webutils.url.current() == 'https://example.com' | |
|
227 | 224 | grav = h.gravatar_url(email_address='test@example.com', size=24) |
|
228 | 225 | assert grav == 'http://example.com/test@example.com' |
|
229 | 226 | |
|
230 | 227 | fake = fake_tmpl_context(_url='http://example.com/{email}') |
|
231 |
with mock.patch(' |
|
|
228 | with mock.patch('kallithea.lib.helpers.c', fake): | |
|
232 | 229 | grav = h.gravatar_url(email_address='test@example.com', size=24) |
|
233 | 230 | assert grav == 'http://example.com/test@example.com' |
|
234 | 231 | |
|
235 | 232 | fake = fake_tmpl_context(_url='http://example.com/{md5email}') |
|
236 |
with mock.patch(' |
|
|
233 | with mock.patch('kallithea.lib.helpers.c', fake): | |
|
237 | 234 | em = 'test@example.com' |
|
238 | 235 | grav = h.gravatar_url(email_address=em, size=24) |
|
239 | 236 | assert grav == 'http://example.com/%s' % (_md5(em)) |
|
240 | 237 | |
|
241 | 238 | fake = fake_tmpl_context(_url='http://example.com/{md5email}/{size}') |
|
242 |
with mock.patch(' |
|
|
239 | with mock.patch('kallithea.lib.helpers.c', fake): | |
|
243 | 240 | em = 'test@example.com' |
|
244 | 241 | grav = h.gravatar_url(email_address=em, size=24) |
|
245 | 242 | assert grav == 'http://example.com/%s/%s' % (_md5(em), 24) |
|
246 | 243 | |
|
247 | 244 | fake = fake_tmpl_context(_url='{scheme}://{netloc}/{md5email}/{size}') |
|
248 |
with mock.patch(' |
|
|
245 | with mock.patch('kallithea.lib.helpers.c', fake): | |
|
249 | 246 | em = 'test@example.com' |
|
250 | 247 | grav = h.gravatar_url(email_address=em, size=24) |
|
251 | 248 | assert grav == 'https://example.com/%s/%s' % (_md5(em), 24) |
@@ -267,7 +264,6 b' class TestLibs(base.TestController):' | |||
|
267 | 264 | ('https://proxy1.example.com/{user}/{repo}', 'group/repo1', 'username', '', 'https://proxy1.example.com/username/group/repo1'), |
|
268 | 265 | ]) |
|
269 | 266 | def test_clone_url_generator(self, clone_uri_tmpl, repo_name, username, prefix, expected): |
|
270 | from kallithea.lib.utils2 import get_clone_url | |
|
271 | 267 | clone_url = get_clone_url(clone_uri_tmpl=clone_uri_tmpl, prefix_url='http://vps1:8000' + prefix, |
|
272 | 268 | repo_name=repo_name, repo_id=23, username=username) |
|
273 | 269 | assert clone_url == expected |
@@ -278,8 +274,6 b' class TestLibs(base.TestController):' | |||
|
278 | 274 | |
|
279 | 275 | :param text: |
|
280 | 276 | """ |
|
281 | import re | |
|
282 | ||
|
283 | 277 | # quickly change expected url[] into a link |
|
284 | 278 | url_pattern = re.compile(r'(?:url\[)(.+?)(?:\])') |
|
285 | 279 | |
@@ -553,9 +547,6 b' class TestLibs(base.TestController):' | |||
|
553 | 547 | ]) |
|
554 | 548 | def test_canonical_url(self, canonical, test, expected): |
|
555 | 549 | # setup url(), used by canonical_url |
|
556 | import routes | |
|
557 | from tg import request | |
|
558 | ||
|
559 | 550 | m = routes.Mapper() |
|
560 | 551 | m.connect('about', '/about-page') |
|
561 | 552 | url = routes.URLGenerator(m, {'HTTP_HOST': 'http_host.example.org'}) |
@@ -575,9 +566,6 b' class TestLibs(base.TestController):' | |||
|
575 | 566 | ('http://www.example.org/kallithea/repos/', 'www.example.org'), |
|
576 | 567 | ]) |
|
577 | 568 | def test_canonical_hostname(self, canonical, expected): |
|
578 | import routes | |
|
579 | from tg import request | |
|
580 | ||
|
581 | 569 | # setup url(), used by canonical_hostname |
|
582 | 570 | m = routes.Mapper() |
|
583 | 571 | url = routes.URLGenerator(m, {'HTTP_HOST': 'http_host.example.org'}) |
@@ -14,6 +14,7 b'' | |||
|
14 | 14 | |
|
15 | 15 | import pytest |
|
16 | 16 | |
|
17 | from kallithea.lib.graphmod import graph_data | |
|
17 | 18 | from kallithea.model import db |
|
18 | 19 | from kallithea.tests import base |
|
19 | 20 | |
@@ -23,7 +24,6 b' class TestVCSPerformance(base.TestContro' | |||
|
23 | 24 | |
|
24 | 25 | def graphmod(self, repo): |
|
25 | 26 | """ Simple test for running the graph_data function for profiling/testing performance. """ |
|
26 | from kallithea.lib.graphmod import graph_data | |
|
27 | 27 | dbr = db.Repository.get_by_repo_name(repo) |
|
28 | 28 | scm_inst = dbr.scm_instance |
|
29 | 29 | collection = scm_inst.get_changesets(start=0, end=None, branch_name=None) |
@@ -41,6 +41,7 b' import kallithea.config.application' | |||
|
41 | 41 | from kallithea.lib.auth import get_crypt_password |
|
42 | 42 | from kallithea.model import db, meta |
|
43 | 43 | from kallithea.model.base import init_model |
|
44 | from kallithea.model.repo import RepoModel | |
|
44 | 45 | from kallithea.tests.base import HG_REPO, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS |
|
45 | 46 | |
|
46 | 47 | |
@@ -114,7 +115,6 b' def create_test_user(force=True):' | |||
|
114 | 115 | |
|
115 | 116 | def create_test_repo(force=True): |
|
116 | 117 | print('creating test repo') |
|
117 | from kallithea.model.repo import RepoModel | |
|
118 | 118 | sa = get_session() |
|
119 | 119 | |
|
120 | 120 | user = sa.query(db.User).filter(db.User.username == USER).scalar() |
@@ -1,3 +1,4 b'' | |||
|
1 | import copy | |
|
1 | 2 | import datetime |
|
2 | 3 | |
|
3 | 4 | import pytest |
@@ -31,7 +32,6 b' class RepositoryBaseTest(_BackendTestMix' | |||
|
31 | 32 | assert self.repo == self.repo |
|
32 | 33 | |
|
33 | 34 | def test_repo_equality_broken_object(self): |
|
34 | import copy | |
|
35 | 35 | _repo = copy.copy(self.repo) |
|
36 | 36 | delattr(_repo, 'path') |
|
37 | 37 | assert self.repo != _repo |
@@ -2,6 +2,7 b' import datetime' | |||
|
2 | 2 | |
|
3 | 3 | import pytest |
|
4 | 4 | |
|
5 | from kallithea.lib.vcs.exceptions import BranchDoesNotExistError | |
|
5 | 6 | from kallithea.lib.vcs.nodes import FileNode |
|
6 | 7 | from kallithea.tests.vcs.base import _BackendTestMixin |
|
7 | 8 | |
@@ -67,8 +68,6 b' class WorkdirTestCaseMixin(_BackendTestM' | |||
|
67 | 68 | assert self.repo.workdir.get_changeset() == old_head |
|
68 | 69 | |
|
69 | 70 | def test_checkout_branch(self): |
|
70 | from kallithea.lib.vcs.exceptions import BranchDoesNotExistError | |
|
71 | ||
|
72 | 71 | # first, 'foobranch' does not exist. |
|
73 | 72 | with pytest.raises(BranchDoesNotExistError): |
|
74 | 73 | self.repo.workdir.checkout_branch(branch='foobranch') |
@@ -2,6 +2,7 b'' | |||
|
2 | 2 | # -*- coding: utf-8 -*- |
|
3 | 3 | import os |
|
4 | 4 | import platform |
|
5 | import re | |
|
5 | 6 | import sys |
|
6 | 7 | |
|
7 | 8 | import setuptools |
@@ -17,7 +18,6 b' here = os.path.abspath(os.path.dirname(_' | |||
|
17 | 18 | |
|
18 | 19 | |
|
19 | 20 | def _get_meta_var(name, data, callback_handler=None): |
|
20 | import re | |
|
21 | 21 | matches = re.compile(r'(?:%s)\s*=\s*(.*)' % name).search(data) |
|
22 | 22 | if matches: |
|
23 | 23 | s = eval(matches.groups()[0]) |
General Comments 0
You need to be logged in to leave comments.
Login now