예제 #1
0
def test_default_values_array_value():
    schema = {
        "type": "object",
        "properties": {
            "foo": with_default(Properties.array, [])
        },
        "required": [],
    }
    try:
        obj = {}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": []}
        obj = {"foo": ["bar"]}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": ["bar"]}
    except DCIException:
        pytest.fail("default array value doesn't work")
예제 #2
0
def test_default_values_boolean_value():
    schema = {
        "type": "object",
        "properties": {
            "foo": with_default(Properties.boolean, False)
        },
        "required": [],
    }
    try:
        obj = {}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": False}
        obj = {"foo": True}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": True}
    except DCIException:
        pytest.fail("default boolean value doesn't work")
예제 #3
0
def test_default_values_none_value():
    schema = {
        "type": "object",
        "properties": {
            "foo": with_default(Properties.uuid, None)
        },
        "required": [],
    }
    try:
        obj = {}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": None}
        obj = {"foo": "b82dca4a-0597-4c70-b90f-0c422fc05c38"}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": "b82dca4a-0597-4c70-b90f-0c422fc05c38"}
    except DCIException:
        pytest.fail("default None value doesn't work")
예제 #4
0
def test_default_values_string_value():
    schema = {
        "type": "object",
        "properties": {
            "foo": with_default(Properties.string, "bar")
        },
        "required": [],
    }
    try:
        obj = {}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": "bar"}
        obj = {"foo": "foo"}
        check_json_is_valid(schema, obj)
        assert obj == {"foo": "foo"}
    except DCIException:
        pytest.fail("default string value doesn't work")