|
7 | 7 | from collections import OrderedDict
|
8 | 8 | from contextlib import contextmanager
|
9 | 9 | from types import SimpleNamespace
|
10 |
| -from unittest.mock import MagicMock, call, patch |
| 10 | +from unittest.mock import ANY, MagicMock, call, patch |
11 | 11 |
|
12 | 12 | from invoke import Context, MockContext, Result
|
13 | 13 | from invoke.exceptions import Exit
|
@@ -1165,3 +1165,112 @@ def test_100_tags(self):
|
1165 | 1165 | mock_modules.return_value = mock_dict
|
1166 | 1166 | release.tag_modules(c, version="version")
|
1167 | 1167 | self.assertEqual(c.run.call_count, 34)
|
| 1168 | + |
| 1169 | + |
| 1170 | +class TestTagVersion(unittest.TestCase): |
| 1171 | + @patch('tasks.release.__tag_single_module') |
| 1172 | + @patch('tasks.release.push_tags_in_batches') |
| 1173 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1174 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=False)) |
| 1175 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1176 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1177 | + def test_not_in_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1178 | + c = MockContext(run=Result("yolo")) |
| 1179 | + rc_version = "6.53.5-rc.2" |
| 1180 | + release.tag_version(c, start_qual=False, version=rc_version) |
| 1181 | + tag_single_module_mock.assert_called_with(c, ANY, rc_version, ANY, ANY, ANY) |
| 1182 | + assert tag_single_module_mock.call_count == 1 |
| 1183 | + assert push_tags_in_batches_mock.call_count == 1 |
| 1184 | + |
| 1185 | + @patch('tasks.release.__tag_single_module') |
| 1186 | + @patch('tasks.release.push_tags_in_batches') |
| 1187 | + @patch('time.time', new=MagicMock(return_value=1234)) |
| 1188 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1189 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=False)) |
| 1190 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1191 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1192 | + def test_start_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1193 | + c = MockContext(run=Result("yolo")) |
| 1194 | + rc_version = "6.53.5-rc.2" |
| 1195 | + release.tag_version(c, start_qual=True, version=rc_version) |
| 1196 | + calls = tag_single_module_mock.call_args_list |
| 1197 | + calls[0].assert_called_with(c, ANY, rc_version, ANY, ANY, ANY) |
| 1198 | + calls[1].assert_called_with(c, ANY, "qualification-1234", ANY, ANY, ANY) |
| 1199 | + assert tag_single_module_mock.call_count == 2 |
| 1200 | + assert push_tags_in_batches_mock.call_count == 1 |
| 1201 | + |
| 1202 | + @patch('tasks.release.__tag_single_module') |
| 1203 | + @patch('tasks.release.push_tags_in_batches') |
| 1204 | + @patch('time.time', new=MagicMock(return_value=2345)) |
| 1205 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1206 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=True)) |
| 1207 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1208 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1209 | + def test_during_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1210 | + c = MockContext(run=Result("yolo")) |
| 1211 | + rc_version = "6.53.5-rc.3" |
| 1212 | + release.tag_version(c, start_qual=False, version=rc_version) |
| 1213 | + calls = tag_single_module_mock.call_args_list |
| 1214 | + calls[0].assert_called_with(c, ANY, rc_version, ANY, ANY, ANY) |
| 1215 | + calls[1].assert_called_with(c, ANY, "qualification-2345", ANY, ANY, ANY) |
| 1216 | + assert tag_single_module_mock.call_count == 2 |
| 1217 | + assert push_tags_in_batches_mock.call_count == 1 |
| 1218 | + |
| 1219 | + @patch('tasks.release.__tag_single_module') |
| 1220 | + @patch('tasks.release.push_tags_in_batches') |
| 1221 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1222 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=True)) |
| 1223 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1224 | + @patch('tasks.release.get_qualification_tags', new=MagicMock()) |
| 1225 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1226 | + def test_end_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1227 | + c = MockContext(run=Result("yolo")) |
| 1228 | + final_release_version = "6.53.5" |
| 1229 | + release.tag_version(c, start_qual=False, version=final_release_version) |
| 1230 | + tag_single_module_mock.assert_called_with(c, ANY, final_release_version, ANY, ANY, ANY) |
| 1231 | + assert tag_single_module_mock.call_count == 1 |
| 1232 | + assert push_tags_in_batches_mock.call_count == 2 |
| 1233 | + |
| 1234 | + |
| 1235 | +class TestGetQualificationTags(unittest.TestCase): |
| 1236 | + @patch('tasks.release.qualification_tag_query') |
| 1237 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1238 | + def test_returns_all_tags(self, qualification_tag_query_mock): |
| 1239 | + c = MockContext(run=Result("yolo")) |
| 1240 | + qualification_tag_query_mock.return_value = ['hash2\tqualification_2345^{}', 'hash1\tqualification_1234^{}'] |
| 1241 | + tags = release.get_qualification_tags(c, "6.53.x") |
| 1242 | + qualification_tag_query_mock.assert_called_with(c, "6.53.x", sort=True) |
| 1243 | + assert tags == [['hash2', 'qualification_2345'], ['hash1', 'qualification_1234']] |
| 1244 | + self.assertEqual(len(tags), 2) |
| 1245 | + |
| 1246 | + @patch('tasks.release.qualification_tag_query') |
| 1247 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1248 | + def test_returns_only_one_tag(self, qualification_tag_query_mock): |
| 1249 | + c = MockContext(run=Result("yolo")) |
| 1250 | + qualification_tag_query_mock.return_value = ['hash2\tqualification_2345^{}', 'hash1\tqualification_1234^{}'] |
| 1251 | + tags = release.get_qualification_tags(c, "6.53.x", latest_tag=True) |
| 1252 | + qualification_tag_query_mock.assert_called_with(c, "6.53.x", sort=True) |
| 1253 | + assert tags == [['hash2', 'qualification_2345']] |
| 1254 | + self.assertEqual(len(tags), 1) |
| 1255 | + |
| 1256 | + |
| 1257 | +class TestIsQualification(unittest.TestCase): |
| 1258 | + @patch('builtins.print') |
| 1259 | + @patch('tasks.release.qualification_tag_query', new=MagicMock(return_value="hash1\tqualification_1234")) |
| 1260 | + def test_is_qualification(self, print_mock): |
| 1261 | + c = MockContext(run=Result("yolo")) |
| 1262 | + self.assertTrue(release.is_qualification(c, "6.53.x")) |
| 1263 | + assert print_mock.call_count == 0 |
| 1264 | + self.assertTrue(release.is_qualification(c, "6.53.x", output=True)) |
| 1265 | + print_mock.assert_called_with("true") |
| 1266 | + assert print_mock.call_count == 1 |
| 1267 | + |
| 1268 | + @patch('builtins.print') |
| 1269 | + @patch('tasks.release.qualification_tag_query', new=MagicMock(return_value=None)) |
| 1270 | + def test_is_not_qualification(self, print_mock): |
| 1271 | + c = MockContext(run=Result("yolo")) |
| 1272 | + self.assertFalse(release.is_qualification(c, "6.53.x")) |
| 1273 | + assert print_mock.call_count == 0 |
| 1274 | + self.assertFalse(release.is_qualification(c, "6.53.x", output=True)) |
| 1275 | + print_mock.assert_called_with("false") |
| 1276 | + assert print_mock.call_count == 1 |
0 commit comments