mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Raise SmartDeviceException on invalid config dicts (#640)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -2,6 +2,7 @@ from json import dumps as json_dumps
|
||||
from json import loads as json_loads
|
||||
|
||||
import aiohttp
|
||||
import pytest
|
||||
|
||||
from kasa.credentials import Credentials
|
||||
from kasa.deviceconfig import (
|
||||
@@ -10,6 +11,7 @@ from kasa.deviceconfig import (
|
||||
DeviceFamilyType,
|
||||
EncryptType,
|
||||
)
|
||||
from kasa.exceptions import SmartDeviceException
|
||||
|
||||
|
||||
async def test_serialization():
|
||||
@@ -21,6 +23,19 @@ async def test_serialization():
|
||||
assert config == config2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("input_value", "expected_msg"),
|
||||
[
|
||||
({"Foo": "Bar"}, "Cannot create dataclass from dict, unknown key: Foo"),
|
||||
("foobar", "Invalid device config data: foobar"),
|
||||
],
|
||||
ids=["invalid-dict", "not-dict"],
|
||||
)
|
||||
def test_deserialization_errors(input_value, expected_msg):
|
||||
with pytest.raises(SmartDeviceException, match=expected_msg):
|
||||
DeviceConfig.from_dict(input_value)
|
||||
|
||||
|
||||
async def test_credentials_hash():
|
||||
config = DeviceConfig(
|
||||
host="Foo",
|
||||
|
Reference in New Issue
Block a user