Exemple #1
0
def test_validate_asset_metadata(asset: Asset):
    tasks.validate_asset_metadata(asset.id)

    asset.refresh_from_db()

    assert asset.status == Asset.Status.VALID
    assert asset.validation_errors == []
Exemple #2
0
def test_validate_asset_metadata_no_schema_version(asset: Asset):
    asset.metadata = {}
    asset.save()

    tasks.validate_asset_metadata(asset.id)

    asset.refresh_from_db()

    assert asset.status == Asset.Status.INVALID
    assert len(asset.validation_errors) == 1
    assert asset.validation_errors[0]['field'] == ''
    assert asset.validation_errors[0]['message'].startswith(
        'Metadata version None is not allowed.')
Exemple #3
0
def test_validate_asset_metadata_no_digest(asset: Asset):
    asset.blob.sha256 = None
    asset.blob.save()

    tasks.validate_asset_metadata(asset.id)

    asset.refresh_from_db()

    assert asset.status == Asset.Status.INVALID
    assert asset.validation_errors == [{
        'field':
        'digest',
        'message':
        'A non-zarr asset must have a sha2_256.'
    }]
Exemple #4
0
def test_validate_asset_metadata_malformed_keywords(asset: Asset):
    asset.metadata['keywords'] = 'foo'
    asset.save()

    tasks.validate_asset_metadata(asset.id)

    asset.refresh_from_db()

    assert asset.status == Asset.Status.INVALID
    assert asset.validation_errors == [{
        'field':
        'keywords',
        'message':
        "'foo' is not of type 'array'"
    }]
Exemple #5
0
def test_validate_asset_metadata_no_encoding_format(asset: Asset):
    del asset.metadata['encodingFormat']
    asset.save()

    tasks.validate_asset_metadata(asset.id)

    asset.refresh_from_db()

    assert asset.status == Asset.Status.INVALID
    assert asset.validation_errors == [{
        'field':
        '',
        'message':
        "'encodingFormat' is a required property"
    }]