-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtest_delete_branch.py
More file actions
102 lines (84 loc) Β· 3.21 KB
/
test_delete_branch.py
File metadata and controls
102 lines (84 loc) Β· 3.21 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
import os
from unittest import mock
from gidgethub import sansio
import pytest
os.environ.setdefault("REDIS_URL", "redis://localhost")
from miss_islington import delete_branch, tasks
class FakeGH:
pass
async def test_branch_deletion_queued_when_pr_merged():
data = {
"action": "closed",
"pull_request": {
"number": 5722,
"user": {"login": "miss-islington"},
"merged": True,
"head": {"ref": "backport-17ab8f0-3.7"},
"url": "https://api.github.com/repos/python/cpython/pulls/5722",
},
"installation": {"id": 123},
}
event = sansio.Event(data, event="pull_request", delivery_id="1")
gh = FakeGH()
with mock.patch.object(tasks.delete_branch_task, "delay") as mock_delay:
await delete_branch.router.dispatch(event, gh)
mock_delay.assert_called_once_with(
"backport-17ab8f0-3.7",
"https://api.github.com/repos/python/cpython/pulls/5722",
True,
installation_id=123
)
async def test_branch_deletion_queued_when_pr_closed_not_merged():
data = {
"action": "closed",
"pull_request": {
"number": 5722,
"user": {"login": "miss-islington"},
"merged": False,
"head": {"ref": "backport-17ab8f0-3.7"},
"url": "https://api.github.com/repos/python/cpython/pulls/5722",
},
"installation": {"id": 456},
}
event = sansio.Event(data, event="pull_request", delivery_id="1")
gh = FakeGH()
with mock.patch.object(tasks.delete_branch_task, "delay") as mock_delay:
await delete_branch.router.dispatch(event, gh)
mock_delay.assert_called_once_with(
"backport-17ab8f0-3.7",
"https://api.github.com/repos/python/cpython/pulls/5722",
False,
installation_id=456
)
async def test_ignore_non_miss_islington_prs():
data = {
"action": "closed",
"pull_request": {
"number": 5722,
"user": {"login": "Mariatta"},
"merged": True,
"head": {"ref": "backport-17ab8f0-3.7"},
"url": "https://api.github.com/repos/python/cpython/pulls/5722",
},
"installation": {"id": 123},
}
event = sansio.Event(data, event="pull_request", delivery_id="1")
gh = FakeGH()
with mock.patch.object(tasks.delete_branch_task, "delay") as mock_delay:
await delete_branch.router.dispatch(event, gh)
mock_delay.assert_not_called()
def test_git_delete_branch_success():
with mock.patch("subprocess.check_output") as mock_subprocess:
tasks._git_delete_branch("backport-17ab8f0-3.7")
mock_subprocess.assert_called_once_with(
["git", "push", "origin", "--delete", "backport-17ab8f0-3.7"],
stderr=mock.ANY
)
def test_git_delete_branch_failure():
with mock.patch("subprocess.check_output") as mock_subprocess:
import subprocess
mock_subprocess.side_effect = subprocess.CalledProcessError(
1, "git", output=b"error: unable to delete"
)
with pytest.raises(subprocess.CalledProcessError):
tasks._git_delete_branch("backport-17ab8f0-3.7")