1010
1111class FakeGH :
1212
13- def __init__ (self , * , getitem = None ):
13+ def __init__ (self , * , getitem = None , post = None , patch = None ):
1414 self ._getitem_return = getitem
1515 self .patch_url = None
1616 self .patch_data = None
17- self .data = None
17+ self ._post_return = post
18+ self .post_url = []
19+ self .post_data = []
20+ self ._patch_return = patch
21+ self .patch_url = []
22+ self .patch_data = []
1823
1924 async def getitem (self , url ):
2025 return self ._getitem_return
2126
22- async def post (self , url , data ):
23- self .url = url
24- self .data = data
27+ async def post (self , url , * , data ):
28+ self .post_url .append (url )
29+ self .post_data .append (data )
30+ return self ._post_return
2531
26- async def patch (self , url , data ):
27- self .patch_url = url
28- self .patch_data = data
32+ async def patch (self , url , * , data ):
33+ self .patch_url .append (url )
34+ self .patch_data .append (data )
35+ return self ._patch_return
2936
3037
3138@pytest .mark .asyncio
@@ -49,7 +56,7 @@ async def test_set_status_failure(action, monkeypatch):
4956 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
5057 gh = FakeGH (getitem = issue_data )
5158 await bpo .router .dispatch (event , gh , session = None )
52- status = gh .data
59+ status = gh .post_data [ 0 ]
5360 assert status ["state" ] == "failure"
5461 assert status ["target_url" ].startswith ("https://devguide.python.org" )
5562 assert status ["context" ] == "bedevere/issue-number"
@@ -70,15 +77,14 @@ async def test_set_status_failure_via_issue_not_found_on_bpo(action):
7077 gh = FakeGH ()
7178 async with aiohttp .ClientSession () as session :
7279 await bpo .router .dispatch (event , gh , session = session )
73- status = gh .data
80+ status = gh .post_data [ 0 ]
7481 assert status ["state" ] == "failure"
7582 assert status ["target_url" ].startswith ("https://bugs.python.org" )
7683 assert status ["context" ] == "bedevere/issue-number"
7784 assert status ["description" ] == "Issue #123 not found on bugs.python.org"
7885
7986
8087@pytest .mark .asyncio
81- @pytest .mark .filterwarnings ("ignore::pytest.PytestUnraisableExceptionWarning" )
8288@pytest .mark .parametrize ("action" , ["opened" , "synchronize" , "reopened" ])
8389async def test_set_status_success (action , monkeypatch ):
8490 monkeypatch .setattr (bpo , '_validate_issue_number' ,
@@ -93,17 +99,16 @@ async def test_set_status_success(action, monkeypatch):
9399 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
94100 gh = FakeGH ()
95101 await bpo .router .dispatch (event , gh , session = None )
96- status = gh .data
102+ status = gh .post_data [ 0 ]
97103 assert status ["state" ] == "success"
98104 assert status ["target_url" ].endswith ("issue1234" )
99105 assert "1234" in status ["description" ]
100106 assert status ["context" ] == "bedevere/issue-number"
101- assert "git-sha" in gh .url
107+ assert "git-sha" in gh .post_url [ 0 ]
102108 bpo ._validate_issue_number .assert_awaited_with ("1234" , session = None )
103109
104110
105111@pytest .mark .asyncio
106- @pytest .mark .filterwarnings ("ignore::pytest.PytestUnraisableExceptionWarning" )
107112@pytest .mark .parametrize ("action" , ["opened" , "synchronize" , "reopened" ])
108113async def test_set_status_success_issue_found_on_bpo (action ):
109114 data = {
@@ -117,16 +122,15 @@ async def test_set_status_success_issue_found_on_bpo(action):
117122 gh = FakeGH ()
118123 async with aiohttp .ClientSession () as session :
119124 await bpo .router .dispatch (event , gh , session = session )
120- status = gh .data
125+ status = gh .post_data [ 0 ]
121126 assert status ["state" ] == "success"
122127 assert status ["target_url" ].endswith ("issue12345" )
123128 assert "12345" in status ["description" ]
124129 assert status ["context" ] == "bedevere/issue-number"
125- assert "git-sha" in gh .url
130+ assert "git-sha" in gh .post_url [ 0 ]
126131
127132
128133@pytest .mark .asyncio
129- @pytest .mark .filterwarnings ("ignore::pytest.PytestUnraisableExceptionWarning" )
130134@pytest .mark .parametrize ("action" , ["opened" , "synchronize" , "reopened" ])
131135async def test_set_status_success_via_skip_issue_label (action , monkeypatch ):
132136 monkeypatch .setattr (bpo , '_validate_issue_number' ,
@@ -147,10 +151,10 @@ async def test_set_status_success_via_skip_issue_label(action, monkeypatch):
147151 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
148152 gh = FakeGH (getitem = issue_data )
149153 await bpo .router .dispatch (event , gh , session = None )
150- status = gh .data
154+ status = gh .post_data [ 0 ]
151155 assert status ["state" ] == "success"
152156 assert status ["context" ] == "bedevere/issue-number"
153- assert "git-sha" in gh .url
157+ assert "git-sha" in gh .post_url [ 0 ]
154158 bpo ._validate_issue_number .assert_not_awaited ()
155159
156160
@@ -169,7 +173,7 @@ async def test_edit_title(monkeypatch):
169173 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
170174 gh = FakeGH ()
171175 await bpo .router .dispatch (event , gh , session = None )
172- assert gh .data is not None
176+ assert len ( gh .post_data ) == 1
173177 bpo ._validate_issue_number .assert_awaited_with ("1234" , session = None )
174178
175179
@@ -192,8 +196,8 @@ async def test_no_body_when_edit_title(monkeypatch):
192196 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
193197 gh = FakeGH ()
194198 await bpo .router .dispatch (event , gh , session = None )
195- assert gh .patch_data is not None
196- assert gh .patch_data ["body" ] == "\n \n <!-- issue-number: bpo-32636 -->\n https://bugs.python.org/issue32636\n <!-- /issue-number -->\n "
199+ assert len ( gh .patch_data ) == 1
200+ assert gh .patch_data [0 ][ "body" ] == "\n \n <!-- issue-number: bpo-32636 -->\n https://bugs.python.org/issue32636\n <!-- /issue-number -->\n "
197201 bpo ._validate_issue_number .assert_awaited_with ("32636" , session = None )
198202
199203
@@ -212,7 +216,8 @@ async def test_edit_other_than_title(monkeypatch):
212216 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
213217 gh = FakeGH ()
214218 await bpo .router .dispatch (event , gh , session = None )
215- assert gh .data is None
219+ assert len (gh .patch_data ) == 0
220+ assert len (gh .post_data ) == 0
216221 bpo ._validate_issue_number .assert_not_awaited ()
217222
218223
@@ -229,8 +234,8 @@ async def test_new_label_skip_issue_no_issue():
229234 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
230235 gh = FakeGH ()
231236 await bpo .router .dispatch (event , gh )
232- assert gh .data ["state" ] == "success"
233- assert "git-sha" in gh .url
237+ assert gh .post_data [ 0 ] ["state" ] == "success"
238+ assert "git-sha" in gh .post_url [ 0 ]
234239
235240
236241@pytest .mark .asyncio
@@ -246,12 +251,12 @@ async def test_new_label_skip_issue_with_issue_number():
246251 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
247252 gh = FakeGH ()
248253 await bpo .router .dispatch (event , gh )
249- status = gh .data
254+ status = gh .post_data [ 0 ]
250255 assert status ["state" ] == "success"
251256 assert status ["target_url" ].endswith ("issue1234" )
252257 assert "1234" in status ["description" ]
253258 assert status ["context" ] == "bedevere/issue-number"
254- assert "git-sha" in gh .url
259+ assert "git-sha" in gh .post_url [ 0 ]
255260
256261
257262@pytest .mark .asyncio
@@ -266,7 +271,7 @@ async def test_new_label_not_skip_issue():
266271 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
267272 gh = FakeGH ()
268273 await bpo .router .dispatch (event , gh )
269- assert gh .data is None
274+ assert len ( gh .post_data ) == 0
270275
271276
272277@pytest .mark .asyncio
@@ -286,7 +291,7 @@ async def test_removed_label_from_label_deletion(monkeypatch):
286291 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
287292 gh = FakeGH ()
288293 await bpo .router .dispatch (event , gh , session = None )
289- assert gh .data is None
294+ assert len ( gh .post_data ) == 0
290295 bpo ._validate_issue_number .assert_not_awaited ()
291296
292297
@@ -305,12 +310,12 @@ async def test_removed_label_skip_issue(monkeypatch):
305310 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
306311 gh = FakeGH ()
307312 await bpo .router .dispatch (event , gh , session = None )
308- status = gh .data
313+ status = gh .post_data [ 0 ]
309314 assert status ["state" ] == "success"
310315 assert status ["target_url" ].endswith ("issue1234" )
311316 assert "1234" in status ["description" ]
312317 assert status ["context" ] == "bedevere/issue-number"
313- assert "git-sha" in gh .url
318+ assert "git-sha" in gh .post_url [ 0 ]
314319 bpo ._validate_issue_number .assert_awaited_with ("1234" , session = None )
315320
316321
@@ -328,7 +333,7 @@ async def test_removed_label_non_skip_issue(monkeypatch):
328333 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
329334 gh = FakeGH ()
330335 await bpo .router .dispatch (event , gh , session = None )
331- assert gh .data is None
336+ assert len ( gh .post_data ) == 0
332337 bpo ._validate_issue_number .assert_not_awaited ()
333338
334339
@@ -348,9 +353,9 @@ async def test_set_body_success(monkeypatch):
348353 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
349354 gh = FakeGH ()
350355 await bpo .router .dispatch (event , gh , session = None )
351- status = gh .patch_data
356+ status = gh .patch_data [ 0 ]
352357 assert "https://bugs.python.org/issue1234" in status ["body" ]
353- assert "1347" in gh .patch_url
358+ assert "1347" in gh .patch_url [ 0 ]
354359 bpo ._validate_issue_number .assert_awaited_with ("1234" , session = None )
355360
356361
@@ -370,8 +375,8 @@ async def test_set_body_failure(monkeypatch):
370375 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
371376 gh = FakeGH ()
372377 await bpo .router .dispatch (event , gh , session = None )
373- assert gh .patch_data is None
374- assert gh .patch_url is None
378+ assert len ( gh .patch_data ) == 0
379+ assert len ( gh .patch_url ) == 0
375380 bpo ._validate_issue_number .assert_awaited_with ("1234" , session = None )
376381
377382
@@ -405,10 +410,15 @@ async def set_pull_request_body_success_helper(action, monkeypatch):
405410 event = sansio .Event (data , event = "pull_request" , delivery_id = "123123" )
406411 gh = FakeGH ()
407412 await bpo .router .dispatch (event , gh , session = None )
408- body_data = gh .patch_data
409- assert "[bpo-12345](https://bugs.python.org/issue12345)" in body_data ["body" ]
410- assert "123456" in gh .patch_url
413+ assert len (gh .patch_data ) > 0
414+ body_patched = False
415+ for body_data in gh .patch_data :
416+ if "[bpo-12345]" in body_data ["body" ]:
417+ body_patched = True
418+ assert "[bpo-12345](https://bugs.python.org/issue12345)" in body_data ["body" ]
419+ assert data ["pull_request" ]["issue_url" ] in gh .patch_url
411420
421+ assert body_patched is True
412422
413423@pytest .mark .asyncio
414424@pytest .mark .parametrize ("event,action" , [("issue_comment" , "created" ),
@@ -427,9 +437,9 @@ async def test_set_comment_body_success(event, action):
427437 event = sansio .Event (data , event = event , delivery_id = "123123" )
428438 gh = FakeGH ()
429439 await bpo .router .dispatch (event , gh )
430- body_data = gh .patch_data
440+ body_data = gh .patch_data [ 0 ]
431441 assert "[bpo-12345](https://bugs.python.org/issue12345)" in body_data ["body" ]
432- assert "123456" in gh .patch_url
442+ assert data [ "comment" ][ "url" ] in gh .patch_url
433443
434444
435445@pytest .mark .asyncio
@@ -474,8 +484,8 @@ async def test_set_comment_body_without_bpo(event, action):
474484 event = sansio .Event (data , event = event , delivery_id = "123123" )
475485 gh = FakeGH ()
476486 await bpo .router .dispatch (event , gh )
477- assert gh .patch_data is None
478- assert gh .patch_url is None
487+ assert len ( gh .patch_data ) == 0
488+ assert len ( gh .patch_url ) == 0
479489
480490
481491@pytest .mark .asyncio
@@ -518,10 +528,15 @@ async def set_pull_request_body_already_hyperlinked_bpo_helper(action, monkeypat
518528 event = sansio .Event (data , event = "pull_request" , delivery_id = "123123" )
519529 gh = FakeGH ()
520530 await bpo .router .dispatch (event , gh , session = None )
521- body_data = gh .patch_data
522- assert body_data ["body" ].count ("[bpo-123](https://bugs.python.org/issue123)" ) == 2
523- assert body_data ["body" ].count ("[something about bpo-123](https://bugs.python.org/issue123)" ) == 1
524- assert "123456" in gh .patch_url
531+ patched = False
532+ for body_data in gh .patch_data :
533+ if body_data ["body" ].startswith ("[bpo-123]" ):
534+ patched = True
535+ assert body_data ["body" ].count ("[bpo-123](https://bugs.python.org/issue123)" ) == 2
536+ assert body_data ["body" ].count ("[something about bpo-123](https://bugs.python.org/issue123)" ) == 1
537+ assert data ["pull_request" ]["issue_url" ] in gh .patch_url
538+
539+ assert patched is True
525540
526541
527542@pytest .mark .asyncio
@@ -545,7 +560,7 @@ async def test_set_comment_body_already_hyperlinked_bpo(event, action):
545560 event = sansio .Event (data , event = event , delivery_id = "123123" )
546561 gh = FakeGH ()
547562 await bpo .router .dispatch (event , gh )
548- body_data = gh .patch_data
563+ body_data = gh .patch_data [ 0 ]
549564 assert body_data ["body" ].count ("[bpo-123](https://bugs.python.org/issue123)" ) == 2
550565 assert body_data ["body" ].count ("[something about bpo-123](https://bugs.python.org/issue123)" ) == 1
551- assert "123456" in gh .patch_url
566+ assert data [ "comment" ][ "url" ] in gh .patch_url
0 commit comments