| 1 |
from random import choice |
| 2 |
|
| 3 |
from blebox_uniapi.box_types import ( |
| 4 |
BOX_TYPE_CONF, |
| 5 |
get_conf, |
| 6 |
get_conf_set, |
| 7 |
get_latest_api_level, |
| 8 |
get_latest_conf, |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
class TestBoxTypesOrder: |
| 13 |
def test_conf_order(self): |
| 14 |
for device_type, conf_set in BOX_TYPE_CONF.items(): |
| 15 |
api_levels = list(conf_set.keys()) |
| 16 |
sorted_api_levels = sorted(api_levels) |
| 17 |
|
| 18 |
assert ( |
| 19 |
api_levels == sorted_api_levels |
| 20 |
), f"Entries for '{device_type}' are not ordered by API level." |
| 21 |
|
| 22 |
|
| 23 |
class TestBoxTypes: |
| 24 |
box_types = tuple(BOX_TYPE_CONF.keys()) |
| 25 |
simple_conf_set = {5: {"tag": "first_entry"}, 10: {"tag": "second_entry"}} |
| 26 |
|
| 27 |
async def test_get_conf_set_valid(self): |
| 28 |
conf_set = get_conf_set(choice(self.box_types)) |
| 29 |
|
| 30 |
assert isinstance(conf_set, dict) |
| 31 |
assert conf_set != {} |
| 32 |
|
| 33 |
async def test_get_conf_set_invalid(self): |
| 34 |
conf_set = get_conf_set("nonexistent_type") |
| 35 |
|
| 36 |
assert isinstance(conf_set, dict) |
| 37 |
assert conf_set == {} |
| 38 |
|
| 39 |
async def test_get_conf_valid(self): |
| 40 |
"""Test choosing functionality of get_conf function on exemplary conf_set.""" |
| 41 |
for api_level, tag_value in ( |
| 42 |
(5, "first_entry"), |
| 43 |
(7, "first_entry"), |
| 44 |
(10, "second_entry"), |
| 45 |
(17, "second_entry"), |
| 46 |
): |
| 47 |
conf = get_conf(api_level, self.simple_conf_set) |
| 48 |
|
| 49 |
assert isinstance(conf, dict) |
| 50 |
assert conf["tag"] == tag_value |
| 51 |
|
| 52 |
async def test_get_conf_invalid(self): |
| 53 |
conf = get_conf(3, self.simple_conf_set) |
| 54 |
|
| 55 |
assert isinstance(conf, dict) |
| 56 |
assert conf == {} |
| 57 |
|
| 58 |
async def test_get_latest_conf_valid(self): |
| 59 |
conf = get_latest_conf(choice(self.box_types)) |
| 60 |
|
| 61 |
assert isinstance(conf, dict) |
| 62 |
assert conf != {} |
| 63 |
|
| 64 |
async def test_get_latest_conf_invalid(self): |
| 65 |
conf = get_latest_conf("nonexistent_type") |
| 66 |
|
| 67 |
assert isinstance(conf, dict) |
| 68 |
assert conf == {} |
| 69 |
|
| 70 |
async def test_get_latest_api_level_valid(self): |
| 71 |
api_level = get_latest_api_level(choice(self.box_types)) |
| 72 |
|
| 73 |
assert isinstance(api_level, int) |
| 74 |
assert api_level |
| 75 |
|
| 76 |
async def test_get_latest_api_level_invalid(self): |
| 77 |
api_level = get_latest_api_level("nonexistent_type") |
| 78 |
|
| 79 |
assert isinstance(api_level, int) |
| 80 |
assert not api_level |