Show More
@@ -38,7 +38,7 b' import os' | |||
|
38 | 38 | import pytest |
|
39 | 39 | |
|
40 | 40 | from rhodecode.lib.vcs import create_vcsserver_proxy |
|
41 |
from rhodecode.lib.vcs.backends import get_ |
|
|
41 | from rhodecode.lib.vcs.backends import get_backend, get_vcs_instance | |
|
42 | 42 | from rhodecode.tests import TEST_HG_REPO, TEST_GIT_REPO |
|
43 | 43 | |
|
44 | 44 | |
@@ -54,7 +54,7 b' def repo(request, pylonsapp):' | |||
|
54 | 54 | 'hg': TEST_HG_REPO, |
|
55 | 55 | 'git': TEST_GIT_REPO, |
|
56 | 56 | } |
|
57 |
repo = get_ |
|
|
57 | repo = get_vcs_instance(repos[request.param]) | |
|
58 | 58 | return repo |
|
59 | 59 | |
|
60 | 60 |
@@ -22,14 +22,16 b'' | |||
|
22 | 22 | Tests for main module's methods. |
|
23 | 23 | """ |
|
24 | 24 | |
|
25 | import mock | |
|
25 | 26 | import os |
|
26 | 27 | import shutil |
|
28 | import tempfile | |
|
27 | 29 | |
|
28 | 30 | import pytest |
|
29 | 31 | |
|
30 |
from rhodecode.lib.vcs import VCSError, get_ |
|
|
32 | from rhodecode.lib.vcs import VCSError, get_backend, get_vcs_instance | |
|
31 | 33 | from rhodecode.lib.vcs.backends.hg import MercurialRepository |
|
32 |
from rhodecode.tests import TEST_HG_REPO, TEST_GIT_REPO |
|
|
34 | from rhodecode.tests import TEST_HG_REPO, TEST_GIT_REPO | |
|
33 | 35 | |
|
34 | 36 | |
|
35 | 37 | pytestmark = pytest.mark.usefixtures("pylonsapp") |
@@ -62,53 +64,81 b' def test_wrong_alias():' | |||
|
62 | 64 | get_backend(alias) |
|
63 | 65 | |
|
64 | 66 | |
|
65 | def test_get_repo(): | |
|
66 | alias = 'hg' | |
|
67 | path = TEST_HG_REPO | |
|
68 | backend = get_backend(alias) | |
|
69 | repo = backend(path) | |
|
67 | def test_get_vcs_instance_by_path(vcs_repo): | |
|
68 | repo = get_vcs_instance(vcs_repo.path) | |
|
70 | 69 | |
|
71 |
assert repo.__class__ |
|
|
72 |
assert repo.path |
|
|
70 | assert repo.__class__ == vcs_repo.__class__ | |
|
71 | assert repo.path == vcs_repo.path | |
|
72 | assert repo.alias == vcs_repo.alias | |
|
73 | assert repo.name == vcs_repo.name | |
|
73 | 74 | |
|
74 | 75 | |
|
75 | def test_get_repo_autoalias_hg(): | |
|
76 | alias = 'hg' | |
|
77 | path = TEST_HG_REPO | |
|
78 | backend = get_backend(alias) | |
|
79 | repo = backend(path) | |
|
76 | @mock.patch('rhodecode.lib.vcs.backends.get_scm') | |
|
77 | @mock.patch('rhodecode.lib.vcs.backends.get_backend') | |
|
78 | def test_get_vcs_instance_by_path_args_passed( | |
|
79 | get_backend_mock, get_scm_mock): | |
|
80 | """ | |
|
81 | Test that the arguments passed to ``get_vcs_instance_by_path`` are | |
|
82 | forewarded to the vcs backend class. | |
|
83 | """ | |
|
84 | backend = mock.MagicMock() | |
|
85 | get_backend_mock.return_value = backend | |
|
86 | args = ['these-are-test-args', 0, True, None] | |
|
87 | get_vcs_instance(TEST_HG_REPO, *args) | |
|
80 | 88 | |
|
81 | assert repo.__class__ == get_repo(path).__class__ | |
|
82 | assert repo.path == get_repo(path).path | |
|
89 | backend.assert_called_with(*args, repo_path=TEST_HG_REPO) | |
|
83 | 90 | |
|
84 | 91 | |
|
85 | def test_get_repo_autoalias_git(): | |
|
86 | alias = 'git' | |
|
87 | path = TEST_GIT_REPO | |
|
88 | backend = get_backend(alias) | |
|
89 | repo = backend(path) | |
|
92 | @mock.patch('rhodecode.lib.vcs.backends.get_scm') | |
|
93 | @mock.patch('rhodecode.lib.vcs.backends.get_backend') | |
|
94 | def test_get_vcs_instance_by_path_kwargs_passed( | |
|
95 | get_backend_mock, get_scm_mock): | |
|
96 | """ | |
|
97 | Test that the keyword arguments passed to ``get_vcs_instance_by_path`` are | |
|
98 | forewarded to the vcs backend class. | |
|
99 | """ | |
|
100 | backend = mock.MagicMock() | |
|
101 | get_backend_mock.return_value = backend | |
|
102 | kwargs = { | |
|
103 | 'foo': 'these-are-test-args', | |
|
104 | 'bar': 0, | |
|
105 | 'baz': True, | |
|
106 | 'foobar': None | |
|
107 | } | |
|
108 | get_vcs_instance(TEST_HG_REPO, **kwargs) | |
|
90 | 109 | |
|
91 | assert repo.__class__ == get_repo(path).__class__ | |
|
92 | assert repo.path == get_repo(path).path | |
|
110 | backend.assert_called_with(repo_path=TEST_HG_REPO, **kwargs) | |
|
93 | 111 | |
|
94 | 112 | |
|
95 |
def test_get_ |
|
|
96 | blank_repo_path = os.path.join(TESTS_TMP_PATH, 'blank-error-repo') | |
|
97 | if os.path.isdir(blank_repo_path): | |
|
98 | shutil.rmtree(blank_repo_path) | |
|
113 | def test_get_vcs_instance_by_path_err(request): | |
|
114 | """ | |
|
115 | Test that ``get_vcs_instance_by_path`` returns None if a path is passed | |
|
116 | to an empty directory. | |
|
117 | """ | |
|
118 | empty_dir = tempfile.mkdtemp(prefix='pytest-empty-dir-') | |
|
99 | 119 | |
|
100 | os.mkdir(blank_repo_path) | |
|
101 | pytest.raises(VCSError, get_repo, blank_repo_path) | |
|
102 | pytest.raises(VCSError, get_repo, blank_repo_path + 'non_existing') | |
|
120 | def fin(): | |
|
121 | shutil.rmtree(empty_dir) | |
|
122 | request.addfinalizer(fin) | |
|
123 | ||
|
124 | repo = get_vcs_instance(empty_dir) | |
|
125 | ||
|
126 | assert repo is None | |
|
103 | 127 | |
|
104 | 128 | |
|
105 | def test_get_repo_multialias(): | |
|
106 | multialias_repo_path = os.path.join(TESTS_TMP_PATH, 'hg-git-repo') | |
|
107 | if os.path.isdir(multialias_repo_path): | |
|
108 | shutil.rmtree(multialias_repo_path) | |
|
129 | def test_get_vcs_instance_by_path_multiple_repos(request): | |
|
130 | """ | |
|
131 | Test that ``get_vcs_instance_by_path`` returns None if a path is passed | |
|
132 | to a directory with multiple repositories. | |
|
133 | """ | |
|
134 | empty_dir = tempfile.mkdtemp(prefix='pytest-empty-dir-') | |
|
135 | os.mkdir(os.path.join(empty_dir, '.git')) | |
|
136 | os.mkdir(os.path.join(empty_dir, '.hg')) | |
|
109 | 137 | |
|
110 | os.mkdir(multialias_repo_path) | |
|
138 | def fin(): | |
|
139 | shutil.rmtree(empty_dir) | |
|
140 | request.addfinalizer(fin) | |
|
111 | 141 | |
|
112 | os.mkdir(os.path.join(multialias_repo_path, '.git')) | |
|
113 | os.mkdir(os.path.join(multialias_repo_path, '.hg')) | |
|
114 | pytest.raises(VCSError, get_repo, multialias_repo_path) | |
|
142 | repo = get_vcs_instance(empty_dir) | |
|
143 | ||
|
144 | assert repo is None |
General Comments 0
You need to be logged in to leave comments.
Login now