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