@@ -35,14 +35,6 @@ async def test_signature(monkeypatch):
3535 'unused' )
3636
3737
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-
4638async def test_update_repo_empty (tmp_path_factory ):
4739 """Test that updating an empty repository works as expected."""
4840 repo1 = tmp_path_factory .mktemp ('repo1' )
@@ -137,15 +129,25 @@ async def test_github_webhook_errors(aiohttp_client, monkeypatch):
137129 assert resp .status == 400
138130 assert 'incorrect repository' in await resp .text ()
139131
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+
140142
141- async def test_github_webhook_valid (aiohttp_client , monkeypatch ):
143+ async def test_github_webhook_valid (aiohttp_client , monkeypatch , tmp_path ):
142144 """Test valid input to webhook."""
143145 client = await aiohttp_client (create_app ())
144146
145147 # Do no actual work, since that's tested above.
146148 monkeypatch .setattr (webhook , 'verify_signature' ,
147149 mock .Mock (verify_signature , return_value = True ))
148- monkeypatch .setenv ('SITE_DIR' , 'non-existent-site-dir' )
150+ monkeypatch .setenv ('SITE_DIR' , str ( tmp_path ) )
149151 ur_mock = mock .Mock (update_repo , return_value = None )
150152 monkeypatch .setattr (webhook , 'update_repo' , ur_mock )
151153
@@ -177,6 +179,8 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
177179 ur_mock .assert_not_called ()
178180
179181 # 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 )
180184 resp = await client .post (
181185 '/gh/non-existent-repo' ,
182186 headers = {** valid_headers , 'X-GitHub-Event' : 'push' },
@@ -186,5 +190,4 @@ async def test_github_webhook_valid(aiohttp_client, monkeypatch):
186190 ' "owner": {"login": "matplotlib"}}}' )
187191 assert resp .status == 200
188192 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