3
3
from . import helper
4
4
5
5
get_example_data = helper .create_example_data_helper ('repos_branch_example' )
6
- url_for = helper .create_url_helper (
6
+ url_for_branches = helper .create_url_helper (
7
+ 'https://api.github.com/repos/octocat/Hello-World/branches/master'
8
+ )
9
+ url_for_commits = helper .create_url_helper (
7
10
'https://api.github.com/repos/octocat/Hello-World/commits/master'
8
11
)
9
12
@@ -22,6 +25,112 @@ def test_latest_sha(self):
22
25
}
23
26
self .instance .latest_sha (differs_from = '123' )
24
27
self .session .get .assert_called_once_with (
25
- url_for (),
28
+ url_for_commits (),
26
29
headers = headers
27
30
)
31
+
32
+ def test_protect (self ):
33
+ """Verify the request to protect a branch."""
34
+ headers = {
35
+ 'Accept' : 'application/vnd.github.loki-preview+json'
36
+ }
37
+ json = {
38
+ 'protection' : {
39
+ 'enabled' : True ,
40
+ 'required_status_checks' : {
41
+ 'enforcement_level' : 'non_admins' ,
42
+ 'contexts' : [
43
+ 'continuous-integration/travis-ci'
44
+ ]
45
+ }
46
+ }
47
+ }
48
+
49
+ self .instance .protect ()
50
+ self .session .patch .assert_called_once_with (
51
+ url_for_branches (),
52
+ headers = headers ,
53
+ json = json
54
+ )
55
+
56
+ def test_protect_enforcement (self ):
57
+ """Verify the request to protect a branch changing enforcement."""
58
+ headers = {
59
+ 'Accept' : 'application/vnd.github.loki-preview+json'
60
+ }
61
+ json = {
62
+ 'protection' : {
63
+ 'enabled' : True ,
64
+ 'required_status_checks' : {
65
+ 'enforcement_level' : 'off' ,
66
+ 'contexts' : [
67
+ 'continuous-integration/travis-ci'
68
+ ]
69
+ }
70
+ }
71
+ }
72
+
73
+ self .instance .protect (enforcement = 'off' )
74
+ self .session .patch .assert_called_once_with (
75
+ url_for_branches (),
76
+ headers = headers ,
77
+ json = json
78
+ )
79
+
80
+ def test_protect_status_checks (self ):
81
+ """Verify the request to protect a branch changing status checks."""
82
+ headers = {
83
+ 'Accept' : 'application/vnd.github.loki-preview+json'
84
+ }
85
+ json = {
86
+ 'protection' : {
87
+ 'enabled' : True ,
88
+ 'required_status_checks' : {
89
+ 'enforcement_level' : 'non_admins' ,
90
+ 'contexts' : [
91
+ 'another/status-check'
92
+ ]
93
+ }
94
+ }
95
+ }
96
+
97
+ self .instance .protect (status_checks = ['another/status-check' ])
98
+ self .session .patch .assert_called_once_with (
99
+ url_for_branches (),
100
+ headers = headers ,
101
+ json = json
102
+ )
103
+
104
+ def test_unprotect (self ):
105
+ """Verify the request to unprotect a branch."""
106
+ headers = {
107
+ 'Accept' : 'application/vnd.github.loki-preview+json'
108
+ }
109
+ json = {
110
+ 'protection' : {
111
+ 'enabled' : False
112
+ }
113
+ }
114
+
115
+ self .instance .unprotect ()
116
+ self .session .patch .assert_called_once_with (
117
+ url_for_branches (),
118
+ headers = headers ,
119
+ json = json
120
+ )
121
+
122
+
123
+ class TestBranchRequiresAuth (helper .UnitRequiresAuthenticationHelper ):
124
+
125
+ """Unit tests for Branch methods that require authentication."""
126
+
127
+ described_class = github3 .repos .branch .Branch
128
+ example_data = get_example_data ()
129
+
130
+ def test_protect (self ):
131
+ """Verify that protecting a branch requires authentication."""
132
+ self .assert_requires_auth (self .instance .protect )
133
+
134
+ def test_unprotect (self ):
135
+ """Verify that unprotecting a branch requires authentication."""
136
+ self .assert_requires_auth (self .instance .unprotect )
0 commit comments