Show More
@@ -38,7 +38,7 b' import os' | |||||
38 | import pytest |
|
38 | import pytest | |
39 |
|
39 | |||
40 | from rhodecode.lib.vcs import create_vcsserver_proxy |
|
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 | from rhodecode.tests import TEST_HG_REPO, TEST_GIT_REPO |
|
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 | 'hg': TEST_HG_REPO, |
|
54 | 'hg': TEST_HG_REPO, | |
55 | 'git': TEST_GIT_REPO, |
|
55 | 'git': TEST_GIT_REPO, | |
56 | } |
|
56 | } | |
57 |
repo = get_ |
|
57 | repo = get_vcs_instance(repos[request.param]) | |
58 | return repo |
|
58 | return repo | |
59 |
|
59 | |||
60 |
|
60 |
@@ -22,14 +22,16 b'' | |||||
22 | Tests for main module's methods. |
|
22 | Tests for main module's methods. | |
23 | """ |
|
23 | """ | |
24 |
|
24 | |||
|
25 | import mock | |||
25 | import os |
|
26 | import os | |
26 | import shutil |
|
27 | import shutil | |
|
28 | import tempfile | |||
27 |
|
29 | |||
28 | import pytest |
|
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 | from rhodecode.lib.vcs.backends.hg import MercurialRepository |
|
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 | pytestmark = pytest.mark.usefixtures("pylonsapp") |
|
37 | pytestmark = pytest.mark.usefixtures("pylonsapp") | |
@@ -62,53 +64,81 b' def test_wrong_alias():' | |||||
62 | get_backend(alias) |
|
64 | get_backend(alias) | |
63 |
|
65 | |||
64 |
|
66 | |||
65 | def test_get_repo(): |
|
67 | def test_get_vcs_instance_by_path(vcs_repo): | |
66 | alias = 'hg' |
|
68 | repo = get_vcs_instance(vcs_repo.path) | |
67 | path = TEST_HG_REPO |
|
|||
68 | backend = get_backend(alias) |
|
|||
69 | repo = backend(path) |
|
|||
70 |
|
69 | |||
71 |
assert repo.__class__ |
|
70 | assert repo.__class__ == vcs_repo.__class__ | |
72 |
assert repo.path |
|
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 | @mock.patch('rhodecode.lib.vcs.backends.get_scm') | |
76 | alias = 'hg' |
|
77 | @mock.patch('rhodecode.lib.vcs.backends.get_backend') | |
77 | path = TEST_HG_REPO |
|
78 | def test_get_vcs_instance_by_path_args_passed( | |
78 | backend = get_backend(alias) |
|
79 | get_backend_mock, get_scm_mock): | |
79 | repo = backend(path) |
|
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__ |
|
89 | backend.assert_called_with(*args, repo_path=TEST_HG_REPO) | |
82 | assert repo.path == get_repo(path).path |
|
|||
83 |
|
90 | |||
84 |
|
91 | |||
85 | def test_get_repo_autoalias_git(): |
|
92 | @mock.patch('rhodecode.lib.vcs.backends.get_scm') | |
86 | alias = 'git' |
|
93 | @mock.patch('rhodecode.lib.vcs.backends.get_backend') | |
87 | path = TEST_GIT_REPO |
|
94 | def test_get_vcs_instance_by_path_kwargs_passed( | |
88 | backend = get_backend(alias) |
|
95 | get_backend_mock, get_scm_mock): | |
89 | repo = backend(path) |
|
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__ |
|
110 | backend.assert_called_with(repo_path=TEST_HG_REPO, **kwargs) | |
92 | assert repo.path == get_repo(path).path |
|
|||
93 |
|
111 | |||
94 |
|
112 | |||
95 |
def test_get_ |
|
113 | def test_get_vcs_instance_by_path_err(request): | |
96 | blank_repo_path = os.path.join(TESTS_TMP_PATH, 'blank-error-repo') |
|
114 | """ | |
97 | if os.path.isdir(blank_repo_path): |
|
115 | Test that ``get_vcs_instance_by_path`` returns None if a path is passed | |
98 | shutil.rmtree(blank_repo_path) |
|
116 | to an empty directory. | |
|
117 | """ | |||
|
118 | empty_dir = tempfile.mkdtemp(prefix='pytest-empty-dir-') | |||
99 |
|
119 | |||
100 | os.mkdir(blank_repo_path) |
|
120 | def fin(): | |
101 | pytest.raises(VCSError, get_repo, blank_repo_path) |
|
121 | shutil.rmtree(empty_dir) | |
102 | pytest.raises(VCSError, get_repo, blank_repo_path + 'non_existing') |
|
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(): |
|
129 | def test_get_vcs_instance_by_path_multiple_repos(request): | |
106 | multialias_repo_path = os.path.join(TESTS_TMP_PATH, 'hg-git-repo') |
|
130 | """ | |
107 | if os.path.isdir(multialias_repo_path): |
|
131 | Test that ``get_vcs_instance_by_path`` returns None if a path is passed | |
108 | shutil.rmtree(multialias_repo_path) |
|
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')) |
|
142 | repo = get_vcs_instance(empty_dir) | |
113 | os.mkdir(os.path.join(multialias_repo_path, '.hg')) |
|
143 | ||
114 | pytest.raises(VCSError, get_repo, multialias_repo_path) |
|
144 | assert repo is None |
General Comments 0
You need to be logged in to leave comments.
Login now