|
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
|
@@ -1075,3 +1075,110 @@ def test_100_tags(self):
|
1075 | 1075 | mock_modules.return_value = mock_dict
|
1076 | 1076 | release.tag_modules(c, version="version")
|
1077 | 1077 | self.assertEqual(c.run.call_count, 34)
|
| 1078 | + |
| 1079 | + |
| 1080 | +class TestTagVersion(unittest.TestCase): |
| 1081 | + c = MockContext(run=Result("yolo")) |
| 1082 | + |
| 1083 | + @patch('tasks.release.__tag_single_module') |
| 1084 | + @patch('tasks.release.push_tags_in_batches') |
| 1085 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1086 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=False)) |
| 1087 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1088 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1089 | + def test_not_in_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1090 | + rc_version = "6.53.5-rc.2" |
| 1091 | + release.tag_version(self.c, start_qual=False, version=rc_version) |
| 1092 | + tag_single_module_mock.assert_called_with(self.c, ANY, rc_version, ANY, ANY, ANY) |
| 1093 | + assert tag_single_module_mock.call_count == 1 |
| 1094 | + assert push_tags_in_batches_mock.call_count == 1 |
| 1095 | + |
| 1096 | + @patch('tasks.release.__tag_single_module') |
| 1097 | + @patch('tasks.release.push_tags_in_batches') |
| 1098 | + @patch('time.time', new=MagicMock(return_value=1234)) |
| 1099 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1100 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=False)) |
| 1101 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1102 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1103 | + def test_start_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1104 | + rc_version = "6.53.5-rc.2" |
| 1105 | + release.tag_version(self.c, start_qual=True, version=rc_version) |
| 1106 | + calls = tag_single_module_mock.call_args_list |
| 1107 | + calls[0].assert_called_with(self.c, ANY, rc_version, ANY, ANY, ANY) |
| 1108 | + calls[1].assert_called_with(self.c, ANY, "qualification-1234", ANY, ANY, ANY) |
| 1109 | + assert tag_single_module_mock.call_count == 2 |
| 1110 | + assert push_tags_in_batches_mock.call_count == 1 |
| 1111 | + |
| 1112 | + @patch('tasks.release.__tag_single_module') |
| 1113 | + @patch('tasks.release.push_tags_in_batches') |
| 1114 | + @patch('time.time', new=MagicMock(return_value=2345)) |
| 1115 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1116 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=True)) |
| 1117 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1118 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1119 | + def test_during_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1120 | + rc_version = "6.53.5-rc.3" |
| 1121 | + release.tag_version(self.c, start_qual=False, version=rc_version) |
| 1122 | + calls = tag_single_module_mock.call_args_list |
| 1123 | + calls[0].assert_called_with(self.c, ANY, rc_version, ANY, ANY, ANY) |
| 1124 | + calls[1].assert_called_with(self.c, ANY, "qualification-2345", ANY, ANY, ANY) |
| 1125 | + assert tag_single_module_mock.call_count == 2 |
| 1126 | + assert push_tags_in_batches_mock.call_count == 1 |
| 1127 | + |
| 1128 | + @patch('tasks.release.__tag_single_module') |
| 1129 | + @patch('tasks.release.push_tags_in_batches') |
| 1130 | + @patch('tasks.release.is_agent6', new=MagicMock(return_value=True)) |
| 1131 | + @patch('tasks.release.is_qualification', new=MagicMock(return_value=True)) |
| 1132 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1133 | + @patch('tasks.release.get_qualification_tags', new=MagicMock()) |
| 1134 | + @patch.dict(os.environ, {'GITLAB_CI': 'false', 'GITHUB_ACTIONS': 'false'}) |
| 1135 | + def test_end_qualification_phase(self, push_tags_in_batches_mock, tag_single_module_mock): |
| 1136 | + final_release_version = "6.53.5" |
| 1137 | + release.tag_version(self.c, start_qual=False, version=final_release_version) |
| 1138 | + tag_single_module_mock.assert_called_with(self.c, ANY, final_release_version, ANY, ANY, ANY) |
| 1139 | + assert tag_single_module_mock.call_count == 1 |
| 1140 | + assert push_tags_in_batches_mock.call_count == 2 |
| 1141 | + |
| 1142 | + |
| 1143 | +class TestGetQualificationTags(unittest.TestCase): |
| 1144 | + c = MockContext(run=Result("yolo")) |
| 1145 | + |
| 1146 | + @patch('tasks.release.qualification_tag_query') |
| 1147 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1148 | + def test_returns_all_tags(self, qualification_tag_query_mock): |
| 1149 | + qualification_tag_query_mock.return_value = ['hash2\tqualification_2345^{}', 'hash1\tqualification_1234^{}'] |
| 1150 | + tags = release.get_qualification_tags(self.c, "6.53.x") |
| 1151 | + qualification_tag_query_mock.assert_called_with(self.c, "6.53.x", sort=True) |
| 1152 | + assert tags == [['hash2', 'qualification_2345'], ['hash1', 'qualification_1234']] |
| 1153 | + self.assertEqual(len(tags), 2) |
| 1154 | + |
| 1155 | + @patch('tasks.release.qualification_tag_query') |
| 1156 | + @patch('tasks.release.agent_context', new=MagicMock()) |
| 1157 | + def test_returns_only_one_tag(self, qualification_tag_query_mock): |
| 1158 | + qualification_tag_query_mock.return_value = ['hash2\tqualification_2345^{}', 'hash1\tqualification_1234^{}'] |
| 1159 | + tags = release.get_qualification_tags(self.c, "6.53.x", latest_tag=True) |
| 1160 | + qualification_tag_query_mock.assert_called_with(self.c, "6.53.x", sort=True) |
| 1161 | + assert tags == [['hash2', 'qualification_2345']] |
| 1162 | + self.assertEqual(len(tags), 1) |
| 1163 | + |
| 1164 | + |
| 1165 | +class TestIsQualification(unittest.TestCase): |
| 1166 | + c = MockContext(run=Result("yolo")) |
| 1167 | + |
| 1168 | + @patch('builtins.print') |
| 1169 | + @patch('tasks.release.qualification_tag_query', new=MagicMock(return_value="hash1\tqualification_1234")) |
| 1170 | + def test_is_qualification(self, print_mock): |
| 1171 | + self.assertTrue(release.is_qualification(self.c, "6.53.x")) |
| 1172 | + assert print_mock.call_count == 0 |
| 1173 | + self.assertTrue(release.is_qualification(self.c, "6.53.x", output=True)) |
| 1174 | + print_mock.assert_called_with("true") |
| 1175 | + assert print_mock.call_count == 1 |
| 1176 | + |
| 1177 | + @patch('builtins.print') |
| 1178 | + @patch('tasks.release.qualification_tag_query', new=MagicMock(return_value=None)) |
| 1179 | + def test_is_not_qualification(self, print_mock): |
| 1180 | + self.assertFalse(release.is_qualification(self.c, "6.53.x")) |
| 1181 | + assert print_mock.call_count == 0 |
| 1182 | + self.assertFalse(release.is_qualification(self.c, "6.53.x", output=True)) |
| 1183 | + print_mock.assert_called_with("false") |
| 1184 | + assert print_mock.call_count == 1 |
0 commit comments