@@ -105,35 +105,35 @@ async def test_github_webhook_errors(aiohttp_client, monkeypatch):
105105 monkeypatch .setattr (webhook , 'verify_signature' ,
106106 mock .Mock (verify_signature , return_value = True ))
107107
108+ valid_headers = {
109+ 'X-GitHub-Delivery' : 'foo' ,
110+ 'X-Hub-Signature-256' : 'unused' ,
111+ 'X-GitHub-Event' : 'ping' ,
112+ }
113+
108114 # 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 = '}{' )
113117 assert resp .status == 400
114118 assert 'Invalid data input' in await resp .text ()
115119
116120 # 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 = '{}' )
121123 assert resp .status == 400
122124 assert 'Missing required fields' in await resp .text ()
123125
124126 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",'
128129 ' "repository": "foo"}' )
129130 assert resp .status == 400
130131 assert 'incorrect organization' in await resp .text ()
131132
132133 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"}' )
137137 assert resp .status == 400
138138 assert 'incorrect repository' in await resp .text ()
139139
@@ -149,11 +149,16 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
149149 ur_mock = mock .Mock (update_repo , return_value = None )
150150 monkeypatch .setattr (webhook , 'update_repo' , ur_mock )
151151
152+ valid_headers = {
153+ 'X-GitHub-Delivery' : 'foo' ,
154+ 'X-Hub-Signature-256' : 'unused' ,
155+ }
156+
152157 # Ping event just returns success.
153158 resp = await client .post (
154159 '/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 ,'
157162 ' "zen": "Beautiful is better than ugly.",'
158163 ' "organization": "matplotlib",'
159164 ' "repository": "non-existent-repo"}' )
@@ -163,9 +168,8 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
163168 # Push event should run an update.
164169 resp = await client .post (
165170 '/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",'
169173 ' "repository": "non-existent-repo"}' )
170174 assert resp .status == 200
171175 ur_mock .assert_called_once_with (
0 commit comments