##// END OF EJS Templates
validators: fix url_validator tests and make it flag controllable.
marcink -
r3072:fe39713b default
parent child Browse files
Show More
@@ -19,7 +19,7 b''
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import os
22
22 import mock
23 23 import pytest
24 24
25 25 from rhodecode.tests import TESTS_TMP_PATH
@@ -29,6 +29,7 b' from rhodecode.api.tests.utils import ('
29 29
30 30 @pytest.mark.usefixtures("testuser_api", "app")
31 31 class TestPull(object):
32
32 33 @pytest.mark.backends("git", "hg")
33 34 def test_api_pull(self, backend):
34 35 r = backend.create_repo()
@@ -37,12 +38,13 b' class TestPull(object):'
37 38 r.clone_uri = clone_uri
38 39
39 40 id_, params = build_data(self.apikey, 'pull', repoid=repo_name,)
40 response = api_call(self.app, params)
41 msg = 'Pulled from url `%s` on repo `%s`' % (
42 clone_uri, repo_name)
43 expected = {'msg': msg,
44 'repository': repo_name}
45 assert_ok(id_, expected, given=response.body)
41 with mock.patch('rhodecode.model.scm.url_validator'):
42 response = api_call(self.app, params)
43 msg = 'Pulled from url `%s` on repo `%s`' % (
44 clone_uri, repo_name)
45 expected = {'msg': msg,
46 'repository': repo_name}
47 assert_ok(id_, expected, given=response.body)
46 48
47 49 def test_api_pull_error(self, backend):
48 50 id_, params = build_data(
@@ -56,9 +56,15 b' class TestApiUpdateRepo(object):'
56 56 ({'clone_uri': ''},
57 57 {'clone_uri': ''}),
58 58
59 ({'clone_uri': 'http://example.com/repo_pull'},
60 {'clone_uri': 'http://example.com/repo_pull'}),
61
59 62 ({'push_uri': ''},
60 63 {'push_uri': ''}),
61 64
65 ({'push_uri': 'http://example.com/repo_push'},
66 {'push_uri': 'http://example.com/repo_push'}),
67
62 68 ({'landing_rev': 'rev:tip'},
63 69 {'landing_rev': ['rev', 'tip']}),
64 70
@@ -377,7 +377,7 b' class ScmModel(BaseModel):'
377 377 self.sa.add(repo)
378 378 return repo
379 379
380 def pull_changes(self, repo, username, remote_uri=None):
380 def pull_changes(self, repo, username, remote_uri=None, validate_uri=True):
381 381 dbrepo = self._get_repo(repo)
382 382 remote_uri = remote_uri or dbrepo.clone_uri
383 383 if not remote_uri:
@@ -390,8 +390,9 b' class ScmModel(BaseModel):'
390 390 # NOTE(marcink): add extra validation so we skip invalid urls
391 391 # this is due this tasks can be executed via scheduler without
392 392 # proper validation of remote_uri
393 config = make_db_config(clear_session=False)
394 url_validator(remote_uri, dbrepo.repo_type, config)
393 if validate_uri:
394 config = make_db_config(clear_session=False)
395 url_validator(remote_uri, dbrepo.repo_type, config)
395 396 except InvalidCloneUrl:
396 397 raise
397 398
@@ -405,7 +406,7 b' class ScmModel(BaseModel):'
405 406 log.error(traceback.format_exc())
406 407 raise
407 408
408 def push_changes(self, repo, username, remote_uri=None):
409 def push_changes(self, repo, username, remote_uri=None, validate_uri=True):
409 410 dbrepo = self._get_repo(repo)
410 411 remote_uri = remote_uri or dbrepo.push_uri
411 412 if not remote_uri:
@@ -418,8 +419,9 b' class ScmModel(BaseModel):'
418 419 # NOTE(marcink): add extra validation so we skip invalid urls
419 420 # this is due this tasks can be executed via scheduler without
420 421 # proper validation of remote_uri
421 config = make_db_config(clear_session=False)
422 url_validator(remote_uri, dbrepo.repo_type, config)
422 if validate_uri:
423 config = make_db_config(clear_session=False)
424 url_validator(remote_uri, dbrepo.repo_type, config)
423 425 except InvalidCloneUrl:
424 426 raise
425 427
General Comments 0
You need to be logged in to leave comments. Login now