Пример #1
0
def test_bootstrap(bootstrap):
    obj = Bootstrap.from_unifi_dict(**deepcopy(bootstrap))

    set_no_debug()
    obj_construct = Bootstrap.from_unifi_dict(**deepcopy(bootstrap))
    set_debug()

    obj_dict = obj.unifi_dict()

    # TODO:
    del bootstrap["legacyUFVs"]
    del bootstrap["displays"]
    del bootstrap["doorlocks"]
    del bootstrap["chimes"]
    del bootstrap["schedules"]
    del bootstrap["nvr"]["uiVersion"]
    del bootstrap["nvr"]["errorCode"]
    del bootstrap["nvr"]["wifiSettings"]
    del bootstrap["nvr"]["ssoChannel"]
    del bootstrap["nvr"]["smartDetectAgreement"]

    for model_type in ModelType.bootstrap_models():
        key = model_type + "s"
        expected_data = bootstrap.pop(key)
        actual_data = obj_dict.pop(key)

        assert len(expected_data) == len(actual_data)

        for index, expected in enumerate(expected_data):
            actual = actual_data[index]
            compare_objs(expected["modelKey"], expected, actual)

    assert bootstrap == obj_dict
    assert obj == obj_construct
Пример #2
0
def test_bootstrap_benchmark_construct(bootstrap, benchmark: BenchmarkFixture):
    set_no_debug()

    def create():
        Bootstrap.from_unifi_dict(**deepcopy(bootstrap))

    benchmark.pedantic(create, rounds=50, iterations=5)
    set_debug()
Пример #3
0
def compare_devices(data):
    obj = create_from_unifi_dict(deepcopy(data))
    obj_dict = obj.unifi_dict()
    compare_objs(obj.model.value, data, obj_dict)

    set_no_debug()
    obj_construct = create_from_unifi_dict(deepcopy(data))
    assert obj == obj_construct
    set_debug()
Пример #4
0
def test_bootstrap_device_not_adopted_no_api(bootstrap):
    bootstrap["cameras"][0]["isAdopted"] = False
    obj = Bootstrap.from_unifi_dict(**deepcopy(bootstrap))

    set_no_debug()
    obj_construct: Bootstrap = Bootstrap.from_unifi_dict(**deepcopy(bootstrap))
    set_debug()

    assert len(obj.cameras) == len(bootstrap["cameras"])
    assert obj.cameras == obj_construct.cameras
Пример #5
0
def test_bootstrap_device_not_adopted(bootstrap, protect_client: ProtectApiClient):
    bootstrap["cameras"][0]["isAdopted"] = False
    obj: Bootstrap = Bootstrap.from_unifi_dict(**deepcopy(bootstrap), api=protect_client)

    set_no_debug()
    obj_construct: Bootstrap = Bootstrap.from_unifi_dict(**deepcopy(bootstrap), api=protect_client)
    set_debug()

    assert len(obj.cameras) == len(bootstrap["cameras"]) - 1
    assert obj.cameras == obj_construct.cameras
Пример #6
0
def test_bootstrap(bootstrap):
    obj = Bootstrap.from_unifi_dict(**deepcopy(bootstrap))

    set_no_debug()
    obj_construct = Bootstrap.from_unifi_dict(**deepcopy(bootstrap))
    set_debug()

    obj_dict = obj.unifi_dict()

    # TODO:
    del bootstrap["legacyUFVs"]
    del bootstrap["displays"]
    del bootstrap["chimes"]
    del bootstrap["schedules"]
    if "deviceGroups" in bootstrap:
        del bootstrap["deviceGroups"]
    del bootstrap["nvr"]["uiVersion"]
    del bootstrap["nvr"]["errorCode"]
    del bootstrap["nvr"]["wifiSettings"]
    del bootstrap["nvr"]["ssoChannel"]
    del bootstrap["nvr"]["smartDetectAgreement"]
    bootstrap["nvr"]["systemInfo"].pop("ustorage", None)

    for model_type in ModelType.bootstrap_models():
        key = model_type + "s"
        expected_data = bootstrap.pop(key)
        actual_data = obj_dict.pop(key)

        assert len(expected_data) == len(actual_data)

        for index, expected in enumerate(expected_data):
            actual = actual_data[index]
            compare_objs(expected["modelKey"], expected, actual)

    for key in NEW_FIELDS.intersection(obj_dict["nvr"].keys()):
        if key not in bootstrap["nvr"]:
            del obj_dict["nvr"][key]
    bootstrap["nvr"]["ports"]["piongw"] = bootstrap["nvr"]["ports"].get("piongw")

    assert bootstrap == obj_dict
    assert obj == obj_construct
Пример #7
0
async def protect_client_ws():
    set_no_debug()

    client = ProtectApiClient("127.0.0.1", 0, "username", "password")
    yield await setup_client(client, MockWebsocket(), timeout=30)
    await cleanup_client(client)