1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
import pytest
from blebox_uniapi.session import ApiHost
from blebox_uniapi.box import Box
from blebox_uniapi import error
from .conftest import json_get_expect
@pytest.fixture
def data():
return {
"id": "abcd1234ef",
"type": "unknownBox",
"deviceName": "foobar",
"fv": "1.23",
"hv": "4.56",
"apiLevel": "20180403",
}
class TestUnknownDevice:
async def test_unknown_product(self, aioclient_mock, data):
host = "172.1.2.3"
with pytest.raises(error.UnsupportedBoxResponse, match=r"unknownBox"):
full_data = {"device": data}
json_get_expect(
aioclient_mock, f"http://{host}:80/api/device/state", json=full_data
)
port = 80
timeout = 2
api_host = ApiHost(host, port, timeout, aioclient_mock, None, None)
await Box.async_from_host(api_host)
async def test_unknown_product_without_device_section(self, aioclient_mock, data):
host = "172.1.2.3"
with pytest.raises(error.UnsupportedBoxResponse, match=r"unknownBox"):
json_get_expect(
aioclient_mock, f"http://{host}:80/api/device/state", json=data
)
port = 80
timeout = 2
api_host = ApiHost(host, port, timeout, aioclient_mock, None, None)
await Box.async_from_host(api_host)
async def test_unknown_product_without_device_and_type(self, aioclient_mock, data):
host = "172.1.2.3"
with pytest.raises(error.UnsupportedBoxResponse, match=r"has no type"):
del data["type"]
json_get_expect(
aioclient_mock, f"http://{host}:80/api/device/state", json=data
)
port = 80
timeout = 2
api_host = ApiHost(host, port, timeout, aioclient_mock, None, None)
await Box.async_from_host(api_host)
|