def test_validate_text_with_pattern(): schema = { 'title': 'Example', 'type': 'text', 'pattern': '^[1-9][0-9]*/[A-Za-z]+$' } validate_schema(wrap_into_basic_schema(schema))
def test_validate_measurement_schema(): schema = { 'title': 'Example', 'type': 'measurement', 'note': 'Example Note' } validate_schema(wrap_into_basic_schema(schema))
def test_nested_hazards_in_object(): schema = { 'title': 'Object', 'type': 'object', 'properties': { 'name': { 'title': 'Name', 'type': 'text' }, 'nested': { 'title': 'Nested Object', 'type': 'object', 'properties': { 'name': { 'title': 'Name', 'type': 'text' }, 'hazards': { 'title': 'GHS hazards', 'type': 'hazards' } }, 'required': ['name', 'hazards'] } }, 'required': ['name', 'hazards'] } validate_schema(schema['properties']['nested']) with pytest.raises(ValidationError): validate_schema(schema)
def test_validate_datetime_schema_default(): schema = { 'title': 'Example', 'type': 'datetime', 'default': '2017-03-31 10:20:30' } validate_schema(wrap_into_basic_schema(schema))
def test_validate_schema_invalid_type(): schema = {'title': 'Example', 'type': 'invalid'} with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema)) schema = {'title': 'Example', 'type': b'bool'} with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_quantity_schema_note(): schema = { 'title': 'Example', 'type': 'quantity', 'units': 'm', 'note': 'Example Note' } validate_schema(wrap_into_basic_schema(schema))
def test_validate_quantity_schema_default(): schema = { 'title': 'Example', 'type': 'quantity', 'units': 'm', 'default': 1.5 } validate_schema(wrap_into_basic_schema(schema))
def test_validate_object_reference_schema(): schema = { 'title': 'Example', 'type': 'object_reference', 'note': 'Example Note', 'action_type_id': ActionType.SAMPLE_CREATION } validate_schema(wrap_into_basic_schema(schema))
def test_validate_text_with_invalid_pattern_type(): schema = { 'title': 'Example', 'type': 'text', 'pattern': b'^[1-9][0-9]*/[A-Za-z]+$' } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_object_reference_schema_with_invalid_action_type_id(): schema = { 'title': 'Example', 'type': 'object_reference', 'action_type_id': 'measurement' } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_object_reference_schema_with_action_type_id_none(): schema = { 'title': 'Example', 'type': 'object_reference', 'note': 'Example Note', 'action_type_id': None } validate_schema(wrap_into_basic_schema(schema))
def test_validate_text_with_min_and_max_length(): schema = { 'title': 'Example', 'type': 'text', 'minLength': 1, 'maxLength': 10 } validate_schema(wrap_into_basic_schema(schema))
def test_validate_plotly_chart_schema_invalid_key(): schema = { 'title': 'Example', 'type': 'plotly_chart', 'invalid Key': 'test' } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_quantity_schema_with_placeholder(): schema = { 'title': 'Example', 'type': 'quantity', 'units': 'm', 'placeholder': 'Placeholder' } validate_schema(wrap_into_basic_schema(schema))
def test_validate_datetime_schema_invalid_key(): schema = { 'title': 'Example', 'type': 'datetime', 'utc_datetime': '2017-03-31 10:20:30' } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_datetime_schema_invalid_default_type(): schema = { 'title': 'Example', 'type': 'datetime', 'default': datetime.datetime.now() } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_quantity_schema_with_invalid_placeholder(): schema = { 'title': 'Example', 'type': 'quantity', 'units': 'm', 'placeholder': 1 } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_quantity_schema_invalid_key(): schema = { 'title': 'Example', 'type': 'quantity', 'units': 'm', 'magnitude_in_base_units': '1.5' } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_text_invalid_min_and_max_length(): schema = { 'title': 'Example', 'type': 'text', 'minLength': 10, 'maxLength': 1 } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_text_with_placeholder_and_choices(): schema = { 'title': 'Example', 'type': 'text', 'placeholder': 'Placeholder', 'choices': ['A', 'B', 'C'] } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_array_schema(): schema = { 'title': 'Example', 'type': 'array', 'items': { 'title': 'Example Item', 'type': 'text' } } validate_schema(wrap_into_basic_schema(schema))
def test_validate_object_reference_schema_with_invalid_action_id_type(): schema = { 'title': 'Example', 'type': 'object_reference', 'note': 'Example Note', 'action_type_id': ActionType.SAMPLE_CREATION, 'action_id': '1' } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_array_schema_with_style(): schema = { 'title': 'Example', 'type': 'array', 'items': { 'title': 'Example Item', 'type': 'text' }, 'style': 'table' } validate_schema(wrap_into_basic_schema(schema))
def test_validate_object_schema_invalid_properties_type(): schema = { 'title': 'Example', 'type': 'object', 'properties': [{ 'title': 'Example', 'type': 'text' }] } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_array_schema_invalid_default(): schema = { 'title': 'Example', 'type': 'array', 'items': { 'title': 'Example Item', 'type': 'text' }, 'default': [1] } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_array_schema_invalid_max_items_type(): schema = { 'title': 'Example', 'type': 'array', 'items': { 'title': 'Example Item', 'type': 'text' }, 'maxItems': 1.0 } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_array_schema_with_invalid_style(): schema = { 'title': 'Example', 'type': 'array', 'items': { 'title': 'Example Item', 'type': 'text' }, 'style': 'grid' } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))
def test_validate_object_schema(): schema = { 'title': 'Example', 'type': 'object', 'properties': { 'example': { 'title': 'Example', 'type': 'text' } } } validate_schema(wrap_into_basic_schema(schema))
def test_validate_object_schema_with_display_properties(): schema = { 'title': 'Example', 'type': 'object', 'properties': { 'name': { 'title': 'Example Property', 'type': 'text' } }, 'required': ['name'], 'displayProperties': ['name'] } validate_schema(schema)
def test_validate_object_schema_required_unknown_property(): schema = { 'title': 'Example', 'type': 'object', 'properties': { 'example': { 'title': 'Example', 'type': 'text' } }, 'required': ['unknown'] } with pytest.raises(ValidationError): validate_schema(wrap_into_basic_schema(schema))