|
17 | 17 | from kernel_patches_daemon.branch_worker import NewPRWithNoChangeException |
18 | 18 | from kernel_patches_daemon.config import KPDConfig |
19 | 19 | from kernel_patches_daemon.github_sync import GithubSync, HEAD_BASE_SEPARATOR |
20 | | -from tests.common.patchwork_mock import init_pw_responses, load_test_data, PatchworkMock |
| 20 | +from tests.common.patchwork_mock import ( |
| 21 | + init_pw_responses, |
| 22 | + load_test_data, |
| 23 | + PatchworkMock, |
| 24 | +) |
21 | 25 |
|
22 | 26 | TEST_BRANCH = "test-branch" |
23 | 27 | TEST_BPF_NEXT_BRANCH = "test-bpf-next" |
@@ -278,6 +282,43 @@ async def test_sync_relevant_subject_success_second_branch(self) -> None: |
278 | 282 | list(self._gh.workers.values()), pr_mock |
279 | 283 | ) |
280 | 284 |
|
| 285 | + def _setup_test_select_target_branches_for_subject(self): |
| 286 | + series_prefix = "series/123123" |
| 287 | + subject_mock = MagicMock() |
| 288 | + subject_mock.subject = "Test subject" |
| 289 | + subject_mock.branch = AsyncMock(return_value=series_prefix) |
| 290 | + |
| 291 | + pr_mock = MagicMock() |
| 292 | + pr_mock.head.ref = f"{series_prefix}{HEAD_BASE_SEPARATOR}{TEST_BPF_NEXT_BRANCH}" |
| 293 | + |
| 294 | + worker_mock = self._gh.workers[TEST_BPF_NEXT_BRANCH] |
| 295 | + worker_mock.prs = {subject_mock.subject: pr_mock} |
| 296 | + |
| 297 | + return subject_mock, pr_mock |
| 298 | + |
| 299 | + async def test_select_target_branches_for_subject(self) -> None: |
| 300 | + subject_mock, _ = self._setup_test_select_target_branches_for_subject() |
| 301 | + mapped_branches = [TEST_BRANCH, TEST_BPF_NEXT_BRANCH] |
| 302 | + |
| 303 | + selected_branches = await self._gh.select_target_branches_for_subject( |
| 304 | + subject_mock, mapped_branches |
| 305 | + ) |
| 306 | + |
| 307 | + self.assertEqual(selected_branches, [TEST_BPF_NEXT_BRANCH]) |
| 308 | + |
| 309 | + async def test_select_target_branches_for_subject_merge_conflict(self) -> None: |
| 310 | + subject_mock, pr_mock = self._setup_test_select_target_branches_for_subject() |
| 311 | + label = MagicMock() |
| 312 | + label.name = "merge-conflict" |
| 313 | + pr_mock.get_labels = MagicMock(return_value=[label]) |
| 314 | + mapped_branches = [TEST_BRANCH, TEST_BPF_NEXT_BRANCH] |
| 315 | + |
| 316 | + selected_branches = await self._gh.select_target_branches_for_subject( |
| 317 | + subject_mock, mapped_branches |
| 318 | + ) |
| 319 | + |
| 320 | + self.assertEqual(selected_branches, mapped_branches) |
| 321 | + |
281 | 322 | @aioresponses() |
282 | 323 | async def test_sync_patches_pr_summary_success(self, m: aioresponses) -> None: |
283 | 324 | """ |
|
0 commit comments