Migrate http client to use aiohttp instead of httpx (#643)

This commit is contained in:
Steven B
2024-01-18 17:32:26 +00:00
committed by GitHub
parent 3b1b0a3c21
commit 642e9a1f5b
10 changed files with 488 additions and 119 deletions

View File

@@ -1,7 +1,7 @@
from json import dumps as json_dumps
from json import loads as json_loads
import httpx
import aiohttp
from kasa.credentials import Credentials
from kasa.deviceconfig import (
@@ -12,8 +12,8 @@ from kasa.deviceconfig import (
)
def test_serialization():
config = DeviceConfig(host="Foo", http_client=httpx.AsyncClient())
async def test_serialization():
config = DeviceConfig(host="Foo", http_client=aiohttp.ClientSession())
config_dict = config.to_dict()
config_json = json_dumps(config_dict)
config2_dict = json_loads(config_json)
@@ -21,10 +21,10 @@ def test_serialization():
assert config == config2
def test_credentials_hash():
async def test_credentials_hash():
config = DeviceConfig(
host="Foo",
http_client=httpx.AsyncClient(),
http_client=aiohttp.ClientSession(),
credentials=Credentials("foo", "bar"),
)
config_dict = config.to_dict(credentials_hash="credhash")
@@ -35,10 +35,10 @@ def test_credentials_hash():
assert config2.credentials is None
def test_blank_credentials_hash():
async def test_blank_credentials_hash():
config = DeviceConfig(
host="Foo",
http_client=httpx.AsyncClient(),
http_client=aiohttp.ClientSession(),
credentials=Credentials("foo", "bar"),
)
config_dict = config.to_dict(credentials_hash="")
@@ -49,10 +49,10 @@ def test_blank_credentials_hash():
assert config2.credentials is None
def test_exclude_credentials():
async def test_exclude_credentials():
config = DeviceConfig(
host="Foo",
http_client=httpx.AsyncClient(),
http_client=aiohttp.ClientSession(),
credentials=Credentials("foo", "bar"),
)
config_dict = config.to_dict(exclude_credentials=True)