|
a/Allura/allura/tests/unit/test_repo.py |
|
b/Allura/allura/tests/unit/test_repo.py |
|
... |
|
... |
101 |
b.name = name
|
101 |
b.name = name
|
102 |
b.id = id
|
102 |
b.id = id
|
103 |
return b
|
103 |
return b
|
104 |
|
104 |
|
105 |
|
105 |
|
106 |
class TestRefreshLastCommit(unittest.TestCase):
|
|
|
107 |
@patch('allura.model.repo_refresh.TreeDoc.m.get')
|
|
|
108 |
@patch('allura.model.repo_refresh.set_last_commit')
|
|
|
109 |
def test_no_changes(self, set_last_commit, get):
|
|
|
110 |
repo_id = 'repo_1'
|
|
|
111 |
path = '/'
|
|
|
112 |
lhs_tree = tree('lhs_tree', 'tid1')
|
|
|
113 |
rhs_tree = tree('rhs_tree', 'tid1')
|
|
|
114 |
parent_tree = Mock()
|
|
|
115 |
commit_info = {}
|
|
|
116 |
|
|
|
117 |
M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
|
|
|
118 |
|
|
|
119 |
self.assertEqual(set_last_commit.call_count, 0)
|
|
|
120 |
self.assertEqual(get.call_count, 0)
|
|
|
121 |
|
|
|
122 |
@patch('allura.model.repo_refresh.TreeDoc.m.get')
|
|
|
123 |
@patch('allura.model.repo_refresh.set_last_commit')
|
|
|
124 |
def test_unchanged_blob(self, set_last_commit, get):
|
|
|
125 |
repo_id = 'repo_1'
|
|
|
126 |
path = '/'
|
|
|
127 |
lhs_tree = tree('lhs_tree', 'tid1', blobs=[blob('unchanged_blob', 'bid1')])
|
|
|
128 |
rhs_tree = tree('rhs_tree', 'tid2', blobs=[blob('unchanged_blob', 'bid1')])
|
|
|
129 |
parent_tree = Mock()
|
|
|
130 |
commit_info = {}
|
|
|
131 |
|
|
|
132 |
M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
|
|
|
133 |
|
|
|
134 |
self.assertEqual(set_last_commit.call_count, 0)
|
|
|
135 |
self.assertEqual(get.call_count, 0)
|
|
|
136 |
|
|
|
137 |
@patch('allura.model.repo_refresh.TreeDoc.m.get')
|
|
|
138 |
@patch('allura.model.repo_refresh.set_last_commit')
|
|
|
139 |
def test_changed_blob(self, set_last_commit, get):
|
|
|
140 |
repo_id = 'repo_1'
|
|
|
141 |
path = '/'
|
|
|
142 |
lhs_tree = tree('lhs_tree', 'tid1', blobs=[blob('changed_blob', 'bid1')])
|
|
|
143 |
rhs_tree = tree('rhs_tree', 'tid2', blobs=[blob('changed_blob', 'bid2')])
|
|
|
144 |
parent_tree = Mock()
|
|
|
145 |
commit_info = {'author': 'Testy'}
|
|
|
146 |
|
|
|
147 |
M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
|
|
|
148 |
|
|
|
149 |
set_last_commit.assert_called_once_with(repo_id, path, 'changed_blob', 'bid2', commit_info)
|
|
|
150 |
self.assertEqual(get.call_count, 0)
|
|
|
151 |
|
|
|
152 |
@patch('allura.model.repo_refresh.TreeDoc.m.get')
|
|
|
153 |
@patch('allura.model.repo_refresh.set_last_commit')
|
|
|
154 |
def test_new_blob(self, set_last_commit, get):
|
|
|
155 |
repo_id = 'repo_1'
|
|
|
156 |
path = '/'
|
|
|
157 |
lhs_tree = tree('lhs_tree', 'tid1', blobs=[blob('old_blob', 'bid1')])
|
|
|
158 |
rhs_tree = tree('rhs_tree', 'tid2', blobs=[blob('new_blob', 'bid2')])
|
|
|
159 |
parent_tree = Mock()
|
|
|
160 |
commit_info = {'author': 'Testy'}
|
|
|
161 |
|
|
|
162 |
M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
|
|
|
163 |
|
|
|
164 |
set_last_commit.assert_called_once_with(repo_id, path, 'new_blob', 'bid2', commit_info)
|
|
|
165 |
self.assertEqual(get.call_count, 0)
|
|
|
166 |
|
|
|
167 |
@patch('allura.model.repo_refresh.TreeDoc.m.get')
|
|
|
168 |
@patch('allura.model.repo_refresh.set_last_commit')
|
|
|
169 |
def test_unchanged_subtree(self, set_last_commit, get):
|
|
|
170 |
repo_id = 'repo_1'
|
|
|
171 |
path = '/'
|
|
|
172 |
lhs_tree = tree('lhs_tree', 'tid1', trees=[tree('unchanged_tree', 'tid3')])
|
|
|
173 |
rhs_tree = tree('rhs_tree', 'tid2', trees=[tree('unchanged_tree', 'tid3', blobs=[blob('new_blob', 'bid1')])])
|
|
|
174 |
parent_tree = Mock()
|
|
|
175 |
commit_info = {'author': 'Testy'}
|
|
|
176 |
get.side_effect = [rhs_tree.tree_ids[0], lhs_tree.tree_ids[0]]
|
|
|
177 |
|
|
|
178 |
M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
|
|
|
179 |
|
|
|
180 |
self.assertEqual(set_last_commit.call_count, 0)
|
|
|
181 |
self.assertEqual(get.call_count, 2)
|
|
|
182 |
self.assertEqual(get.call_args_list, [[{'_id': 'tid3'}], [{'_id': 'tid3'}]])
|
|
|
183 |
|
|
|
184 |
@patch('allura.model.repo_refresh.TreeDoc.m.get')
|
|
|
185 |
@patch('allura.model.repo_refresh.set_last_commit')
|
|
|
186 |
def test_changed_subtree(self, set_last_commit, get):
|
|
|
187 |
repo_id = 'repo_1'
|
|
|
188 |
path = '/'
|
|
|
189 |
lhs_tree = tree('lhs_tree', 'tid1', trees=[tree('changed_tree', 'tid3')])
|
|
|
190 |
rhs_tree = tree('rhs_tree', 'tid2', trees=[tree('changed_tree', 'tid4', blobs=[blob('new_blob', 'bid1')])])
|
|
|
191 |
parent_tree = Mock()
|
|
|
192 |
commit_info = {'author': 'Testy'}
|
|
|
193 |
get.side_effect = [rhs_tree.tree_ids[0], lhs_tree.tree_ids[0]]
|
|
|
194 |
|
|
|
195 |
M.repo_refresh.refresh_last_commit(repo_id, path, rhs_tree, lhs_tree, parent_tree, commit_info)
|
|
|
196 |
|
|
|
197 |
self.assertEqual(set_last_commit.call_count, 2)
|
|
|
198 |
self.assertEqual(set_last_commit.call_args_list, [
|
|
|
199 |
[(repo_id, '/', 'changed_tree', 'tid4', commit_info)],
|
|
|
200 |
[(repo_id, '/changed_tree/', 'new_blob', 'bid1', commit_info)],
|
|
|
201 |
])
|
|
|
202 |
self.assertEqual(get.call_count, 2)
|
|
|
203 |
self.assertEqual(get.call_args_list, [[{'_id': 'tid4'}], [{'_id': 'tid3'}]])
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
class TestTree(unittest.TestCase):
|
106 |
class TestTree(unittest.TestCase):
|
207 |
|
107 |
|
208 |
@patch('allura.model.repo.Tree.__getitem__')
|
108 |
@patch('allura.model.repo.Tree.__getitem__')
|
209 |
def test_get_obj_by_path(self, getitem):
|
109 |
def test_get_obj_by_path(self, getitem):
|
210 |
tree = M.repo.Tree()
|
110 |
tree = M.repo.Tree()
|