Пример #1
0
def test_optional_schema_list(coresys):
    """Test with an optional list schema."""
    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "extend": ["str?"]
        },
        MOCK_ADDON_NAME,
        MOCK_ADDON_SLUG,
    )({
        "name": "Pascal",
        "password": "******"
    })

    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "extend": ["str?"]
        },
        MOCK_ADDON_NAME,
        MOCK_ADDON_SLUG,
    )({
        "name": "Pascal",
        "password": "******",
        "extend": []
    })

    with pytest.raises(vol.error.Invalid):
        AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "extend": ["str"]
            },
            MOCK_ADDON_NAME,
            MOCK_ADDON_SLUG,
        )({
            "name": "Pascal",
            "password": "******"
        })

    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "extend": ["str"]
        },
        MOCK_ADDON_NAME,
        MOCK_ADDON_SLUG,
    )({
        "name": "Pascal",
        "password": "******",
        "extend": []
    })
Пример #2
0
def test_simple_schema(coresys):
    """Test with simple schema."""
    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "fires": "bool",
            "alias": "str?"
        },
    )({
        "name": "Pascal",
        "password": "******",
        "fires": True,
        "alias": "test"
    })

    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "fires": "bool",
            "alias": "str?"
        },
    )({
        "name": "Pascal",
        "password": "******",
        "fires": True
    })

    with pytest.raises(vol.error.Invalid):
        AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "fires": "bool",
                "alias": "str?"
            },
        )({
            "name": "Pascal",
            "password": "******",
            "fires": "hah"
        })

    with pytest.raises(vol.error.Invalid):
        AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "fires": "bool",
                "alias": "str?"
            },
        )({
            "name": "Pascal",
            "fires": True
        })
Пример #3
0
def test_complex_schema_dict(coresys):
    """Test with complex dict schema."""
    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "extend": {
                "test": "int"
            }
        },
        MOCK_ADDON_NAME,
        MOCK_ADDON_SLUG,
    )({
        "name": "Pascal",
        "password": "******",
        "extend": {
            "test": 1
        }
    })

    with pytest.raises(vol.error.Invalid):
        AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "extend": {
                    "test": "int"
                }
            },
            MOCK_ADDON_NAME,
            MOCK_ADDON_SLUG,
        )({
            "name": "Pascal",
            "password": "******",
            "extend": {
                "wrong": 1
            }
        })

    with pytest.raises(vol.error.Invalid):
        AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "extend": ["str"]
            },
            MOCK_ADDON_NAME,
            MOCK_ADDON_SLUG,
        )({
            "name": "Pascal",
            "password": "******",
            "extend": "test"
        })
Пример #4
0
def test_complex_schema_list(coresys):
    """Test with complex list schema."""
    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "extend": ["str"]
        },
        MOCK_ADDON_NAME,
        MOCK_ADDON_SLUG,
    )({
        "name": "Pascal",
        "password": "******",
        "extend": ["test", "blu"]
    })

    with pytest.raises(vol.error.Invalid):
        AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "extend": ["str"]
            },
            MOCK_ADDON_NAME,
            MOCK_ADDON_SLUG,
        )({
            "name": "Pascal",
            "password": "******",
            "extend": ["test", 1]
        })

    with pytest.raises(vol.error.Invalid):
        AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "extend": ["str"]
            },
            MOCK_ADDON_NAME,
            MOCK_ADDON_SLUG,
        )({
            "name": "Pascal",
            "password": "******",
            "extend": "test"
        })
Пример #5
0
def test_simple_schema_password(coresys):
    """Test with simple schema password pwned."""
    validate = AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "fires": "bool",
            "alias": "str?"
        },
        MOCK_ADDON_NAME,
        MOCK_ADDON_SLUG,
    )

    assert validate({
        "name": "Pascal",
        "password": "******",
        "fires": True,
        "alias": "test"
    })

    assert validate.pwned == {"7110eda4d09e062aa5e4a390b0a572ac0d2c0220"}

    validate.pwned.clear()
    assert validate({
        "name": "Pascal",
        "password": "",
        "fires": True,
        "alias": "test"
    })

    assert not validate.pwned
Пример #6
0
def test_log_entry(coresys, caplog):
    """Test log entry when no option match in schema."""
    options = AddonOptions(coresys, {}, MOCK_ADDON_NAME, MOCK_ADDON_SLUG)({
        "test":
        "str"
    })
    assert options == {}
    assert (
        "Option 'test' does not exist in the schema for Mock Add-on (mock_addon)"
        in caplog.text)
Пример #7
0
def test_simple_device_schema(coresys):
    """Test with simple schema."""
    for device in (
            Device(
                "ttyACM0",
                Path("/dev/ttyACM0"),
                Path("/sys/bus/usb/002"),
                "tty",
                [],
                {"ID_VENDOR": "xy"},
            ),
            Device(
                "ttyUSB0",
                Path("/dev/ttyUSB0"),
                Path("/sys/bus/usb/001"),
                "tty",
                [Path("/dev/ttyS1"),
                 Path("/dev/serial/by-id/xyx")],
                {"ID_VENDOR": "xy"},
            ),
            Device("ttyS0", Path("/dev/ttyS0"), Path("/sys/bus/usb/003"),
                   "tty", [], {}),
            Device(
                "video1",
                Path("/dev/video1"),
                Path("/sys/bus/usb/004"),
                "misc",
                [],
                {"ID_VENDOR": "xy"},
            ),
    ):
        coresys.hardware.update_device(device)

    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "input": "device"
        },
    )({
        "name": "Pascal",
        "password": "******",
        "input": "/dev/ttyUSB0"
    })

    data = AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "input": "device"
        },
    )({
        "name": "Pascal",
        "password": "******",
        "input": "/dev/serial/by-id/xyx"
    })
    assert data["input"] == "/dev/ttyUSB0"

    assert AddonOptions(
        coresys,
        {
            "name": "str",
            "password": "******",
            "input": "device(subsystem=tty)"
        },
    )({
        "name": "Pascal",
        "password": "******",
        "input": "/dev/ttyACM0"
    })

    with pytest.raises(vol.error.Invalid):
        assert AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "input": "device"
            },
        )({
            "name": "Pascal",
            "password": "******",
            "input": "/dev/not_exists"
        })

    with pytest.raises(vol.error.Invalid):
        assert AddonOptions(
            coresys,
            {
                "name": "str",
                "password": "******",
                "input": "device(subsystem=tty)"
            },
        )({
            "name": "Pascal",
            "password": "******",
            "input": "/dev/video1"
        })