Skip to content

Commit 087693f

Browse files
authored
test: 移除 should_call_apis (#448)
与 inline-snapshot 有冲突,现在通过大模型也能很方便的写测试了,不如直接删掉。
1 parent caa06ef commit 087693f

29 files changed

+3355
-2703
lines changed

tests/plugins/github/config/process/test_config_auto_merge.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
assert_subprocess_run_calls,
88
get_github_bot,
99
mock_subprocess_run_with_side_effect,
10-
should_call_apis,
1110
)
1211

1312

@@ -48,32 +47,25 @@ async def test_config_auto_merge(
4847
event = get_mock_event(PullRequestReviewSubmitted)
4948
event.payload.pull_request.labels = get_issue_labels(["Config", "Plugin"])
5049

51-
should_call_apis(
52-
ctx,
53-
[
54-
{
55-
"api": "rest.apps.async_get_repo_installation",
56-
"result": mock_installation,
57-
},
58-
{
59-
"api": "rest.apps.async_create_installation_access_token",
60-
"result": mock_installation_token,
61-
},
62-
{
63-
"api": "rest.pulls.async_merge",
64-
"result": True,
65-
},
66-
],
67-
[
68-
{"owner": "he0119", "repo": "action-test"},
69-
{"installation_id": mock_installation.parsed_data.id},
70-
{
71-
"owner": "he0119",
72-
"repo": "action-test",
73-
"pull_number": 100,
74-
"merge_method": "rebase",
75-
},
76-
],
50+
ctx.should_call_api(
51+
"rest.apps.async_get_repo_installation",
52+
{"owner": "he0119", "repo": "action-test"},
53+
mock_installation,
54+
)
55+
ctx.should_call_api(
56+
"rest.apps.async_create_installation_access_token",
57+
{"installation_id": mock_installation.parsed_data.id},
58+
mock_installation_token,
59+
)
60+
ctx.should_call_api(
61+
"rest.pulls.async_merge",
62+
{
63+
"owner": "he0119",
64+
"repo": "action-test",
65+
"pull_number": 100,
66+
"merge_method": "rebase",
67+
},
68+
True,
7769
)
7870

7971
ctx.receive_event(bot, event)

tests/plugins/github/config/process/test_config_check.py

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
from tests.plugins.github.config.utils import generate_issue_body
1111
from tests.plugins.github.event import get_mock_event
1212
from tests.plugins.github.utils import (
13-
GitHubApi,
1413
MockIssue,
1514
assert_subprocess_run_calls,
1615
check_json_data,
1716
get_github_bot,
1817
get_issue_labels,
1918
mock_subprocess_run_with_side_effect,
20-
should_call_apis,
2119
)
2220

2321

@@ -113,55 +111,23 @@ async def test_process_config_check(
113111
event = get_mock_event(IssuesOpened)
114112
event.payload.issue.labels = get_config_labels()
115113

116-
# 定义要调用的 API 列表
117-
apis: list[GitHubApi] = [
118-
{
119-
"api": "rest.apps.async_get_repo_installation",
120-
"result": mock_installation,
121-
},
122-
{
123-
"api": "rest.apps.async_create_installation_access_token",
124-
"result": mock_installation_token,
125-
},
126-
{
127-
"api": "rest.issues.async_get",
128-
"result": mock_issues_resp,
129-
},
130-
{
131-
"api": "rest.issues.async_update",
132-
"result": None,
133-
},
134-
{
135-
"api": "rest.issues.async_list_comments",
136-
"result": mock_list_comments_resp,
137-
},
138-
{
139-
"api": "rest.issues.async_update_comment",
140-
"result": True,
141-
},
142-
{
143-
"api": "rest.issues.async_update",
144-
"result": None,
145-
},
146-
{
147-
"api": "rest.pulls.async_create",
148-
"result": mock_pull_resp,
149-
},
150-
{
151-
"api": "rest.issues.async_add_labels",
152-
"result": None,
153-
},
154-
{
155-
"api": "rest.issues.async_update",
156-
"result": None,
157-
},
158-
]
159-
160-
# 对应的 API 数据
161-
api_data = [
114+
ctx.should_call_api(
115+
"rest.apps.async_get_repo_installation",
162116
{"owner": "he0119", "repo": "action-test"},
117+
mock_installation,
118+
)
119+
ctx.should_call_api(
120+
"rest.apps.async_create_installation_access_token",
163121
{"installation_id": mock_installation.parsed_data.id},
122+
mock_installation_token,
123+
)
124+
ctx.should_call_api(
125+
"rest.issues.async_get",
164126
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
127+
mock_issues_resp,
128+
)
129+
ctx.should_call_api(
130+
"rest.issues.async_update",
165131
snapshot(
166132
{
167133
"owner": "he0119",
@@ -188,7 +154,15 @@ async def test_process_config_check(
188154
""",
189155
}
190156
),
157+
None,
158+
)
159+
ctx.should_call_api(
160+
"rest.issues.async_list_comments",
191161
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
162+
mock_list_comments_resp,
163+
)
164+
ctx.should_call_api(
165+
"rest.issues.async_update_comment",
192166
snapshot(
193167
{
194168
"owner": "he0119",
@@ -225,6 +199,10 @@ async def test_process_config_check(
225199
""",
226200
}
227201
),
202+
True,
203+
)
204+
ctx.should_call_api(
205+
"rest.issues.async_update",
228206
snapshot(
229207
{
230208
"owner": "he0119",
@@ -233,6 +211,10 @@ async def test_process_config_check(
233211
"title": "Plugin: name",
234212
}
235213
),
214+
None,
215+
)
216+
ctx.should_call_api(
217+
"rest.pulls.async_create",
236218
snapshot(
237219
{
238220
"owner": "he0119",
@@ -243,6 +225,10 @@ async def test_process_config_check(
243225
"head": "config/issue80",
244226
}
245227
),
228+
mock_pull_resp,
229+
)
230+
ctx.should_call_api(
231+
"rest.issues.async_add_labels",
246232
snapshot(
247233
{
248234
"owner": "he0119",
@@ -251,6 +237,10 @@ async def test_process_config_check(
251237
"labels": ["Plugin", "Config"],
252238
}
253239
),
240+
None,
241+
)
242+
ctx.should_call_api(
243+
"rest.issues.async_update",
254244
snapshot(
255245
{
256246
"owner": "he0119",
@@ -277,10 +267,8 @@ async def test_process_config_check(
277267
""",
278268
}
279269
),
280-
]
281-
282-
# 使用辅助函数调用 API
283-
should_call_apis(ctx, apis, api_data)
270+
None,
271+
)
284272

285273
ctx.receive_event(bot, event) # 测试 git 命令
286274

tests/plugins/github/config/process/test_config_pull_request.py

Lines changed: 55 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
assert_subprocess_run_calls,
1313
get_github_bot,
1414
mock_subprocess_run_with_side_effect,
15-
should_call_apis,
1615
)
1716

1817

@@ -45,43 +44,36 @@ async def test_config_process_pull_request(
4544
event.payload.pull_request.labels = get_pr_labels(["Config", "Plugin"])
4645
event.payload.pull_request.merged = True
4746

48-
should_call_apis(
49-
ctx,
50-
[
51-
{
52-
"api": "rest.apps.async_get_repo_installation",
53-
"result": mock_installation,
54-
},
55-
{
56-
"api": "rest.apps.async_create_installation_access_token",
57-
"result": mock_installation_token,
58-
},
59-
{
60-
"api": "rest.issues.async_get",
61-
"result": mock_issues_resp,
62-
},
63-
{
64-
"api": "rest.issues.async_update",
65-
"result": True,
66-
},
67-
{
68-
"api": "rest.pulls.async_list",
69-
"result": mock_pulls_resp,
70-
},
71-
],
72-
[
73-
{"owner": "he0119", "repo": "action-test"},
74-
{"installation_id": mock_installation.parsed_data.id},
75-
{"owner": "he0119", "repo": "action-test", "issue_number": 76},
76-
{
77-
"owner": "he0119",
78-
"repo": "action-test",
79-
"issue_number": 80,
80-
"state": "closed",
81-
"state_reason": "completed",
82-
},
83-
{"owner": "he0119", "repo": "action-test", "state": "open"},
84-
],
47+
ctx.should_call_api(
48+
"rest.apps.async_get_repo_installation",
49+
{"owner": "he0119", "repo": "action-test"},
50+
mock_installation,
51+
)
52+
ctx.should_call_api(
53+
"rest.apps.async_create_installation_access_token",
54+
{"installation_id": mock_installation.parsed_data.id},
55+
mock_installation_token,
56+
)
57+
ctx.should_call_api(
58+
"rest.issues.async_get",
59+
{"owner": "he0119", "repo": "action-test", "issue_number": 76},
60+
mock_issues_resp,
61+
)
62+
ctx.should_call_api(
63+
"rest.issues.async_update",
64+
{
65+
"owner": "he0119",
66+
"repo": "action-test",
67+
"issue_number": 80,
68+
"state": "closed",
69+
"state_reason": "completed",
70+
},
71+
True,
72+
)
73+
ctx.should_call_api(
74+
"rest.pulls.async_list",
75+
{"owner": "he0119", "repo": "action-test", "state": "open"},
76+
mock_pulls_resp,
8577
)
8678
ctx.receive_event(bot, event)
8779

@@ -133,38 +125,31 @@ async def test_process_config_pull_request_not_merged(
133125
event = get_mock_event(PullRequestClosed)
134126
event.payload.pull_request.labels = get_pr_labels(["Config", "Plugin"])
135127

136-
should_call_apis(
137-
ctx,
138-
[
139-
{
140-
"api": "rest.apps.async_get_repo_installation",
141-
"result": mock_installation,
142-
},
143-
{
144-
"api": "rest.apps.async_create_installation_access_token",
145-
"result": mock_installation_token,
146-
},
147-
{
148-
"api": "rest.issues.async_get",
149-
"result": mock_issues_resp,
150-
},
151-
{
152-
"api": "rest.issues.async_update",
153-
"result": True,
154-
},
155-
],
156-
[
157-
{"owner": "he0119", "repo": "action-test"},
158-
{"installation_id": mock_installation.parsed_data.id},
159-
{"owner": "he0119", "repo": "action-test", "issue_number": 76},
160-
{
161-
"owner": "he0119",
162-
"repo": "action-test",
163-
"issue_number": 80,
164-
"state": "closed",
165-
"state_reason": "not_planned",
166-
},
167-
],
128+
ctx.should_call_api(
129+
"rest.apps.async_get_repo_installation",
130+
{"owner": "he0119", "repo": "action-test"},
131+
mock_installation,
132+
)
133+
ctx.should_call_api(
134+
"rest.apps.async_create_installation_access_token",
135+
{"installation_id": mock_installation.parsed_data.id},
136+
mock_installation_token,
137+
)
138+
ctx.should_call_api(
139+
"rest.issues.async_get",
140+
{"owner": "he0119", "repo": "action-test", "issue_number": 76},
141+
mock_issues_resp,
142+
)
143+
ctx.should_call_api(
144+
"rest.issues.async_update",
145+
{
146+
"owner": "he0119",
147+
"repo": "action-test",
148+
"issue_number": 80,
149+
"state": "closed",
150+
"state_reason": "not_planned",
151+
},
152+
True,
168153
)
169154

170155
ctx.receive_event(bot, event)

0 commit comments

Comments
 (0)