validators: fix url_validator tests and make it flag controllable.
This commit is contained in:
parent
8ab9a65878
commit
da91bab5d6
3 changed files with 23 additions and 13 deletions
|
|
@ -19,7 +19,7 @@
|
|||
# and proprietary license terms, please see https://rhodecode.com/licenses/
|
||||
|
||||
import os
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from rhodecode.tests import TESTS_TMP_PATH
|
||||
|
|
@ -29,6 +29,7 @@ from rhodecode.api.tests.utils import (
|
|||
|
||||
@pytest.mark.usefixtures("testuser_api", "app")
|
||||
class TestPull(object):
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_api_pull(self, backend):
|
||||
r = backend.create_repo()
|
||||
|
|
@ -37,12 +38,13 @@ class TestPull(object):
|
|||
r.clone_uri = clone_uri
|
||||
|
||||
id_, params = build_data(self.apikey, 'pull', repoid=repo_name,)
|
||||
response = api_call(self.app, params)
|
||||
msg = 'Pulled from url `%s` on repo `%s`' % (
|
||||
clone_uri, repo_name)
|
||||
expected = {'msg': msg,
|
||||
'repository': repo_name}
|
||||
assert_ok(id_, expected, given=response.body)
|
||||
with mock.patch('rhodecode.model.scm.url_validator'):
|
||||
response = api_call(self.app, params)
|
||||
msg = 'Pulled from url `%s` on repo `%s`' % (
|
||||
clone_uri, repo_name)
|
||||
expected = {'msg': msg,
|
||||
'repository': repo_name}
|
||||
assert_ok(id_, expected, given=response.body)
|
||||
|
||||
def test_api_pull_error(self, backend):
|
||||
id_, params = build_data(
|
||||
|
|
|
|||
|
|
@ -56,9 +56,15 @@ class TestApiUpdateRepo(object):
|
|||
({'clone_uri': ''},
|
||||
{'clone_uri': ''}),
|
||||
|
||||
({'clone_uri': 'http://example.com/repo_pull'},
|
||||
{'clone_uri': 'http://example.com/repo_pull'}),
|
||||
|
||||
({'push_uri': ''},
|
||||
{'push_uri': ''}),
|
||||
|
||||
({'push_uri': 'http://example.com/repo_push'},
|
||||
{'push_uri': 'http://example.com/repo_push'}),
|
||||
|
||||
({'landing_rev': 'rev:tip'},
|
||||
{'landing_rev': ['rev', 'tip']}),
|
||||
|
||||
|
|
|
|||
|
|
@ -377,7 +377,7 @@ class ScmModel(BaseModel):
|
|||
self.sa.add(repo)
|
||||
return repo
|
||||
|
||||
def pull_changes(self, repo, username, remote_uri=None):
|
||||
def pull_changes(self, repo, username, remote_uri=None, validate_uri=True):
|
||||
dbrepo = self._get_repo(repo)
|
||||
remote_uri = remote_uri or dbrepo.clone_uri
|
||||
if not remote_uri:
|
||||
|
|
@ -390,8 +390,9 @@ class ScmModel(BaseModel):
|
|||
# NOTE(marcink): add extra validation so we skip invalid urls
|
||||
# this is due this tasks can be executed via scheduler without
|
||||
# proper validation of remote_uri
|
||||
config = make_db_config(clear_session=False)
|
||||
url_validator(remote_uri, dbrepo.repo_type, config)
|
||||
if validate_uri:
|
||||
config = make_db_config(clear_session=False)
|
||||
url_validator(remote_uri, dbrepo.repo_type, config)
|
||||
except InvalidCloneUrl:
|
||||
raise
|
||||
|
||||
|
|
@ -405,7 +406,7 @@ class ScmModel(BaseModel):
|
|||
log.error(traceback.format_exc())
|
||||
raise
|
||||
|
||||
def push_changes(self, repo, username, remote_uri=None):
|
||||
def push_changes(self, repo, username, remote_uri=None, validate_uri=True):
|
||||
dbrepo = self._get_repo(repo)
|
||||
remote_uri = remote_uri or dbrepo.push_uri
|
||||
if not remote_uri:
|
||||
|
|
@ -418,8 +419,9 @@ class ScmModel(BaseModel):
|
|||
# NOTE(marcink): add extra validation so we skip invalid urls
|
||||
# this is due this tasks can be executed via scheduler without
|
||||
# proper validation of remote_uri
|
||||
config = make_db_config(clear_session=False)
|
||||
url_validator(remote_uri, dbrepo.repo_type, config)
|
||||
if validate_uri:
|
||||
config = make_db_config(clear_session=False)
|
||||
url_validator(remote_uri, dbrepo.repo_type, config)
|
||||
except InvalidCloneUrl:
|
||||
raise
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue