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
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"))
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()
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
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
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
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"))
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
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
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"))
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"))
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()