示例#1
0
def test_accept_integer_values_for_decimal_properties(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72,  # specify height as a whole number
        "age": 40,
        "sex": "M",
    }
    result = v.validate_records(properties, records)
    assert result.ok
示例#2
0
def test_bad_enumeration_value(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72.0,
        "age": 40,
        "sex": "G",
    }
    result = v.validate_records(properties, records)
    assert "[G] not in" in str(result.error("sex"))
示例#3
0
def test_bad_value_for_type(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": 898989,
        "height": 72.0,
        "age": 40,
        "sex": "M",
    }
    result = v.validate_records(properties, records)
    assert "not a string: 898989" in str(result.error("name")).lower()
示例#4
0
def test_invalid_record_id_value(properties):
    records = {
        "id": 1234,  # bad
        "name": "Joseph Schmoe",
        "height": 72.0,
        "age": 40,
        "sex": "M",
    }
    result = v.validate_records(properties, records)
    assert not result.ok
示例#5
0
def test_valid_records(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Joseph Schmoe",
        "age": 40,
        "height": 72.0,
        "sex": "M",
    }
    result = v.validate_records(properties, records)
    assert result.ok
示例#6
0
def test_accept_enums_with_valid_values(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72,
        "age": 40,
        "sex": "M",
        "favorite_color": "red",
    }
    result = v.validate_records(properties, records)
    assert result.ok
示例#7
0
def test_reject_bad_enum_values(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72,
        "age": 40,
        "sex": "M",
        "favorite_color": "purple",
    }
    result = v.validate_records(properties, records)
    assert "not in enum ['red', 'green', 'blue']" in str(result.error("favorite_color"))
示例#8
0
def test_accept_strings_with_valid_format_value(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72,  # specify height as a whole number
        "age": 40,
        "sex": "M",
        "email": "*****@*****.**",
    }
    result = v.validate_records(properties, records)
    assert result.ok
示例#9
0
def test_accept_valid_email_uri(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72,
        "age": 40,
        "sex": "M",
        "email": "*****@*****.**",
        "url": "http://www.hvac-dude.biz",
    }
    result = v.validate_records(properties, records)
    assert result.ok
示例#10
0
def test_validate_array_data_types(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72,  # specify height as a whole number
        "age": 40,
        "sex": "M",
        "email": "*****@*****.**",
        "favorite_numbers": ["red", "green"],
    }
    result = v.validate_records(properties, records)
    assert "Not a Long" in str(result.error("favorite_numbers"))
示例#11
0
def test_reject_invalid_email_uri(properties):
    records = {
        "id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9",
        "name": "Broseph Schmoe",
        "height": 72,
        "age": 40,
        "sex": "M",
        "email": "foobar",
        "url": "foobar",
    }
    result = v.validate_records(properties, records)
    assert "Not a String(Email): foobar" in str(result.error("email"))
    assert "Not a String(URL): foobar" in str(result.error("url"))
示例#12
0
def test_missing_record_property(properties):
    # missing name, height, and age
    records = {"id": "a009fee1-71f8-4b1f-aa62-7ad5ed91a4c9", "sex": "M"}
    result = v.validate_records(properties, records)
    assert not result.ok
    assert "missing required property" in str(result.error("name")).lower()