##// END OF EJS Templates
tests: improved vcs tests
marcink -
r2613:fb7f2b99 default
parent child Browse files
Show More
@@ -21,41 +21,31 b''
21 21 """
22 22 Tests for main module's methods.
23 23 """
24
24 import os
25 import tempfile
26 import shutil
25 27 import mock
26 import os
27 import shutil
28 import tempfile
29
30 28 import pytest
31 29
32 30 from rhodecode.lib.vcs import VCSError, get_backend, get_vcs_instance
33 from rhodecode.lib.vcs.backends.hg import MercurialRepository
34 from rhodecode.tests import TEST_HG_REPO, TEST_GIT_REPO
35 31
36 32
37 33 pytestmark = pytest.mark.usefixtures("baseapp")
38 34
39 35
40 def test_get_backend():
41 hg = get_backend('hg')
42 assert hg == MercurialRepository
36 def test_get_backend(backend):
37 repo_class = get_backend(backend.alias)
38 assert repo_class == backend.repo.scm_instance().__class__
43 39
44 40
45 def test_alias_detect_hg():
46 alias = 'hg'
47 path = TEST_HG_REPO
48 backend = get_backend(alias)
49 repo = backend(path)
50 assert 'hg' == repo.alias
41 def test_alias_detect(backend):
42 alias = backend.alias
43 path = backend.repo.scm_instance().path
51 44
45 new_backend = get_backend(alias)
46 repo = new_backend(path)
52 47
53 def test_alias_detect_git():
54 alias = 'git'
55 path = TEST_GIT_REPO
56 backend = get_backend(alias)
57 repo = backend(path)
58 assert 'git' == repo.alias
48 assert alias == repo.alias
59 49
60 50
61 51 def test_wrong_alias():
@@ -73,56 +63,13 b' def test_get_vcs_instance_by_path(vcs_re'
73 63 assert repo.name == vcs_repo.name
74 64
75 65
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)
88
89 backend.assert_called_with(*args, repo_path=TEST_HG_REPO)
90
91
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)
109
110 backend.assert_called_with(repo_path=TEST_HG_REPO, **kwargs)
111
112
113 def test_get_vcs_instance_by_path_err(request):
66 def test_get_vcs_instance_by_path_empty_dir(request, tmpdir):
114 67 """
115 68 Test that ``get_vcs_instance_by_path`` returns None if a path is passed
116 69 to an empty directory.
117 70 """
118 empty_dir = tempfile.mkdtemp(prefix='pytest-empty-dir-')
119
120 def fin():
121 shutil.rmtree(empty_dir)
122 request.addfinalizer(fin)
123
71 empty_dir = str(tmpdir)
124 72 repo = get_vcs_instance(empty_dir)
125
126 73 assert repo is None
127 74
128 75
@@ -142,3 +89,42 b' def test_get_vcs_instance_by_path_multip'
142 89 repo = get_vcs_instance(empty_dir)
143 90
144 91 assert repo is None
92
93
94 @mock.patch('rhodecode.lib.vcs.backends.get_scm')
95 @mock.patch('rhodecode.lib.vcs.backends.get_backend')
96 def test_get_vcs_instance_by_path_args_passed(
97 get_backend_mock, get_scm_mock, tmpdir, vcs_repo):
98 """
99 Test that the arguments passed to ``get_vcs_instance_by_path`` are
100 forwarded to the vcs backend class.
101 """
102 backend = mock.MagicMock()
103 get_backend_mock.return_value = backend
104 args = ['these-are-test-args', 0, True, None]
105 repo = vcs_repo.path
106 get_vcs_instance(repo, *args)
107
108 backend.assert_called_with(*args, repo_path=repo)
109
110
111 @mock.patch('rhodecode.lib.vcs.backends.get_scm')
112 @mock.patch('rhodecode.lib.vcs.backends.get_backend')
113 def test_get_vcs_instance_by_path_kwargs_passed(
114 get_backend_mock, get_scm_mock, vcs_repo):
115 """
116 Test that the keyword arguments passed to ``get_vcs_instance_by_path`` are
117 forwarded to the vcs backend class.
118 """
119 backend = mock.MagicMock()
120 get_backend_mock.return_value = backend
121 kwargs = {
122 'foo': 'these-are-test-args',
123 'bar': 0,
124 'baz': True,
125 'foobar': None
126 }
127 repo = vcs_repo.path
128 get_vcs_instance(repo, **kwargs)
129
130 backend.assert_called_with(repo_path=repo, **kwargs)
General Comments 0
You need to be logged in to leave comments. Login now