async def test_get_trigger_capabilities_off(hass):
    """Test we get the expected capabilities from a humidifier trigger."""
    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            "platform": "device",
            "domain": "humidifier",
            "type": "turned_off",
            "entity_id": "humidifier.upstairs",
            "above": "23",
        },
    )

    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [{
            "name":
            "for",
            "optional":
            True,
            "type":
            "positive_time_period_dict"
        }]
예제 #2
0
async def test_get_trigger_capabilities_central_scene_value_notification(
        hass, client, wallmote_central_scene, integration):
    """Test we get the expected capabilities from a value_notification.central_scene trigger."""
    dev_reg = async_get_dev_reg(hass)
    device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "type": "event.value_notification.central_scene",
            "device_id": device.id,
            "command_class": CommandClass.CENTRAL_SCENE.value,
            "property": "scene",
            "property_key": "001",
            "endpoint": 0,
            "subtype": "Endpoint 0 Scene 001",
        },
    )
    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [
            {
                "name":
                "value",
                "optional":
                True,
                "type":
                "select",
                "options": [(0, "KeyPressed"), (1, "KeyReleased"),
                            (2, "KeyHeldDown")],
            },
        ]
예제 #3
0
async def test_get_trigger_capabilities_scene_activation_value_notification(
        hass, client, hank_binary_switch, integration):
    """Test we get the expected capabilities from a value_notification.scene_activation trigger."""
    dev_reg = async_get_dev_reg(hass)
    device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "type": "event.value_notification.scene_activation",
            "device_id": device.id,
            "command_class": CommandClass.SCENE_ACTIVATION.value,
            "property": "sceneId",
            "property_key": None,
            "endpoint": 0,
            "subtype": "Endpoint 0",
        },
    )
    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [{
            "name": "value",
            "optional": True,
            "type": "integer",
            "valueMin": 1,
            "valueMax": 255,
        }]
예제 #4
0
async def test_capabilities_missing_entity(hass, device_reg, entity_reg,
                                           action, capability_name, extra):
    """Test getting capabilities."""
    config_entry = MockConfigEntry(domain="test", data={})
    config_entry.add_to_hass(hass)

    capabilities = await device_action.async_get_action_capabilities(
        hass,
        {
            "domain": DOMAIN,
            "device_id": "abcdefgh",
            "entity_id": f"{DOMAIN}.test_5678",
            "type": action,
        },
    )

    expected_capabilities = [{
        "name": capability_name,
        "required": True,
        **extra,
    }]

    assert capabilities and "extra_fields" in capabilities

    assert (voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == expected_capabilities)
예제 #5
0
async def test_get_trigger_capabilities_entry_control_notification(
        hass, client, lock_schlage_be469, integration):
    """Test we get the expected capabilities from a notification.entry_control trigger."""
    dev_reg = async_get_dev_reg(hass)
    device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "device_id": device.id,
            "type": "event.notification.entry_control",
            "command_class": CommandClass.ENTRY_CONTROL.value,
        },
    )
    assert capabilities and "extra_fields" in capabilities

    assert_lists_same(
        voluptuous_serialize.convert(capabilities["extra_fields"],
                                     custom_serializer=cv.custom_serializer),
        [
            {
                "name": "event_type",
                "optional": True,
                "type": "string"
            },
            {
                "name": "data_type",
                "optional": True,
                "type": "string"
            },
        ],
    )
예제 #6
0
def test_dict():
    assert [
        {
            'name': 'name',
            'type': 'string',
            'lengthMin': 5,
            'required': True,
        },
        {
            'name': 'age',
            'type': 'integer',
            'valueMin': 18,
            'required': True,
        },
        {
            'name': 'hobby',
            'type': 'string',
            'default': 'not specified',
            'optional': True,
        }
     ] == convert(vol.Schema({
            vol.Required('name'): vol.All(str, vol.Length(min=5)),
            vol.Required('age'): vol.All(vol.Coerce(int), vol.Range(min=18)),
            vol.Optional('hobby', default='not specified'): str
        }))
예제 #7
0
async def _async_get_device_automation_capabilities(hass, automation_type, automation):
    """List device automations."""
    try:
        platform = await async_get_device_automation_platform(
            hass, automation[CONF_DOMAIN], automation_type
        )
    except InvalidDeviceAutomationConfig:
        return {}

    function_name = TYPES[automation_type][2]

    if not hasattr(platform, function_name):
        # The device automation has no capabilities
        return {}

    try:
        capabilities = await getattr(platform, function_name)(hass, automation)
    except InvalidDeviceAutomationConfig:
        return {}

    capabilities = capabilities.copy()

    extra_fields = capabilities.get("extra_fields")
    if extra_fields is None:
        capabilities["extra_fields"] = []
    else:
        capabilities["extra_fields"] = voluptuous_serialize.convert(
            extra_fields, custom_serializer=cv.custom_serializer
        )

    return capabilities
예제 #8
0
def test_length():
    assert {
        'type': 'string',
        'length-min': 100,
        'length-max': 1000,
    } == convert(
        vol.Schema(vol.All(vol.Coerce(str), vol.Length(min=100, max=1000))))
예제 #9
0
def test_dict():
    assert [{
        'name': 'name',
        'type': 'string',
        'length-min': 5,
        'required': True,
    }, {
        'name': 'age',
        'type': 'integer',
        'value-min': 18,
        'required': True,
    }, {
        'name': 'hobby',
        'type': 'string',
        'default': 'not specified',
        'optional': True,
    }] == convert(
        vol.Schema({
            vol.Required('name'):
            vol.All(str, vol.Length(min=5)),
            vol.Required('age'):
            vol.All(vol.Coerce(int), vol.Range(min=18)),
            vol.Optional('hobby', default='not specified'):
            str
        }))
예제 #10
0
파일: api.py 프로젝트: Claret-Srl/core
async def websocket_get_configuration(hass, connection, msg):
    """Get ZHA configuration."""
    zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
    import voluptuous_serialize  # pylint: disable=import-outside-toplevel

    def custom_serializer(schema: Any) -> Any:
        """Serialize additional types for voluptuous_serialize."""
        if schema is cv_boolean:
            return {"type": "bool"}
        if schema is vol.Schema:
            return voluptuous_serialize.convert(
                schema, custom_serializer=custom_serializer
            )

        return cv.custom_serializer(schema)

    data = {"schemas": {}, "data": {}}
    for section, schema in ZHA_CONFIG_SCHEMAS.items():
        if section == ZHA_ALARM_OPTIONS and not async_cluster_exists(
            hass, IasAce.cluster_id
        ):
            continue
        data["schemas"][section] = voluptuous_serialize.convert(
            schema, custom_serializer=custom_serializer
        )
        data["data"][section] = zha_gateway.config_entry.options.get(
            CUSTOM_CONFIGURATION, {}
        ).get(section, {})
    connection.send_result(msg[ID], data)
예제 #11
0
def test_integer_clamp():
    assert {
        'type': 'integer',
        'value-min': 100,
        'value-max': 1000,
    } == convert(
        vol.Schema(vol.All(vol.Coerce(int), vol.Clamp(min=100, max=1000))))
async def test_get_trigger_capabilities(hass, device_reg, entity_reg):
    """Test we get the expected capabilities from a device_tracker trigger."""
    config_entry = MockConfigEntry(domain="test", data={})
    config_entry.add_to_hass(hass)
    device_entry = device_reg.async_get_or_create(
        config_entry_id=config_entry.entry_id,
        connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
    )
    entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "type": "enters",
            "device_id": device_entry.id,
            "entity_id": f"{DOMAIN}.test_5678",
        },
    )
    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"], custom_serializer=cv.custom_serializer
    ) == [
        {
            "name": "zone",
            "required": True,
            "type": "select",
            "options": [("zone.test", "test"), ("zone.home", "test home")],
        }
    ]
예제 #13
0
async def test_get_condition_capabilities_node_status(
    hass, client, lock_schlage_be469, integration
):
    """Test we don't get capabilities from a node_status condition."""
    dev_reg = device_registry.async_get(hass)
    device = device_registry.async_entries_for_config_entry(
        dev_reg, integration.entry_id
    )[0]

    capabilities = await device_condition.async_get_condition_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "device_id": device.id,
            "type": "node_status",
        },
    )
    assert capabilities and "extra_fields" in capabilities
    assert voluptuous_serialize.convert(
        capabilities["extra_fields"], custom_serializer=cv.custom_serializer
    ) == [
        {
            "name": "status",
            "required": True,
            "type": "select",
            "options": [
                ("asleep", "asleep"),
                ("awake", "awake"),
                ("dead", "dead"),
                ("alive", "alive"),
            ],
        }
    ]
예제 #14
0
async def test_get_fingerprint_trigger_capabilities(hass, entry,
                                                    lcn_connection):
    """Test we get the expected capabilities from a fingerprint device trigger."""
    address = (0, 7, False)
    device = get_device(hass, entry, address)

    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            CONF_PLATFORM: "device",
            CONF_DOMAIN: DOMAIN,
            CONF_TYPE: "fingerprint",
            CONF_DEVICE_ID: device.id,
        },
    )
    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [{
            "name": "code",
            "optional": True,
            "type": "string",
            "lower": True
        }]
예제 #15
0
async def test_get_trigger_capabilities_temp_humid(hass, type):
    """Test we get the expected capabilities from a climate trigger."""
    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            "platform": "device",
            "domain": "climate",
            "type": "current_temperature_changed",
            "entity_id": "climate.upstairs",
            "above": "23",
        },
    )

    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"], custom_serializer=cv.custom_serializer
    ) == [
        {
            "description": {"suffix": "°C"},
            "name": "above",
            "optional": True,
            "type": "float",
        },
        {
            "description": {"suffix": "°C"},
            "name": "below",
            "optional": True,
            "type": "float",
        },
        {"name": "for", "optional": True, "type": "positive_time_period_dict"},
    ]
예제 #16
0
async def test_get_action_capabilities_meter_triggers(
    hass: HomeAssistant,
    client: Client,
    aeon_smart_switch_6: Node,
    integration: ConfigEntry,
) -> None:
    """Test we get the expected action capabilities for meter triggers."""
    node = aeon_smart_switch_6
    dev_reg = device_registry.async_get(hass)
    device = dev_reg.async_get_device({get_device_id(client, node)})
    assert device
    capabilities = await device_action.async_get_action_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "device_id": device.id,
            "entity_id": "sensor.meter",
            "type": "reset_meter",
        },
    )
    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [{
            "type": "string",
            "name": "value",
            "optional": True
        }]
예제 #17
0
def test_in():
    assert {
        'type': 'select',
        'options': [
            ('beer', 'beer'),
            ('wine', 'wine'),
        ],
    } == convert(vol.Schema(vol.In(['beer', 'wine'])))
예제 #18
0
def test_length():
    assert {
        'type': 'string',
        'lengthMin': 100,
        'lengthMax': 1000,
    } == convert(vol.Schema(
            vol.All(vol.Coerce(str),
                    vol.Length(min=100, max=1000))))
예제 #19
0
def test_in():
    assert {
        'type': 'select',
        'options': [
            ('beer', 'beer'),
            ('wine', 'wine'),
        ],
    } == convert(vol.Schema(vol.In(['beer', 'wine'])))
예제 #20
0
def test_integer_clamp():
    assert {
        'type': 'integer',
        'valueMin': 100,
        'valueMax': 1000,
    } == convert(vol.Schema(
            vol.All(vol.Coerce(int),
                    vol.Clamp(min=100, max=1000))))
예제 #21
0
def test_in_dict():
    assert {
        'type': 'select',
        'options': [
            ('en_US', 'American English'),
            ('zh_CN', 'Chinese (Simplified)'),
        ],
    } == convert(vol.Schema(vol.In(
        {'en_US': 'American English', 'zh_CN': 'Chinese (Simplified)'})))
예제 #22
0
    def custom_serializer(schema: Any) -> Any:
        """Serialize additional types for voluptuous_serialize."""
        if schema is cv_boolean:
            return {"type": "bool"}
        if schema is vol.Schema:
            return voluptuous_serialize.convert(
                schema, custom_serializer=custom_serializer)

        return cv.custom_serializer(schema)
예제 #23
0
def test_in_dict():
    assert {
        'type': 'select',
        'options': [
            ('en_US', 'American English'),
            ('zh_CN', 'Chinese (Simplified)'),
        ],
    } == convert(vol.Schema(vol.In(
        {'en_US': 'American English', 'zh_CN': 'Chinese (Simplified)'})))
예제 #24
0
def test_marker_description():
    assert [{
        'name': 'name',
        'type': 'string',
        'description': 'Description of name',
        'required': True,
    }] == convert(vol.Schema({
        vol.Required('name', description='Description of name'): str,
    }))
예제 #25
0
def test_marker_description():
    assert [{
        'name': 'name',
        'type': 'string',
        'description': 'Description of name',
        'required': True,
    }] == convert(vol.Schema({
        vol.Required('name', description='Description of name'): str,
    }))
예제 #26
0
def test_mapping_schema():
    assert {
        'type': 'mapping',
        'key': {
            'type': 'integer'
        },
        'value': {
            'type': 'string'
        }
    } == convert(vol.Schema({int: str}))
예제 #27
0
async def test_get_action_capabilities(hass: HomeAssistant) -> None:
    """Test we get the expected capabilities from a select action."""
    config = {
        "platform": "device",
        "domain": DOMAIN,
        "type": "select_option",
        "entity_id": "select.test",
        "option": "option1",
    }

    # Test when entity doesn't exists
    capabilities = await async_get_action_capabilities(hass, config)
    assert capabilities
    assert "extra_fields" in capabilities
    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [
            {
                "name": "option",
                "required": True,
                "type": "select",
                "options": [],
            },
        ]

    # Mock an entity
    hass.states.async_set("select.test", "option1",
                          {"options": ["option1", "option2"]})

    # Test if we get the right capabilities now
    capabilities = await async_get_action_capabilities(hass, config)
    assert capabilities
    assert "extra_fields" in capabilities
    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [
            {
                "name": "option",
                "required": True,
                "type": "select",
                "options": [("option1", "option1"), ("option2", "option2")],
            },
        ]
예제 #28
0
def test_dictionary_schema():
    assert [{
        'type': 'dictionary',
        'dictionary': [{
            'type': 'string',
            'name': 'def'
        }],
        'name': 'abc'
    }] == convert(vol.Schema({"abc": {
        "def": str
    }}))
예제 #29
0
def test_custom_serializer():
    def custem_serializer(schema):
        if schema is str:
            return {'type': 'a string!'}
        return UNSUPPORTED

    assert {
        'type': 'a string!',
        'upper': True,
    } == convert(vol.Schema(vol.All(vol.Upper, str)),
                 custom_serializer=custem_serializer)
예제 #30
0
async def test_get_trigger_capabilities_node_status(
    hass, client, lock_schlage_be469, integration
):
    """Test we get the expected capabilities from a node_status trigger."""
    dev_reg = async_get_dev_reg(hass)
    device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
    ent_reg = async_get_ent_reg(hass)
    entity_id = async_get_node_status_sensor_entity_id(
        hass, device.id, ent_reg, dev_reg
    )
    ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
    await hass.config_entries.async_reload(integration.entry_id)
    await hass.async_block_till_done()

    capabilities = await device_trigger.async_get_trigger_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "device_id": device.id,
            "entity_id": entity_id,
            "type": "state.node_status",
        },
    )
    assert capabilities and "extra_fields" in capabilities

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"], custom_serializer=cv.custom_serializer
    ) == [
        {
            "name": "from",
            "optional": True,
            "options": [
                ("asleep", "asleep"),
                ("awake", "awake"),
                ("dead", "dead"),
                ("alive", "alive"),
            ],
            "type": "select",
        },
        {
            "name": "to",
            "optional": True,
            "options": [
                ("asleep", "asleep"),
                ("awake", "awake"),
                ("dead", "dead"),
                ("alive", "alive"),
            ],
            "type": "select",
        },
        {"name": "for", "optional": True, "type": "positive_time_period_dict"},
    ]
예제 #31
0
async def test_get_condition_capabilities_value(hass, client,
                                                lock_schlage_be469,
                                                integration):
    """Test we get the expected capabilities from a value condition."""
    dev_reg = device_registry.async_get(hass)
    device = device_registry.async_entries_for_config_entry(
        dev_reg, integration.entry_id)[0]

    capabilities = await device_condition.async_get_condition_capabilities(
        hass,
        {
            "platform": "device",
            "domain": DOMAIN,
            "device_id": device.id,
            "type": "value",
        },
    )
    assert capabilities and "extra_fields" in capabilities

    cc_options = [(cc.value, cc.name) for cc in CommandClass]

    assert voluptuous_serialize.convert(
        capabilities["extra_fields"],
        custom_serializer=cv.custom_serializer) == [
            {
                "name": "command_class",
                "required": True,
                "options": cc_options,
                "type": "select",
            },
            {
                "name": "property",
                "required": True,
                "type": "string"
            },
            {
                "name": "property_key",
                "optional": True,
                "type": "string"
            },
            {
                "name": "endpoint",
                "optional": True,
                "type": "string"
            },
            {
                "name": "value",
                "required": True,
                "type": "string"
            },
        ]
예제 #32
0
def _get_config_params(node, *args):
    raw_values = get_config_parameters(node)
    config_params = []

    for param in raw_values:
        schema = {}

        if param["type"] in ["Byte", "Int", "Short"]:
            schema = vol.Schema({
                vol.Required(param["label"], default=param["value"]):
                vol.All(vol.Coerce(int),
                        vol.Range(min=param["min"], max=param["max"]))
            })
            data = {param["label"]: param["value"]}

        if param["type"] == "List":

            for options in param["options"]:
                if options["Label"] == param["value"]:
                    selected = options
                    break

            schema = vol.Schema({
                vol.Required(param["label"], ):
                vol.In({
                    option["Value"]: option["Label"]
                    for option in param["options"]
                })
            })
            data = {param["label"]: selected["Value"]}

        config_params.append({
            "type":
            param["type"],
            "label":
            param["label"],
            "parameter":
            param["parameter"],
            "help":
            param["help"],
            "value":
            param["value"],
            "schema":
            voluptuous_serialize.convert(
                schema, custom_serializer=cv.custom_serializer),
            "data":
            data,
        })

    return config_params
예제 #33
0
def _prepare_json(result):
    """Convert result for JSON."""
    if result["type"] != data_entry_flow.RESULT_TYPE_FORM:
        return result

    data = result.copy()

    schema = data["data_schema"]
    if schema is None:
        data["data_schema"] = []
    else:
        data["data_schema"] = voluptuous_serialize.convert(schema)

    return data
예제 #34
0
async def test_capabilities(
    hass,
    device_reg,
    entity_reg,
    set_state,
    capabilities_reg,
    capabilities_state,
    condition,
    expected_capabilities,
):
    """Test getting capabilities."""
    config_entry = MockConfigEntry(domain="test", data={})
    config_entry.add_to_hass(hass)
    device_entry = device_reg.async_get_or_create(
        config_entry_id=config_entry.entry_id,
        connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
    )
    entity_reg.async_get_or_create(
        DOMAIN,
        "test",
        "5678",
        device_id=device_entry.id,
        capabilities=capabilities_reg,
    )
    if set_state:
        hass.states.async_set(
            f"{DOMAIN}.test_5678",
            const.HVAC_MODE_COOL,
            capabilities_state,
        )

    capabilities = await device_condition.async_get_condition_capabilities(
        hass,
        {
            "condition": "device",
            "domain": DOMAIN,
            "device_id": "abcdefgh",
            "entity_id": f"{DOMAIN}.test_5678",
            "type": condition,
        },
    )

    assert capabilities and "extra_fields" in capabilities

    assert (
        voluptuous_serialize.convert(
            capabilities["extra_fields"], custom_serializer=cv.custom_serializer
        )
        == expected_capabilities
    )
예제 #35
0
def _prepare_json(result):
    """Convert result for JSON."""
    if result['type'] != data_entry_flow.RESULT_TYPE_FORM:
        return result

    import voluptuous_serialize

    data = result.copy()

    schema = data['data_schema']
    if schema is None:
        data['data_schema'] = []
    else:
        data['data_schema'] = voluptuous_serialize.convert(schema)

    return data
def _prepare_json(result):
    """Convert result for JSON."""
    if result['type'] != config_entries.RESULT_TYPE_FORM:
        return result

    import voluptuous_serialize

    data = result.copy()

    schema = data['data_schema']
    if schema is None:
        data['data_schema'] = []
    else:
        data['data_schema'] = voluptuous_serialize.convert(schema)

    return data
예제 #37
0
def _get_toggle_properties(device):
    """Generate the mask properties for a KPL device."""
    props = []
    schema = {}
    toggle_prop = device.properties[NON_TOGGLE_MASK]
    toggle_on_prop = device.properties[NON_TOGGLE_ON_OFF_MASK]
    for button in device.groups:
        name = f"{TOGGLE_PROP}{device.groups[button].name}"
        value, modified = _toggle_button_value(toggle_prop, toggle_on_prop, button)
        props.append({"name": name, "value": value, "modified": modified})
        toggle_schema = vol.Schema({vol.Required(name): vol.In(TOGGLE_MODES_SCHEMA)})
        toggle_schema_dict = voluptuous_serialize.convert(
            toggle_schema, custom_serializer=cv.custom_serializer
        )
        schema[name] = toggle_schema_dict[0]
    return props, schema
예제 #38
0
    def _prepare_result_json(self, result):
        """Convert result to JSON."""
        if result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
            data = result.copy()
            data.pop('result')
            data.pop('data')
            return data

        elif result['type'] != data_entry_flow.RESULT_TYPE_FORM:
            return result

        import voluptuous_serialize

        data = result.copy()

        schema = data['data_schema']
        if schema is None:
            data['data_schema'] = []
        else:
            data['data_schema'] = voluptuous_serialize.convert(schema)

        return data
예제 #39
0
def test_strip():
    assert {
        'type': 'string',
        'strip': True,
    } == convert(vol.Schema(vol.All(vol.Strip, str)))
예제 #40
0
def test_lower():
    assert {
        'type': 'string',
        'lower': True,
    } == convert(vol.Schema(vol.All(vol.Lower, str)))
예제 #41
0
def test_str_schema():
    for value in str, vol.Coerce(str):
        assert {'type': 'string'} == convert(vol.Schema(value))
예제 #42
0
def test_capitalize():
    assert {
        'type': 'string',
        'capitalize': True,
    } == convert(vol.Schema(vol.All(vol.Capitalize, str)))
예제 #43
0
def test_upper():
    assert {
        'type': 'string',
        'upper': True,
    } == convert(vol.Schema(vol.All(vol.Upper, str)))
예제 #44
0
def test_title():
    assert {
        'type': 'string',
        'title': True,
    } == convert(vol.Schema(vol.All(vol.Title, str)))
예제 #45
0
def test_float_schema():
    for value in float, vol.Coerce(float):
        assert {'type': 'float'} == convert(vol.Schema(value))
예제 #46
0
def test_bool_schema():
    for value in bool, vol.Coerce(bool):
        assert {'type': 'boolean'} == convert(vol.Schema(value))
예제 #47
0
def test_datetime():
    assert {
        'type': 'datetime',
        'format': '%Y-%m-%dT%H:%M:%S.%fZ',
    } == convert(vol.Schema(vol.Datetime()))
예제 #48
0
def test_int_schema():
    for value in int, vol.Coerce(int):
        assert {'type': 'integer'} == convert(vol.Schema(value))