@@ -35,14 +35,6 @@ async def test_signature(monkeypatch):
35
35
'unused' )
36
36
37
37
38
- async def test_update_repo_error ():
39
- """Test that updating a repository fails as expected."""
40
- with pytest .raises (web .HTTPServerError ,
41
- match = 'non-existent does not exist' ):
42
- await update_repo (Path ('non-existent' ), 'unused' ,
43
- 'matplotlib/non-existent' )
44
-
45
-
46
38
async def test_update_repo_empty (tmp_path_factory ):
47
39
"""Test that updating an empty repository works as expected."""
48
40
repo1 = tmp_path_factory .mktemp ('repo1' )
@@ -137,15 +129,25 @@ async def test_github_webhook_errors(aiohttp_client, monkeypatch):
137
129
assert resp .status == 400
138
130
assert 'incorrect repository' in await resp .text ()
139
131
132
+ # Problem on our side.
133
+ resp = await client .post (
134
+ '/gh/non-existent' ,
135
+ headers = {** valid_headers , 'X-GitHub-Event' : 'push' },
136
+ data = '{"sender": {"login": "QuLogic"}, "ref": "refs/heads/gh-pages", '
137
+ '"repository": {"name": "non-existent", '
138
+ '"owner": {"login": "matplotlib"}}}' )
139
+ assert resp .status == 500
140
+ assert 'non-existent does not exist' in await resp .text ()
141
+
140
142
141
- async def test_github_webhook_valid (aiohttp_client , monkeypatch ):
143
+ async def test_github_webhook_valid (aiohttp_client , monkeypatch , tmp_path ):
142
144
"""Test valid input to webhook."""
143
145
client = await aiohttp_client (create_app ())
144
146
145
147
# Do no actual work, since that's tested above.
146
148
monkeypatch .setattr (webhook , 'verify_signature' ,
147
149
mock .Mock (verify_signature , return_value = True ))
148
- monkeypatch .setenv ('SITE_DIR' , 'non-existent-site-dir' )
150
+ monkeypatch .setenv ('SITE_DIR' , str ( tmp_path ) )
149
151
ur_mock = mock .Mock (update_repo , return_value = None )
150
152
monkeypatch .setattr (webhook , 'update_repo' , ur_mock )
151
153
@@ -177,6 +179,8 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
177
179
ur_mock .assert_not_called ()
178
180
179
181
# Push event to gh-pages branch should run an update.
182
+ tmp_repo = tmp_path / 'non-existent-repo'
183
+ (tmp_repo / '.git' ).mkdir (parents = True , exist_ok = True )
180
184
resp = await client .post (
181
185
'/gh/non-existent-repo' ,
182
186
headers = {** valid_headers , 'X-GitHub-Event' : 'push' },
@@ -186,5 +190,4 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
186
190
' "owner": {"login": "matplotlib"}}}' )
187
191
assert resp .status == 200
188
192
ur_mock .assert_called_once_with (
189
- Path ('non-existent-site-dir/non-existent-repo' ), 'foo' ,
190
- 'matplotlib/non-existent-repo' )
193
+ tmp_repo , 'foo' , 'matplotlib/non-existent-repo' )
0 commit comments