def test_checksum(faker, storage: Storage): name = faker.file_name() sentence = bytes(faker.sentence(), 'utf-8') content = ContentFile(sentence) storage.save(name, content) h = hashlib.sha256() h.update(sentence) expected_sha256 = h.hexdigest() actual_sha256 = calculate_sha256_checksum(storage, name) assert actual_sha256 == expected_sha256
def test_write_dandiset_yaml_already_exists(storage: Storage, version: Version): # Pretend like AssetBlob was defined with the given storage # The task piggybacks off of the AssetBlob storage to write the yamls AssetBlob.blob.field.storage = storage # Save an invalid file for the task to overwrite dandiset_yaml_path = ( f'{settings.DANDI_DANDISETS_BUCKET_PREFIX}' f'dandisets/{version.dandiset.identifier}/{version.version}/dandiset.yaml' ) storage.save(dandiset_yaml_path, ContentFile(b'wrong contents')) write_dandiset_yaml(version) expected = YAMLRenderer().render(version.metadata) with storage.open(dandiset_yaml_path) as f: assert f.read() == expected
def test_write_assets_yaml_already_exists(storage: Storage, version: Version, asset_factory): # Pretend like AssetBlob was defined with the given storage # The task piggybacks off of the AssetBlob storage to write the yamls AssetBlob.blob.field.storage = storage # Create a new asset in the version so there is information to write version.assets.add(asset_factory()) # Save an invalid file for the task to overwrite assets_yaml_path = ( f'{settings.DANDI_DANDISETS_BUCKET_PREFIX}' f'dandisets/{version.dandiset.identifier}/{version.version}/assets.yaml' ) storage.save(assets_yaml_path, ContentFile(b'wrong contents')) write_assets_yaml(version) expected = YAMLRenderer().render( [asset.metadata for asset in version.assets.all()]) with storage.open(assets_yaml_path) as f: assert f.read() == expected