Repository navigation
Expand file tree
/
Copy pathtest_repos_branch.py
More file actions
109 lines (90 loc) · 3.67 KB
/
Copy pathtest_repos_branch.py
File metadata and controls
109 lines (90 loc) · 3.67 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
"""Unit tests for methods implemented on Branch."""
import github3
from . import helper
get_example_data = helper.create_example_data_helper("repos_branch_example")
url_for_branches = helper.create_url_helper(
"https://api.github.com/repos/octocat/Hello-World/branches/master"
)
url_for_commits = helper.create_url_helper(
"https://api.github.com/repos/octocat/Hello-World/commits/master"
)
class TestBranch(helper.UnitHelper):
"""Branch unit tests."""
described_class = github3.repos.branch.Branch
example_data = get_example_data()
def test_latest_sha(self):
"""Verify the request for retreiving the latest_sha."""
headers = {
"Accept": "application/vnd.github.v3.sha",
"If-None-Match": '"123"',
}
self.instance.latest_sha(differs_from="123")
self.session.get.assert_called_once_with(
url_for_commits(), headers=headers
)
def test_protect(self):
"""Verify the request to protect a branch."""
headers = {"Accept": "application/vnd.github.loki-preview+json"}
json = {
"protection": {
"enabled": True,
"required_status_checks": {
"enforcement_level": "non_admins",
"contexts": ["continuous-integration/travis-ci"],
},
}
}
self.instance.protect()
self.session.patch.assert_called_once_with(
url_for_branches(), headers=headers, json=json
)
def test_protect_enforcement(self):
"""Verify the request to protect a branch changing enforcement."""
headers = {"Accept": "application/vnd.github.loki-preview+json"}
json = {
"protection": {
"enabled": True,
"required_status_checks": {
"enforcement_level": "off",
"contexts": ["continuous-integration/travis-ci"],
},
}
}
self.instance.protect(enforcement="off")
self.session.patch.assert_called_once_with(
url_for_branches(), headers=headers, json=json
)
def test_protect_status_checks(self):
"""Verify the request to protect a branch changing status checks."""
headers = {"Accept": "application/vnd.github.loki-preview+json"}
json = {
"protection": {
"enabled": True,
"required_status_checks": {
"enforcement_level": "non_admins",
"contexts": ["another/status-check"],
},
}
}
self.instance.protect(status_checks=["another/status-check"])
self.session.patch.assert_called_once_with(
url_for_branches(), headers=headers, json=json
)
def test_unprotect(self):
"""Verify the request to unprotect a branch."""
headers = {"Accept": "application/vnd.github.loki-preview+json"}
json = {"protection": {"enabled": False}}
self.instance.unprotect()
self.session.patch.assert_called_once_with(
url_for_branches(), headers=headers, json=json
)
class TestBranchRequiresAuth(helper.UnitRequiresAuthenticationHelper):
"""Unit tests for Branch methods that require authentication."""
described_class = github3.repos.branch.Branch
example_data = get_example_data()
def test_protect(self):
"""Verify that protecting a branch requires authentication."""
self.assert_requires_auth(self.instance.protect)
def test_unprotect(self):
"""Verify that unprotecting a branch requires authentication."""
self.assert_requires_auth(self.instance.unprotect)