tests: Fix a helper method that checks if a repository is available on filesystem.

- Moved it into utils to remove duplication
- Refactored it to not hide all kinds of exceptions.
This commit is contained in:
Martin Bornhold 2016-07-21 09:06:47 +02:00
parent 0c7d0871b5
commit 873a0753a5
3 changed files with 12 additions and 24 deletions

View file

@ -18,14 +18,12 @@
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import os
import urllib
import mock
import pytest
from rhodecode.lib import auth
from rhodecode.lib import vcs
from rhodecode.lib.utils2 import safe_str, str2bool
from rhodecode.lib.vcs.exceptions import RepositoryRequirementError
from rhodecode.model.db import Repository, RepoGroup, UserRepoToPerm, User,\
@ -38,9 +36,9 @@ from rhodecode.model.user import UserModel
from rhodecode.tests import (
login_user_session, url, assert_session_flash, TEST_USER_ADMIN_LOGIN,
TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, HG_REPO, GIT_REPO,
TESTS_TMP_PATH, logout_user_session)
logout_user_session)
from rhodecode.tests.fixture import Fixture, error_function
from rhodecode.tests.utils import AssertResponse
from rhodecode.tests.utils import AssertResponse, repo_on_filesystem
fixture = Fixture()
@ -1243,14 +1241,6 @@ class TestVcsSettings(object):
assert repo_element.value == global_element.value
def repo_on_filesystem(repo_name):
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
return True
except Exception:
return False
def _get_permission_for_user(user, repo):
perm = UserRepoToPerm.query()\
.filter(UserRepoToPerm.repository ==

View file

@ -19,13 +19,11 @@
# and proprietary license terms, please see https://rhodecode.com/licenses/
import re
import os
import mock
import pytest
from rhodecode.controllers import summary
from rhodecode.lib import vcs
from rhodecode.lib import helpers as h
from rhodecode.lib.compat import OrderedDict
from rhodecode.lib.vcs.exceptions import RepositoryRequirementError
@ -34,9 +32,9 @@ from rhodecode.model.meta import Session
from rhodecode.model.repo import RepoModel
from rhodecode.model.scm import ScmModel
from rhodecode.tests import (
TestController, url, HG_REPO, assert_session_flash, TESTS_TMP_PATH)
TestController, url, HG_REPO, assert_session_flash)
from rhodecode.tests.fixture import Fixture
from rhodecode.tests.utils import AssertResponse
from rhodecode.tests.utils import AssertResponse, repo_on_filesystem
fixture = Fixture()
@ -400,14 +398,6 @@ class TestRepoLocation:
response, 'The repository at %s cannot be located.' % repo_name)
def repo_on_filesystem(repo_name):
try:
vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
return True
except Exception:
return False
class TestCreateFilesUrl(object):
def test_creates_non_svn_url(self):
controller = summary.SummaryController()

View file

@ -283,3 +283,11 @@ def get_session_from_response(response):
"""
# TODO: Try to look up the session key also.
return response.request.environ['beaker.session']
def repo_on_filesystem(repo_name):
from rhodecode.lib import vcs
from rhodecode.tests import TESTS_TMP_PATH
repo = vcs.get_vcs_instance(
os.path.join(TESTS_TMP_PATH, repo_name), create=False)
return repo is not None