Ejemplo n.º 1
0
def test_validate_missing_type():
    schema = {
        'title': 'Example',
        '_type': 'text'
    }
    instance = {
        '_type': 'text',
        'text': 'test'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 2
0
def test_validate_text_max_length():
    schema = {
        'title': 'Example',
        'type': 'text',
        'maxLength': 10
    }
    instance = {
        '_type': 'text',
        'text': 'test'
    }
    validate(instance, schema)
Ejemplo n.º 3
0
def test_validate_bool_invalid_type():
    schema = {
        'title': 'Example',
        'type': 'bool'
    }
    instance = {
        '_type': 'boolean',
        'value': True
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 4
0
def test_validate_plotly_chart_invalid_type():
    schema = {
        'title': 'Example',
        'type': 'plotly_chart'
    }
    instance = {
        '_type': 'text',
        'plotly': {"data": [{"name": "test", "type": "scatter", "x": [1,2,3], "y": [1,2,3]}]}
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 5
0
def test_validate_array():
    schema = {
        'title': 'Example',
        'type': 'array',
        'items': {
            'title': 'Example Item',
            'type': 'text'
        }
    }
    instance = [{'_type': 'text', 'text': 'test'}]
    validate(instance, schema)
Ejemplo n.º 6
0
def test_validate_sample_invalid_object_id():
    schema = {
        'title': 'Example',
        'type': 'sample'
    }
    instance = {
        '_type': 'sample',
        'object_id': 42
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 7
0
def test_validate_minimal_quantity():
    schema = {
        'title': 'Example',
        'type': 'quantity',
        'units': 'm'
    }
    instance = {
        '_type': 'quantity',
        'magnitude': 3
    }
    validate(instance, schema)
Ejemplo n.º 8
0
def test_validate_user_invalid_user_id():
    schema = {
        'title': 'Example User',
        'type': 'user'
    }
    instance = {
        '_type': 'user',
        'user_id': 42
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 9
0
def test_validate_quantity_invalid_key():
    schema = {'title': 'Example', 'type': 'quantity', 'units': 'm'}
    instance = {
        '_type': 'quantity',
        'units': 'm',
        'dimensionality': '[length]',
        'magnitude_in_base_units': 1e-3,
        'default': True
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 10
0
def test_validate_text_choices():
    schema = {
        'title': 'Example',
        'type': 'text',
        'choices': ["A", "B", "C"]
    }
    instance = {
        '_type': 'text',
        'text': 'B'
    }
    validate(instance, schema)
Ejemplo n.º 11
0
def test_validate_datetime_invalid_type():
    schema = {
        'title': 'Example',
        'type': 'datetime'
    }
    instance = {
        '_type': 'date',
        'utc_datetime': '2017-03-31 10:20:30'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 12
0
def test_validate_text_pattern():
    schema = {
        'title': 'Example',
        'type': 'text',
        'pattern': '^[1-9][0-9]*/[A-Za-z]+'
    }
    instance = {
        '_type': 'text',
        'text': '42/Test'
    }
    validate(instance, schema)
Ejemplo n.º 13
0
def test_validate_datetime_invalid_datetime_type():
    schema = {
        'title': 'Example',
        'type': 'datetime'
    }
    instance = {
        '_type': 'datetime',
        'utc_datetime': datetime.datetime.now()
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 14
0
def test_validate_invalid_schema_type():
    schema = [{
        'title': 'Example',
        'type': 'text'
    }]
    instance = {
        '_type': 'text',
        'text': 'test'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 15
0
def test_validate_tags_duplicate_tags():
    schema = {
        'title': 'Example',
        'type': 'tags'
    }
    instance = {
        '_type': 'tags',
        'tags': ['tag', 'other', 'tag']
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 16
0
def test_validate_tags_invalid_content():
    schema = {
        'title': 'Example',
        'type': 'tags'
    }
    instance = {
        '_type': 'tags',
        'tags': 'tag,other,keyword'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 17
0
def test_validate_array_invalid_item_type():
    schema = {
        'title': 'Example',
        'type': 'array',
        'items': {
            'title': 'Example Item',
            'type': 'text'
        }
    }
    instance = [{'_type': 'bool', 'value': True}]
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 18
0
def test_validate_quantity_missing_key():
    schema = {
        'title': 'Example',
        'type': 'quantity',
        'units': 'm'
    }
    instance = {
        '_type': 'quantity',
        'dimensionality': '[length]',
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 19
0
def test_validate_text_invalid_key():
    schema = {
        'title': 'Example',
        'type': 'text'
    }
    instance = {
        '_type': 'text',
        'text': 'test',
        'locale': 'en_US'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 20
0
def test_validate_text_invalid_max_length():
    schema = {
        'title': 'Example',
        'type': 'text',
        'maxLength': 1
    }
    instance = {
        '_type': 'text',
        'text': 'test'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 21
0
def test_validate_text_pattern_mismatch():
    schema = {
        'title': 'Example',
        'type': 'text',
        'pattern': '[1-9][0-9]*/[A-Za-z]+'
    }
    instance = {
        '_type': 'text',
        'text': '02/Test'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 22
0
def test_validate_text_invalid_choice():
    schema = {
        'title': 'Example',
        'type': 'text',
        'choices': ['A', 'B', 'C']
    }
    instance = {
        '_type': 'text',
        'text': 'D'
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 23
0
def test_convert_object():
    data = {
        'name': {
            '_type': 'text',
            'text': 'Example, Text'
        },
        'keywords': {
            '_type': 'text',
            'text': 'tag1, tag2'
        }
    }
    previous_schema = {
        'type': 'object',
        'title': 'Test',
        'properties': {
            'name': {
                'title': 'Name',
                'type': 'text'
            },
            'keywords': {
                'title': 'Keywords',
                'type': 'text'
            }
        }
    }
    new_schema = {
        'type': 'object',
        'title': 'Test',
        'properties': {
            'name': {
                'title': 'Name',
                'type': 'text'
            },
            'keywords': {
                'title': 'Keywords',
                'type': 'tags'
            }
        }
    }
    validate(data, previous_schema)
    new_data, warnings = convert_to_schema(data, previous_schema, new_schema)
    assert new_data == {
        'name': {
            '_type': 'text',
            'text': 'Example, Text'
        },
        'keywords': {
            '_type': 'tags',
            'tags': ['tag1', 'tag2']
        }
    }
    assert not warnings
Ejemplo n.º 24
0
def test_validate_quantity_missing_key():
    schema = {
        'title': 'Example',
        'type': 'quantity',
        'units': 'm'
    }
    instance = {
        '_type': 'quantity',
        'units': 'm',
        'magnitude_in_base_units': 1e-3
    }
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 25
0
def test_validate_quantity():
    schema = {
        'title': 'Example',
        'type': 'quantity',
        'units': 'm'
    }
    instance = {
        '_type': 'quantity',
        'units': 'm',
        'dimensionality': '[length]',
        'magnitude_in_base_units': 1e-3
    }
    validate(instance, schema)
Ejemplo n.º 26
0
def test_validate_object():
    schema = {
        'title': 'Example',
        'type': 'object',
        'properties': {
            'example': {
                'title': 'Example Item',
                'type': 'text'
            }
        }
    }
    instance = {}
    validate(instance, schema)
Ejemplo n.º 27
0
def test_validate_array_invalid_max_items():
    schema = {
        'title': 'Example',
        'type': 'array',
        'items': {
            'title': 'Example Item',
            'type': 'text'
        },
        'maxItems': 0
    }
    instance = [{'_type': 'text', 'text': 'test'}]
    with pytest.raises(ValidationError):
        validate(instance, schema)
Ejemplo n.º 28
0
def test_validate_quantity_pure_magnitude():
    schema = {
        'title': 'Example',
        'type': 'quantity',
        'units': 'm'
    }
    instance = {
        '_type': 'quantity',
        'units': 'm',
        'dimensionality': '[length]',
        'magnitude': 3
    }
    validate(instance, schema)
Ejemplo n.º 29
0
def test_convert_quantities_differing_dimensionality():
    data = {
        '_type': 'quantity',
        'dimensionality': '[length]',
        'magnitude_in_base_units': 1,
        'units': 'm'
    }
    previous_schema = {'type': 'quantity', 'title': 'Test', 'units': 'm'}
    new_schema = {'type': 'quantity', 'title': 'Test', 'units': 'ms'}
    validate(data, previous_schema)
    new_data, warnings = convert_to_schema(data, previous_schema, new_schema)
    assert new_data is None
    assert warnings
Ejemplo n.º 30
0
def test_validate_object_invalid_property():
    schema = {
        'title': 'Example',
        'type': 'object',
        'properties': {
            'example': {
                'title': 'Example',
                'type': 'text'
            }
        }
    }
    instance = {'example': {'_type': 'bool', 'value': True}}
    with pytest.raises(ValidationError):
        validate(instance, schema)