-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_pr_conflict_detector_main.py
More file actions
115 lines (99 loc) · 3.76 KB
/
test_pr_conflict_detector_main.py
File metadata and controls
115 lines (99 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Tests for the main orchestration flow in the PR conflict detector."""
import unittest
from unittest.mock import MagicMock, patch
from pr_conflict_detector import main
from test_helpers import _make_env_vars, _make_pr, _make_repo, _mock_dedup_passthrough
@patch("pr_conflict_detector.deduplication", new=_mock_dedup_passthrough())
@patch("pr_conflict_detector.send_slack_notification")
@patch("pr_conflict_detector.create_or_update_issue")
@patch("pr_conflict_detector.write_to_json")
@patch("pr_conflict_detector.write_to_markdown")
@patch("pr_conflict_detector.detect_conflicts")
@patch("pr_conflict_detector.fetch_all_pr_data")
@patch("pr_conflict_detector.auth.auth_to_github")
@patch("pr_conflict_detector.env.get_env_vars")
class TestMainWithOrganization(unittest.TestCase):
"""Test the main() flow using an organization."""
def test_main_with_organization(
self,
mock_get_env,
mock_auth,
mock_fetch,
mock_detect,
mock_md,
mock_json,
mock_issue,
mock_slack,
):
"""Verify main() orchestrates all steps for an organization."""
repo = _make_repo("test-org/repo-a")
env_vars = _make_env_vars()
mock_get_env.return_value = env_vars
gh = MagicMock()
mock_auth.return_value = gh
org_mock = MagicMock()
org_mock.repositories.return_value = [repo]
gh.organization.return_value = org_mock
pr1, pr2 = _make_pr(1), _make_pr(2)
mock_fetch.return_value = [pr1, pr2]
conflict = MagicMock()
mock_detect.return_value = [conflict]
mock_issue.return_value = "https://github.com/test-org/repo-a/issues/99"
main()
mock_get_env.assert_called_once()
mock_auth.assert_called_once()
mock_fetch.assert_called_once_with(
repo, True, gh, "test-org", "repo-a", filter_authors=None
)
mock_detect.assert_called_once_with(
[pr1, pr2],
verify=False,
github_connection=gh,
owner="test-org",
repo_name="repo-a",
)
mock_md.assert_called_once()
mock_json.assert_called_once()
mock_issue.assert_called_once()
mock_slack.assert_called_once()
@patch("pr_conflict_detector.deduplication", new=_mock_dedup_passthrough())
@patch("pr_conflict_detector.send_slack_notification")
@patch("pr_conflict_detector.create_or_update_issue")
@patch("pr_conflict_detector.write_to_json")
@patch("pr_conflict_detector.write_to_markdown")
@patch("pr_conflict_detector.detect_conflicts")
@patch("pr_conflict_detector.fetch_all_pr_data")
@patch("pr_conflict_detector.auth.auth_to_github")
@patch("pr_conflict_detector.env.get_env_vars")
class TestMainWithRepositoryList(unittest.TestCase):
"""Test the main() flow using a repository list."""
def test_main_with_repository_list(
self,
mock_get_env,
mock_auth,
mock_fetch,
mock_detect,
_mock_md,
_mock_json,
mock_issue,
_mock_slack,
):
"""Verify main() orchestrates all steps for a repository list."""
env_vars = _make_env_vars(
organization=None,
repository_list=["owner/repo-x"],
)
mock_get_env.return_value = env_vars
gh = MagicMock()
mock_auth.return_value = gh
repo = _make_repo("owner/repo-x")
gh.repository.return_value = repo
pr1, pr2 = _make_pr(1), _make_pr(2)
mock_fetch.return_value = [pr1, pr2]
mock_detect.return_value = []
main()
gh.repository.assert_called_once_with("owner", "repo-x")
mock_fetch.assert_called_once()
mock_detect.assert_called_once()
# No conflicts → no issue created
mock_issue.assert_not_called()