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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
from random import choice
from blebox_uniapi.box_types import (
BOX_TYPE_CONF,
get_conf,
get_conf_set,
get_latest_api_level,
get_latest_conf,
)
class TestBoxTypesOrder:
def test_conf_order(self):
for device_type, conf_set in BOX_TYPE_CONF.items():
api_levels = list(conf_set.keys())
sorted_api_levels = sorted(api_levels)
assert (
api_levels == sorted_api_levels
), f"Entries for '{device_type}' are not ordered by API level."
class TestBoxTypes:
box_types = tuple(BOX_TYPE_CONF.keys())
simple_conf_set = {5: {"tag": "first_entry"}, 10: {"tag": "second_entry"}}
async def test_get_conf_set_valid(self):
conf_set = get_conf_set(choice(self.box_types))
assert isinstance(conf_set, dict)
assert conf_set != {}
async def test_get_conf_set_invalid(self):
conf_set = get_conf_set("nonexistent_type")
assert isinstance(conf_set, dict)
assert conf_set == {}
async def test_get_conf_valid(self):
"""Test choosing functionality of get_conf function on exemplary conf_set."""
for api_level, tag_value in (
(5, "first_entry"), # a marginal example
(7, "first_entry"), # 'in between' example
(10, "second_entry"), # a marginal example
(17, "second_entry"), # future example
):
conf = get_conf(api_level, self.simple_conf_set)
assert isinstance(conf, dict)
assert conf["tag"] == tag_value
async def test_get_conf_invalid(self):
conf = get_conf(3, self.simple_conf_set) # not supported example
assert isinstance(conf, dict)
assert conf == {}
async def test_get_latest_conf_valid(self):
conf = get_latest_conf(choice(self.box_types))
assert isinstance(conf, dict)
assert conf != {}
async def test_get_latest_conf_invalid(self):
conf = get_latest_conf("nonexistent_type")
assert isinstance(conf, dict)
assert conf == {}
async def test_get_latest_api_level_valid(self):
api_level = get_latest_api_level(choice(self.box_types))
assert isinstance(api_level, int)
assert api_level
async def test_get_latest_api_level_invalid(self):
api_level = get_latest_api_level("nonexistent_type")
assert isinstance(api_level, int)
assert not api_level
|