1
|
|
|
"""Unit tests for the doorstop.vcs plugin modules.""" |
2
|
|
|
|
3
|
|
|
import unittest |
4
|
|
|
from unittest.mock import patch, Mock, call |
5
|
|
|
|
6
|
|
|
from doorstop.core.vcs import load |
7
|
|
|
from doorstop.common import DoorstopError |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class BaseTestCase(): # pylint: disable=R0904 |
11
|
|
|
"""Base TestCase for tests that need a working copy.""" |
12
|
|
|
|
13
|
|
|
DIRECTORY = None |
14
|
|
|
|
15
|
|
|
path = "path/to/mock/file.txt" |
16
|
|
|
dirpath = "path/to/mock/directory/" |
17
|
|
|
message = "A commit message" |
18
|
|
|
|
19
|
|
|
def setUp(self): |
|
|
|
|
20
|
|
|
with patch('os.listdir', Mock(return_value=[self.DIRECTORY])): |
21
|
|
|
self.wc = load('.') |
22
|
|
|
|
23
|
|
|
def lock(self): |
24
|
|
|
"""Lock a file in the working copy.""" |
25
|
|
|
self.wc.lock(self.path) |
26
|
|
|
|
27
|
|
|
def edit(self): |
28
|
|
|
"""Edit a file in the working copy.""" |
29
|
|
|
self.wc.edit(self.path) |
30
|
|
|
|
31
|
|
|
def add(self): |
32
|
|
|
"""Add a file to the working copy.""" |
33
|
|
|
self.wc.add(self.path) |
34
|
|
|
|
35
|
|
|
def delete(self): |
36
|
|
|
"""Remove a file in the working copy.""" |
37
|
|
|
self.wc.delete(self.path) |
38
|
|
|
|
39
|
|
|
def commit(self): |
40
|
|
|
"""Save all files in the working copy.""" |
41
|
|
|
self.wc.commit(self.message) |
42
|
|
|
|
43
|
|
|
def test_missing_command(self, mock_call): |
44
|
|
|
"""Verify that a missing command raises a DoorstopError""" |
45
|
|
|
mock_call.side_effect = FileNotFoundError |
46
|
|
|
self.assertRaises(DoorstopError, self.add) |
47
|
|
|
|
48
|
|
|
|
49
|
|
View Code Duplication |
@patch('subprocess.call') # pylint: disable=R0904 |
|
|
|
|
50
|
|
|
class TestGit(BaseTestCase, unittest.TestCase): |
51
|
|
|
"""Tests for the Git plugin.""" |
52
|
|
|
|
53
|
|
|
DIRECTORY = '.git' |
54
|
|
|
|
55
|
|
|
def test_lock(self, mock_call): |
56
|
|
|
"""Verify Git can (fake) lock files.""" |
57
|
|
|
self.lock() |
58
|
|
|
calls = [call(("git", "pull"))] |
59
|
|
|
mock_call.assert_has_calls(calls) |
60
|
|
|
|
61
|
|
|
def test_edit(self, mock_call): |
62
|
|
|
"""Verify Git can edit files.""" |
63
|
|
|
self.edit() |
64
|
|
|
calls = [call(("git", "add", self.path))] |
65
|
|
|
mock_call.assert_has_calls(calls) |
66
|
|
|
|
67
|
|
|
def test_add(self, mock_call): |
68
|
|
|
"""Verify Git can add files.""" |
69
|
|
|
self.add() |
70
|
|
|
calls = [call(("git", "add", self.path))] |
71
|
|
|
mock_call.assert_has_calls(calls) |
72
|
|
|
|
73
|
|
|
def test_delete(self, mock_call): |
74
|
|
|
"""Verify Git can delete files.""" |
75
|
|
|
self.delete() |
76
|
|
|
calls = [call(("git", "rm", "-r", self.path, "--force", "--quiet"))] |
77
|
|
|
mock_call.assert_has_calls(calls) |
78
|
|
|
|
79
|
|
|
def test_commit(self, mock_call): |
80
|
|
|
"""Verify Git can commit files.""" |
81
|
|
|
self.commit() |
82
|
|
|
calls = [call(("git", "commit", "--all", "--message", self.message)), |
83
|
|
|
call(("git", "push"))] |
84
|
|
|
mock_call.assert_has_calls(calls) |
85
|
|
|
|
86
|
|
|
|
87
|
|
View Code Duplication |
@patch('subprocess.call') # pylint: disable=R0904 |
|
|
|
|
88
|
|
|
class TestSubversion(BaseTestCase, unittest.TestCase): |
89
|
|
|
"""Tests for the Subversion plugin.""" |
90
|
|
|
|
91
|
|
|
DIRECTORY = '.svn' |
92
|
|
|
|
93
|
|
|
def test_lock(self, mock_call): |
94
|
|
|
"""Verify Subversion can lock files.""" |
95
|
|
|
self.lock() |
96
|
|
|
calls = [call(("svn", "update")), |
97
|
|
|
call(("svn", "lock", self.path))] |
98
|
|
|
mock_call.assert_has_calls(calls) |
99
|
|
|
|
100
|
|
|
def test_edit(self, mock_call): |
101
|
|
|
"""Verify Subversion can (fake) edit files.""" |
102
|
|
|
self.edit() |
103
|
|
|
calls = [] |
104
|
|
|
mock_call.assert_has_calls(calls) |
105
|
|
|
|
106
|
|
|
def test_add(self, mock_call): |
107
|
|
|
"""Verify Subversion can add files.""" |
108
|
|
|
self.add() |
109
|
|
|
calls = [call(("svn", "add", self.path))] |
110
|
|
|
mock_call.assert_has_calls(calls) |
111
|
|
|
|
112
|
|
|
def test_delete(self, mock_call): |
113
|
|
|
"""Verify Subversion can delete files.""" |
114
|
|
|
self.delete() |
115
|
|
|
calls = [call(("svn", "delete", self.path))] |
116
|
|
|
mock_call.assert_has_calls(calls) |
117
|
|
|
|
118
|
|
|
def test_commit(self, mock_call): |
119
|
|
|
"""Verify Subversion can commit files.""" |
120
|
|
|
self.commit() |
121
|
|
|
calls = [call(("svn", "commit", "--message", self.message))] |
122
|
|
|
mock_call.assert_has_calls(calls) |
123
|
|
|
|
124
|
|
|
|
125
|
|
View Code Duplication |
@patch('subprocess.call') # pylint: disable=R0904 |
|
|
|
|
126
|
|
|
class TestVeracity(BaseTestCase, unittest.TestCase): |
127
|
|
|
"""Tests for the Veracity plugin.""" |
128
|
|
|
|
129
|
|
|
DIRECTORY = '.sgdrawer' |
130
|
|
|
|
131
|
|
|
def test_lock(self, mock_call): |
132
|
|
|
"""Verify Veracity can lock files.""" |
133
|
|
|
self.lock() |
134
|
|
|
calls = [call(("vv", "pull")), |
135
|
|
|
call(("vv", "update"))] |
136
|
|
|
mock_call.assert_has_calls(calls) |
137
|
|
|
|
138
|
|
|
def test_edit(self, mock_call): |
139
|
|
|
"""Verify Veracity can (fake) edit files.""" |
140
|
|
|
self.edit() |
141
|
|
|
calls = [] |
142
|
|
|
mock_call.assert_has_calls(calls) |
143
|
|
|
|
144
|
|
|
def test_add(self, mock_call): |
145
|
|
|
"""Verify Veracity can add files.""" |
146
|
|
|
self.add() |
147
|
|
|
calls = [call(("vv", "add", self.path))] |
148
|
|
|
mock_call.assert_has_calls(calls) |
149
|
|
|
|
150
|
|
|
def test_delete(self, mock_call): |
151
|
|
|
"""Verify Veracity can delete files.""" |
152
|
|
|
self.delete() |
153
|
|
|
calls = [call(("vv", "remove", self.path))] |
154
|
|
|
mock_call.assert_has_calls(calls) |
155
|
|
|
|
156
|
|
|
def test_commit(self, mock_call): |
157
|
|
|
"""Verify Veracity can commit files.""" |
158
|
|
|
self.commit() |
159
|
|
|
calls = [call(("vv", "commit", "--message", self.message)), |
160
|
|
|
call(("vv", "push"))] |
161
|
|
|
mock_call.assert_has_calls(calls) |
162
|
|
|
|
163
|
|
|
|
164
|
|
View Code Duplication |
@patch('subprocess.call') # pylint: disable=R0904 |
|
|
|
|
165
|
|
|
class TestMercurial(BaseTestCase, unittest.TestCase): |
166
|
|
|
"""Tests for the Mercurial plugin.""" |
167
|
|
|
|
168
|
|
|
DIRECTORY = '.hg' |
169
|
|
|
|
170
|
|
|
def test_lock(self, mock_call): |
171
|
|
|
"""Verify Mercurial can (fake) lock files.""" |
172
|
|
|
self.lock() |
173
|
|
|
calls = [call(("hg", "pull", "-u"))] |
174
|
|
|
mock_call.assert_has_calls(calls) |
175
|
|
|
|
176
|
|
|
def test_edit(self, mock_call): |
177
|
|
|
"""Verify Mercurial can edit files.""" |
178
|
|
|
self.edit() |
179
|
|
|
calls = [call(("hg", "add", self.path))] |
180
|
|
|
mock_call.assert_has_calls(calls) |
181
|
|
|
|
182
|
|
|
def test_add(self, mock_call): |
183
|
|
|
"""Verify Mercurial can add files.""" |
184
|
|
|
self.add() |
185
|
|
|
calls = [call(("hg", "add", self.path))] |
186
|
|
|
mock_call.assert_has_calls(calls) |
187
|
|
|
|
188
|
|
|
def test_delete(self, mock_call): |
189
|
|
|
"""Verify Mercurial can delete files.""" |
190
|
|
|
self.delete() |
191
|
|
|
calls = [call(("hg", "remove", self.path, "--force"))] |
192
|
|
|
mock_call.assert_has_calls(calls) |
193
|
|
|
|
194
|
|
|
def test_commit(self, mock_call): |
195
|
|
|
"""Verify Mercurial can commit files.""" |
196
|
|
|
self.commit() |
197
|
|
|
calls = [call(("hg", "commit", "--message", self.message)), |
198
|
|
|
call(("hg", "push"))] |
199
|
|
|
mock_call.assert_has_calls(calls) |
200
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.