Beispiel #1
0
def test_generate_number_strategy_no_inf_or_nan():
    schema = {"type": "number"}
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    for i in range(100):
        example = strategy.example()
        assert example != POS_INF, i
        assert example != NEG_INF, i
        assert not isnan(example), i
Beispiel #2
0
def test_generate_number_strategy_inclusive(schema_type):
    inc_min = 0
    inc_max = 16
    schema = {"type": schema_type, "minimum": inc_min, "maximum": inc_max}
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    for i in range(100):
        example = strategy.example()
        assert inc_min <= example <= inc_max, i
Beispiel #3
0
def test_generate_number_strategy_exclusive(schema_type):
    exc_min = 0
    exc_max = 16
    schema = {
        "type": schema_type,
        "exclusiveMinimum": exc_min,
        "exclusiveMaximum": exc_max,
    }
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    for i in range(100):
        assert exc_min < strategy.example() < exc_max, i
Beispiel #4
0
def test_generate_array_strategy_items(item_constraint):
    schema = {
        "type": "array",
        item_constraint: {
            "type": "string"
        },
        "minItems": 1
    }
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert isinstance(example, Sequence)
    assert len(example) >= 1
    assert isinstance(example[0], str)
Beispiel #5
0
def test_generate_object_strategy_simple_combiner(combiner):
    schema = {
        "type": "object",
        "properties": {
            "foo": {
                "type": "string",
                combiner: [{
                    "const": "bar"
                }]
            }
        },
    }
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert example == {"foo": "bar"}
Beispiel #6
0
def test_generate_array_strategy_multiple_items():
    schema = {
        "type": "array",
        "items": [{
            "type": "string"
        }, {
            "type": "integer"
        }]
    }
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert isinstance(example, Sequence)
    assert len(example) == 2
    assert isinstance(example[0], str)
    assert isinstance(example[1], int)
Beispiel #7
0
def test_generate_object_strategy_all_of():
    schema = {
        "type": "object",
        "properties": {
            "foo": {
                "allOf": [{
                    "type": "string"
                }, {
                    "const": "bar"
                }]
            }
        },
    }
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert example == {"foo": "bar"}
Beispiel #8
0
def test_generate_strategy_with_refs():
    schema = {
        "properties": {
            "foo": {
                "$ref": "#/definitions/Reference"
            }
        },
        "definitions": {
            "Reference": {
                "type": "integer"
            }
        },
    }
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert isinstance(example["foo"], int)
Beispiel #9
0
def test_generate_array_strategy_simple():
    schema = {"type": "array"}
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    assert isinstance(strategy.example(), Sequence)
Beispiel #10
0
def test_generate_boolean_strategy():
    schema = {"type": "boolean"}
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    assert isinstance(strategy.example(), bool)
Beispiel #11
0
def test_generate_string_strategy_no_constraints():
    schema = {"type": "string"}
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    assert isinstance(strategy.example(), str)
Beispiel #12
0
def test_generate_string_strategy_length():
    schema = {"type": "string", "minLength": 5, "maxLength": 10}
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    for i in range(100):
        assert schema["minLength"] <= len(
            strategy.example()) <= schema["maxLength"], i
Beispiel #13
0
def test_generate_string_strategy_format():
    schema = {"type": "string", "format": "arn"}
    strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    assert re.fullmatch(STRING_FORMATS["arn"], strategy.example())
Beispiel #14
0
def test_generate_string_strategy_regex():
    schema = {"type": "string", "pattern": "^foo+bar+\\Z$"}
    regex_strategy = ResourceGenerator(schema).generate_schema_strategy(schema)
    assert re.fullmatch(schema["pattern"], regex_strategy.example())
Beispiel #15
0
def test_generate_enum_strategy(schema):
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert example in schema["enum"]
Beispiel #16
0
def test_generate_const_strategy(schema):
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert example == schema["const"]
Beispiel #17
0
def test_generate_object_strategy_empty():
    schema = {}
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert example == {}
Beispiel #18
0
def test_generate_object_strategy_properties():
    schema = {"properties": {"foo": {"type": "string", "const": "bar"}}}
    example = ResourceGenerator(schema).generate_schema_strategy(
        schema).example()
    assert example == {"foo": "bar"}