@@ -105,35 +105,35 @@ async def test_github_webhook_errors(aiohttp_client, monkeypatch):
105
105
monkeypatch .setattr (webhook , 'verify_signature' ,
106
106
mock .Mock (verify_signature , return_value = True ))
107
107
108
+ valid_headers = {
109
+ 'X-GitHub-Delivery' : 'foo' ,
110
+ 'X-Hub-Signature-256' : 'unused' ,
111
+ 'X-GitHub-Event' : 'ping' ,
112
+ }
113
+
108
114
# Data should be JSON.
109
- resp = await client .post (
110
- '/gh/non-existent-repo' ,
111
- headers = {'X-GitHub-Delivery' : 'foo' , 'X-Hub-Signature-256' : 'unused' },
112
- data = '}{' )
115
+ resp = await client .post ('/gh/non-existent-repo' , headers = valid_headers ,
116
+ data = '}{' )
113
117
assert resp .status == 400
114
118
assert 'Invalid data input' in await resp .text ()
115
119
116
120
# Some data fields are required.
117
- resp = await client .post (
118
- '/gh/non-existent-repo' ,
119
- headers = {'X-GitHub-Delivery' : 'foo' , 'X-Hub-Signature-256' : 'unused' },
120
- data = '{}' )
121
+ resp = await client .post ('/gh/non-existent-repo' , headers = valid_headers ,
122
+ data = '{}' )
121
123
assert resp .status == 400
122
124
assert 'Missing required fields' in await resp .text ()
123
125
124
126
resp = await client .post (
125
- '/gh/non-existent-repo' ,
126
- headers = {'X-GitHub-Delivery' : 'foo' , 'X-Hub-Signature-256' : 'unused' },
127
- data = '{"action": "ping", "sender": "QuLogic", "organization": "foo",'
127
+ '/gh/non-existent-repo' , headers = valid_headers ,
128
+ data = '{"sender": "QuLogic", "organization": "foo",'
128
129
' "repository": "foo"}' )
129
130
assert resp .status == 400
130
131
assert 'incorrect organization' in await resp .text ()
131
132
132
133
resp = await client .post (
133
- '/gh/non-existent-repo' ,
134
- headers = {'X-GitHub-Delivery' : 'foo' , 'X-Hub-Signature-256' : 'unused' },
135
- data = '{"action": "ping", "sender": "QuLogic", '
136
- '"organization": "matplotlib", "repository": "foo"}' )
134
+ '/gh/non-existent-repo' , headers = valid_headers ,
135
+ data = '{"sender": "QuLogic", "organization": "matplotlib",'
136
+ ' "repository": "foo"}' )
137
137
assert resp .status == 400
138
138
assert 'incorrect repository' in await resp .text ()
139
139
@@ -149,11 +149,16 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
149
149
ur_mock = mock .Mock (update_repo , return_value = None )
150
150
monkeypatch .setattr (webhook , 'update_repo' , ur_mock )
151
151
152
+ valid_headers = {
153
+ 'X-GitHub-Delivery' : 'foo' ,
154
+ 'X-Hub-Signature-256' : 'unused' ,
155
+ }
156
+
152
157
# Ping event just returns success.
153
158
resp = await client .post (
154
159
'/gh/non-existent-repo' ,
155
- headers = {'X-GitHub-Delivery' : 'foo' , 'X-Hub-Signature-256 ' : 'unused ' },
156
- data = '{"action": "ping", " sender": "QuLogic", "hook_id": "foo" ,'
160
+ headers = {** valid_headers , 'X-GitHub-Event ' : 'ping ' },
161
+ data = '{"sender": "QuLogic", "hook_id": 1234 ,'
157
162
' "zen": "Beautiful is better than ugly.",'
158
163
' "organization": "matplotlib",'
159
164
' "repository": "non-existent-repo"}' )
@@ -163,9 +168,8 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
163
168
# Push event should run an update.
164
169
resp = await client .post (
165
170
'/gh/non-existent-repo' ,
166
- headers = {'X-GitHub-Delivery' : 'foo' , 'X-Hub-Signature-256' : 'unused' },
167
- data = '{"action": "push", "sender": "QuLogic",'
168
- ' "organization": "matplotlib",'
171
+ headers = {** valid_headers , 'X-GitHub-Event' : 'push' },
172
+ data = '{"sender": "QuLogic", "organization": "matplotlib",'
169
173
' "repository": "non-existent-repo"}' )
170
174
assert resp .status == 200
171
175
ur_mock .assert_called_once_with (
0 commit comments