Beispiel #1
0
def test_DataPackageFileAttributesAreValid_unknown_checksum_hash(
        tempdir: pathlib.Path):
    """If no checksum hash is declared, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    (tempdir / 'a').touch()
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)
Beispiel #2
0
def test_DataPackageFileAttributesAreValid_match(tempdir: pathlib.Path):
    """Test that file attributes can be correct."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    df.checksum_hash = dpack_pb2.SHA256
    df.checksum = SHA256_EMPTY_FILE
    (tempdir / 'a').touch()
    assert dpack.DataPackageFileAttributesAreValid(tempdir, df)
Beispiel #3
0
def test_DataPackageFileAttributesAreValid_different_checksum(
        tempdir: pathlib.Path):
    """If checksum of file differs, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    df.checksum_hash = dpack_pb2.SHA256
    (tempdir / 'a').touch()
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)
Beispiel #4
0
def test_DataPackageFileAttributesAreValid_different_size(
        tempdir: pathlib.Path):
    """If the size of a file is incorect, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    df.checksum_hash = dpack_pb2.SHA256
    df.checksum = SHA256_EMPTY_FILE
    df.size_in_bytes = 10  # An empty file has size 0
    (tempdir / 'a').touch()
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)
Beispiel #5
0
def test_SetDataPackageFileAttributes_empty_file(tempdir: pathlib.Path):
    """Test that file attributes are set."""
    df = dpack_pb2.DataPackageFile()
    (tempdir / 'a').touch()
    dpack.SetDataPackageFileAttributes(tempdir, 'a', df)

    assert df.relative_path == 'a'
    assert not df.size_in_bytes
    assert df.checksum_hash == dpack_pb2.SHA256
    assert df.checksum == SHA256_EMPTY_FILE
Beispiel #6
0
def test_DataPackageFileAttributesAreValid_missing_file(tempdir: pathlib.Path):
    """If a file does not exist, attributes are not valid."""
    df = dpack_pb2.DataPackageFile()
    df.relative_path = 'a'
    assert not dpack.DataPackageFileAttributesAreValid(tempdir, df)