Skip to content

Commit baa42d2

Browse files
chantrafacebook-github-bot
authored andcommitted
test: Make tests compatible with yarl 1.9.5+ (#60)
Summary: With yarl 1.9.5 release, the tests would start failing. Changelog: https://yarl.aio-libs.org/en/latest/changes/#id26 TL;DR, the :0 would get eaten and the mock would not intercept the http calls. Tested this manually with 1.9.4 and 1.9.5. The next diff which is part of facebookincubator/kernel-patches-daemon#59 will confirm I did not screw up. Pull Request resolved: facebookincubator/kernel-patches-daemon#60 Reviewed By: chantra Differential Revision: D62521426 fbshipit-source-id: 4f39e59a1a1fc5954376721117674dbf85370463
1 parent d4b669c commit baa42d2

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

tests/common/patchwork_mock.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ class PatchworkMock(Patchwork):
3030
def __init__(self, *args: Any, **kwargs: Any) -> None:
3131
# Force patchwork to use loopback/port 0 for whatever network access
3232
# we fail to mock
33-
# kwargs["server"] = "https://127.0.0.1:0"
33+
# kwargs["server"] = "https://127.0.0.1"
3434
super().__init__(*args, **kwargs)
3535

3636

3737
def get_default_pw_client() -> PatchworkMock:
3838
return PatchworkMock(
39-
server="127.0.0.1:0",
39+
server="127.0.0.1",
4040
api_version="1.1",
4141
search_patterns=[{"archived": False, "project": PROJECT, "delegate": DELEGATE}],
4242
auth_token="mocktoken",
@@ -83,7 +83,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
8383

8484
DEFAULT_FREEZE_DATE = "2010-07-23T00:00:00"
8585
DEFAULT_TEST_RESPONSES: Dict[str, Any] = {
86-
"https://127.0.0.1:0/api/1.1/series/?q=foo": [
86+
"https://127.0.0.1/api/1.1/series/?q=foo": [
8787
# Does not match the subject name
8888
{
8989
"id": 1,
@@ -170,7 +170,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
170170
},
171171
],
172172
# Multiple relevant series to test our guess_pr logic.
173-
"https://127.0.0.1:0/api/1.1/series/?q=barv2": [
173+
"https://127.0.0.1/api/1.1/series/?q=barv2": [
174174
# Matches and has relevant diff.
175175
{
176176
"id": 6,
@@ -197,7 +197,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
197197
},
198198
],
199199
# Single relevant series to test our guess_pr logic.
200-
"https://127.0.0.1:0/api/1.1/series/?q=code": [
200+
"https://127.0.0.1/api/1.1/series/?q=code": [
201201
# Matches, has one relevant diffs, and is the most recent series.
202202
{
203203
"id": 9,
@@ -213,42 +213,42 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
213213
},
214214
],
215215
# Correct project and delegate
216-
"https://127.0.0.1:0/api/1.1/patches/11/": {
216+
"https://127.0.0.1/api/1.1/patches/11/": {
217217
"id": 11,
218218
"project": {"id": PROJECT},
219219
"delegate": {"id": DELEGATE},
220220
"archived": False,
221221
},
222222
# wrong project
223-
"https://127.0.0.1:0/api/1.1/patches/12/": {
223+
"https://127.0.0.1/api/1.1/patches/12/": {
224224
"id": 12,
225225
"project": {"id": PROJECT + 1},
226226
"delegate": {"id": DELEGATE},
227227
"archived": False,
228228
},
229229
# Wrong delegate
230-
"https://127.0.0.1:0/api/1.1/patches/13/": {
230+
"https://127.0.0.1/api/1.1/patches/13/": {
231231
"id": 13,
232232
"project": {"id": PROJECT},
233233
"delegate": {"id": DELEGATE + 1},
234234
"archived": False,
235235
},
236236
# Correct project/delegate but archived
237-
"https://127.0.0.1:0/api/1.1/patches/14/": {
237+
"https://127.0.0.1/api/1.1/patches/14/": {
238238
"id": 14,
239239
"project": {"id": PROJECT},
240240
"delegate": {"id": DELEGATE},
241241
"archived": True,
242242
},
243243
# None project
244-
"https://127.0.0.1:0/api/1.1/patches/15/": {
244+
"https://127.0.0.1/api/1.1/patches/15/": {
245245
"id": 15,
246246
"project": None,
247247
"delegate": {"id": DELEGATE},
248248
"archived": False,
249249
},
250250
# None delegate
251-
"https://127.0.0.1:0/api/1.1/patches/16/": {
251+
"https://127.0.0.1/api/1.1/patches/16/": {
252252
"id": 16,
253253
"project": {"id": PROJECT},
254254
"delegate": None,
@@ -258,7 +258,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
258258
# Series test cases #
259259
#####################
260260
# An open series, is a series that has no patch in irrelevant state.
261-
"https://127.0.0.1:0/api/1.1/series/665/": {
261+
"https://127.0.0.1/api/1.1/series/665/": {
262262
"id": 665,
263263
"name": "[a/b] this series is *NOT* closed!",
264264
"date": "2010-07-20T01:00:00",
@@ -271,7 +271,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
271271
"mbox": "https://example.com",
272272
},
273273
# Patch in an relevant state.
274-
"https://127.0.0.1:0/api/1.1/patches/6651/": {
274+
"https://127.0.0.1/api/1.1/patches/6651/": {
275275
"id": 6651,
276276
"project": {"id": PROJECT},
277277
"delegate": {"id": DELEGATE},
@@ -281,7 +281,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
281281
"name": "foo",
282282
},
283283
# Patch in a relevant state.
284-
"https://127.0.0.1:0/api/1.1/patches/6652/": {
284+
"https://127.0.0.1/api/1.1/patches/6652/": {
285285
"id": 6652,
286286
"project": {"id": PROJECT},
287287
"delegate": {"id": DELEGATE},
@@ -293,7 +293,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
293293
"name": "[0/5, 1/2 , v42, V24, first patch tag, second patch tag, patch , some stuff with spaces , patch] bar",
294294
},
295295
# Patch in an relevant state.
296-
"https://127.0.0.1:0/api/1.1/patches/6653/": {
296+
"https://127.0.0.1/api/1.1/patches/6653/": {
297297
"id": 6653,
298298
"project": {"id": PROJECT},
299299
"delegate": {"id": DELEGATE},
@@ -303,7 +303,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
303303
"name": "[duplicate tag] foo",
304304
},
305305
# A closed series, is a series that has at least 1 patch in an irrelevant state.
306-
"https://127.0.0.1:0/api/1.1/series/666/": {
306+
"https://127.0.0.1/api/1.1/series/666/": {
307307
"id": 666,
308308
"name": "this series is closed!",
309309
"date": "2010-07-20T01:00:00",
@@ -315,23 +315,23 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
315315
"mbox": "https://example.com",
316316
},
317317
# Patch in an irrelevant state.
318-
"https://127.0.0.1:0/api/1.1/patches/6661/": {
318+
"https://127.0.0.1/api/1.1/patches/6661/": {
319319
"id": 6661,
320320
"project": {"id": PROJECT},
321321
"delegate": {"id": DELEGATE},
322322
"archived": True,
323323
"state": get_dict_key(IRRELEVANT_STATES),
324324
},
325325
# Patch in a relevant state.
326-
"https://127.0.0.1:0/api/1.1/patches/6662/": {
326+
"https://127.0.0.1/api/1.1/patches/6662/": {
327327
"id": 6662,
328328
"project": {"id": PROJECT},
329329
"delegate": {"id": DELEGATE},
330330
"archived": True,
331331
"state": get_dict_key(RELEVANT_STATES),
332332
},
333333
# Series with no cover letter and no patches.
334-
"https://127.0.0.1:0/api/1.1/series/667/": {
334+
"https://127.0.0.1/api/1.1/series/667/": {
335335
"id": 667,
336336
"name": "this series has no cover letter!",
337337
"date": "2010-07-20T01:00:00",
@@ -345,7 +345,7 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
345345
},
346346
# Expiration test cases
347347
# Series with expirable patches.
348-
"https://127.0.0.1:0/api/1.1/series/668/": {
348+
"https://127.0.0.1/api/1.1/series/668/": {
349349
"id": 668,
350350
"name": "this series has no cover letter!",
351351
"date": "2010-07-20T01:00:00",
@@ -358,15 +358,15 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
358358
"mbox": "https://example.com",
359359
},
360360
# Patch in a non-expirable state.
361-
"https://127.0.0.1:0/api/1.1/patches/6681/": {
361+
"https://127.0.0.1/api/1.1/patches/6681/": {
362362
"id": 6681,
363363
"project": {"id": PROJECT},
364364
"delegate": {"id": DELEGATE},
365365
"archived": True,
366366
"state": "new",
367367
},
368368
# Patch in an expirable state.
369-
"https://127.0.0.1:0/api/1.1/patches/6682/": {
369+
"https://127.0.0.1/api/1.1/patches/6682/": {
370370
"id": 6682,
371371
"project": {"id": PROJECT},
372372
"delegate": {"id": DELEGATE},
@@ -375,15 +375,15 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
375375
"date": DEFAULT_FREEZE_DATE,
376376
},
377377
# Patch in a non-expirable state.
378-
"https://127.0.0.1:0/api/1.1/patches/6683/": {
378+
"https://127.0.0.1/api/1.1/patches/6683/": {
379379
"id": 6683,
380380
"project": {"id": PROJECT},
381381
"delegate": {"id": DELEGATE},
382382
"archived": True,
383383
"state": "new",
384384
},
385385
# Series with no expirable patches.
386-
"https://127.0.0.1:0/api/1.1/series/669/": {
386+
"https://127.0.0.1/api/1.1/series/669/": {
387387
"id": 669,
388388
"name": "this series has no cover letter!",
389389
"date": "2010-07-20T01:00:00",
@@ -396,23 +396,23 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
396396
"mbox": "https://example.com",
397397
},
398398
# Patch in a non-expirable state.
399-
"https://127.0.0.1:0/api/1.1/patches/6691/": {
399+
"https://127.0.0.1/api/1.1/patches/6691/": {
400400
"id": 6691,
401401
"project": {"id": PROJECT},
402402
"delegate": {"id": DELEGATE},
403403
"archived": True,
404404
"state": "new",
405405
},
406406
# Patch in a non-expirable state.
407-
"https://127.0.0.1:0/api/1.1/patches/6692/": {
407+
"https://127.0.0.1/api/1.1/patches/6692/": {
408408
"id": 6692,
409409
"project": {"id": PROJECT},
410410
"delegate": {"id": DELEGATE},
411411
"archived": True,
412412
"state": "new",
413413
},
414414
# Patch in a non-expirable state.
415-
"https://127.0.0.1:0/api/1.1/patches/6693/": {
415+
"https://127.0.0.1/api/1.1/patches/6693/": {
416416
"id": 6693,
417417
"project": {"id": PROJECT},
418418
"delegate": {"id": DELEGATE},

tests/test_branch_worker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@
5353

5454

5555
TEST_REPO = "repo"
56-
TEST_REPO_URL = f"https://user:[email protected]:0/org/{TEST_REPO}"
56+
TEST_REPO_URL = f"https://user:[email protected]/org/{TEST_REPO}"
5757
TEST_REPO_BRANCH = "test_branch"
5858
TEST_REPO_PR_BASE_BRANCH = "test_branch_base"
5959
TEST_UPSTREAM_REPO_URL = "https://127.0.0.2:0/upstream_org/upstream_repo"
6060
TEST_UPSTREAM_BRANCH = "test_upstream_branch"
6161
TEST_CI_REPO = "ci-repo"
62-
TEST_CI_REPO_URL = f"https://user:[email protected]:0/ci-org/{TEST_CI_REPO}"
62+
TEST_CI_REPO_URL = f"https://user:[email protected]/ci-org/{TEST_CI_REPO}"
6363
TEST_CI_BRANCH = "test_ci_branch"
6464
TEST_BASE_DIRECTORY = "/repos"
6565
TEST_BRANCH = "test-branch"
@@ -917,7 +917,7 @@ async def _get_series(self, m: aioresponses, summaries: List[str]) -> Series:
917917
contains such commits.
918918
"""
919919
data = {
920-
"https://127.0.0.1:0/api/1.1/series/42/": {
920+
"https://127.0.0.1/api/1.1/series/42/": {
921921
"id": 42,
922922
"name": "[a/b] this series is *NOT* closed!",
923923
"date": "2010-07-20T01:00:00",
@@ -930,7 +930,7 @@ async def _get_series(self, m: aioresponses, summaries: List[str]) -> Series:
930930
"mbox": "https://example.com",
931931
},
932932
**{
933-
f"https://127.0.0.1:0/api/1.1/patches/{i}/": {
933+
f"https://127.0.0.1/api/1.1/patches/{i}/": {
934934
"id": i,
935935
"project": {"id": "1234"},
936936
"delegate": {"id": "12345"},

tests/test_github_connector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
TEST_ORG = "org"
4444
TEST_REPO = "repo"
45-
TEST_REPO_URL = f"https://user:[email protected]:0/{TEST_ORG}/{TEST_REPO}"
45+
TEST_REPO_URL = f"https://user:[email protected]/{TEST_ORG}/{TEST_REPO}"
4646
TEST_APP_ID = 1
4747
TEST_INSTALLATION_ID = 2
4848
TEST_PRIV_KEY: str = (
@@ -372,10 +372,10 @@ def test_set_user_token_in_url_when_not_present(self) -> None:
372372
side_effect=side_effect,
373373
) as p, freeze_time(DEFAULT_FREEZE_DATE):
374374
gc_app_auth = get_default_gc_app_auth_client(
375-
repo_url=f"https://127.0.0.1:0/{TEST_ORG}/{TEST_REPO}"
375+
repo_url=f"https://127.0.0.1/{TEST_ORG}/{TEST_REPO}"
376376
)
377377
self.assertEqual(
378-
f"https://test_user[bot]:[email protected]:0/{TEST_ORG}/{TEST_REPO}",
378+
f"https://test_user[bot]:[email protected]/{TEST_ORG}/{TEST_REPO}",
379379
gc_app_auth.repo_url,
380380
)
381381
self.assertEqual(p.call_count, 1)
@@ -395,8 +395,8 @@ class TestCase:
395395
test_cases = [
396396
TestCase(
397397
name="port is 0",
398-
initial_url=f"https://127.0.0.1:0/{TEST_ORG}/{TEST_REPO}",
399-
expected_url=f"https://test_user[bot]:[email protected]:0/{TEST_ORG}/{TEST_REPO}",
398+
initial_url=f"https://127.0.0.1/{TEST_ORG}/{TEST_REPO}",
399+
expected_url=f"https://test_user[bot]:[email protected]/{TEST_ORG}/{TEST_REPO}",
400400
),
401401
TestCase(
402402
name="port is not 0",

0 commit comments

Comments
 (0)