8000 Fix tests due to yarl URL str output change (#1112) · msz-coder/python-kasa@1773f98 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1773f98

Browse files
authored
Fix tests due to yarl URL str output change (python-kasa#1112)
Latest versions of yarl>=1.9.5 omit the port 80 when calling str(url) which broke tests.
1 parent b0d0c4b commit 1773f98

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

kasa/tests/test_aestransport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ async def _post(self, url: URL, json: dict[str, Any]):
460460
elif json["method"] == "login_device":
461461
return await self._return_login_response(url, json)
462462
else:
463-
assert str(url) == f"http://{self.host}:80/app?token={self.token}"
463+
assert url == URL(f"http://{self.host}:80/app?token={self.token}")
464464
return await self._return_send_response(url, json)
465465

466466
async def _return_handshake_response(self, url: URL, json: dict[str, Any]):

kasa/tests/test_klapprotocol.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,14 @@ async def test_handshake(
389389
async def _return_handshake_response(url: URL, params=None, data=None, *_, **__):
390390
nonlocal client_seed, server_seed, device_auth_hash
391391

392-
if str(url) == "http://127.0.0.1:80/app/handshake1":
392+
if url == URL("http://127.0.0.1:80/app/handshake1"):
393393
client_seed = data
394394
seed_auth_hash = _sha256(
395395
seed_auth_hash_calc1(client_seed, server_seed, device_auth_hash)
396396
)
397397

398398
return _mock_response(200, server_seed + seed_auth_hash)
399-
elif str(url) == "http://127.0.0.1:80/app/handshake2":
399+
elif url == URL("http://127.0.0.1:80/app/handshake2"):
400400
seed_auth_hash = _sha256(
401401
seed_auth_hash_calc2(client_seed, server_seed, device_auth_hash)
402402
)
@@ -433,14 +433,14 @@ async def test_query(mocker):
433433
async def _return_response(url: URL, params=None, data=None, *_, **__):
434434
nonlocal client_seed, server_seed, device_auth_hash, seq
435435

436-
if str(url) == "http://127.0.0.1:80/app/handshake1":
436+
if url == URL("http://127.0.0.1:80/app/handshake1"):
437437
client_seed = data
438438
client_seed_auth_hash = _sha256(data + device_auth_hash)
439439

440440
return _mock_response(200, server_seed + client_seed_auth_hash)
441-
elif str(url) == "http://127.0.0.1:80/app/handshake2":
441+
elif url == URL("http://127.0.0.1:80/app/handshake2"):
442442
return _mock_response(200, b"")
443-
elif str(url) == "http://127.0.0.1:80/app/request":
443+
elif url == URL("http://127.0.0.1:80/app/request"):
444444
encryption_session = KlapEncryptionSession(
445445
protocol._transport._encryption_session.local_seed,
446446
protocol._transport._encryption_session.remote_seed,
@@ -526,21 +526,21 @@ async def _return_response(url: URL, params=None, data=None, *_, **__):
526526
response_status, \
527527
credentials_match
528528

529-
if str(url) == "http://127.0.0.1:80/app/handshake1":
529+
if url == URL("http://127.0.0.1:80/app/handshake1"):
530530
client_seed = data
531531
client_seed_auth_hash = _sha256(data + device_auth_hash)
532532
if credentials_match is not False and credentials_match is not True:
533533
client_seed_auth_hash += credentials_match
534534
return _mock_response(
535535
response_status[0], server_seed + client_seed_auth_hash
536536
)
537-
elif str(url) == "http://127.0.0.1:80/app/handshake2":
537+
elif url == URL("http://127.0.0.1:80/app/handshake2"):
538538
client_seed = data
539539
client_seed_auth_hash = _sha256(data + device_auth_hash)
540540
return _mock_response(
541541
response_status[1], server_seed + client_seed_auth_hash
542542
)
543-
elif str(url) == "http://127.0.0.1:80/app/request":
543+
elif url == URL("http://127.0.0.1:80/app/request"):
544544
return _mock_response(response_status[2], b"")
545545

546546
mocker.patch.object(aiohttp.ClientSession, "post", side_effect=_return_response)

0 commit comments

Comments
 (0)
0