From 364c9fe9eba3a8edc3264d77972cca9a40dcde7a Mon Sep 17 00:00:00 2001 From: Dan LaManna Date: Mon, 29 Aug 2022 17:01:15 -0400 Subject: [PATCH] Migrate zarr tests --- dandiapi/api/tests/factories.py | 36 ---------------- dandiapi/{api/tests => }/conftest.py | 8 ++-- dandiapi/zarr/tests/factories.py | 43 +++++++++++++++++++ .../tests/test_ingest_zarr_archive.py | 0 .../tests/test_migrate_zarr_checksums.py | 0 dandiapi/{api => zarr}/tests/test_zarr.py | 0 .../tests/test_zarr_checksums.py | 0 .../{api => zarr}/tests/test_zarr_upload.py | 0 8 files changed, 47 insertions(+), 40 deletions(-) rename dandiapi/{api/tests => }/conftest.py (97%) create mode 100644 dandiapi/zarr/tests/factories.py rename dandiapi/{api => zarr}/tests/test_ingest_zarr_archive.py (100%) rename dandiapi/{api => zarr}/tests/test_migrate_zarr_checksums.py (100%) rename dandiapi/{api => zarr}/tests/test_zarr.py (100%) rename dandiapi/{api => zarr}/tests/test_zarr_checksums.py (100%) rename dandiapi/{api => zarr}/tests/test_zarr_upload.py (100%) diff --git a/dandiapi/api/tests/factories.py b/dandiapi/api/tests/factories.py index 0e40500fd..b71a54e65 100644 --- a/dandiapi/api/tests/factories.py +++ b/dandiapi/api/tests/factories.py @@ -19,7 +19,6 @@ UserMetadata, Version, ) -from dandiapi.zarr.models import ZarrArchive, ZarrUploadFile class UserMetadataFactory(factory.django.DjangoModelFactory): @@ -234,38 +233,3 @@ def etag(self): class EmbargoedUploadFactory(UploadFactory): class Meta: model = EmbargoedUpload - - -class ZarrArchiveFactory(factory.django.DjangoModelFactory): - class Meta: - model = ZarrArchive - - zarr_id = factory.Faker('uuid4') - name = factory.Faker('catch_phrase') - dandiset = factory.SubFactory(DandisetFactory) - - -class ZarrUploadFileFactory(factory.django.DjangoModelFactory): - class Meta: - model = ZarrUploadFile - - zarr_archive = factory.SubFactory(ZarrArchiveFactory) - - @factory.lazy_attribute - def path(self): - # No / prefix - return faker.Faker().file_path(extension='nwb')[1:] - - @factory.lazy_attribute - def blob(self): - return django_files.File( - django_files.base.ContentFile(faker.Faker().binary(length=100)).file, - self.zarr_archive.s3_path(self.path), - ) - - @factory.lazy_attribute - def etag(self): - h = hashlib.md5() - h.update(self.blob.read()) - self.blob.seek(0) - return h.hexdigest() diff --git a/dandiapi/api/tests/conftest.py b/dandiapi/conftest.py similarity index 97% rename from dandiapi/api/tests/conftest.py rename to dandiapi/conftest.py index 8d7122d3a..dd865b04f 100644 --- a/dandiapi/api/tests/conftest.py +++ b/dandiapi/conftest.py @@ -7,8 +7,7 @@ from storages.backends.s3boto3 import S3Boto3Storage from dandiapi.api.storage import create_s3_storage - -from .factories import ( +from dandiapi.api.tests.factories import ( AssetBlobFactory, DandisetFactory, DraftAssetFactory, @@ -20,9 +19,8 @@ SocialAccountFactory, UploadFactory, UserFactory, - ZarrArchiveFactory, - ZarrUploadFileFactory, ) +from dandiapi.zarr.tests.factories import ZarrArchiveFactory, ZarrUploadFileFactory register(PublishedAssetFactory, _name='published_asset') register(DraftAssetFactory, _name='draft_asset') @@ -38,6 +36,8 @@ register(UserFactory) register(SocialAccountFactory) register(UploadFactory) + +# zarr app register(ZarrArchiveFactory) register(ZarrUploadFileFactory) diff --git a/dandiapi/zarr/tests/factories.py b/dandiapi/zarr/tests/factories.py new file mode 100644 index 000000000..2e10089cc --- /dev/null +++ b/dandiapi/zarr/tests/factories.py @@ -0,0 +1,43 @@ +import hashlib + +from django.core import files as django_files +import factory +import faker + +from dandiapi.api.tests.factories import DandisetFactory +from dandiapi.zarr.models import ZarrArchive, ZarrUploadFile + + +class ZarrArchiveFactory(factory.django.DjangoModelFactory): + class Meta: + model = ZarrArchive + + zarr_id = factory.Faker('uuid4') + name = factory.Faker('catch_phrase') + dandiset = factory.SubFactory(DandisetFactory) + + +class ZarrUploadFileFactory(factory.django.DjangoModelFactory): + class Meta: + model = ZarrUploadFile + + zarr_archive = factory.SubFactory(ZarrArchiveFactory) + + @factory.lazy_attribute + def path(self): + # No / prefix + return faker.Faker().file_path(extension='nwb')[1:] + + @factory.lazy_attribute + def blob(self): + return django_files.File( + django_files.base.ContentFile(faker.Faker().binary(length=100)).file, + self.zarr_archive.s3_path(self.path), + ) + + @factory.lazy_attribute + def etag(self): + h = hashlib.md5() + h.update(self.blob.read()) + self.blob.seek(0) + return h.hexdigest() diff --git a/dandiapi/api/tests/test_ingest_zarr_archive.py b/dandiapi/zarr/tests/test_ingest_zarr_archive.py similarity index 100% rename from dandiapi/api/tests/test_ingest_zarr_archive.py rename to dandiapi/zarr/tests/test_ingest_zarr_archive.py diff --git a/dandiapi/api/tests/test_migrate_zarr_checksums.py b/dandiapi/zarr/tests/test_migrate_zarr_checksums.py similarity index 100% rename from dandiapi/api/tests/test_migrate_zarr_checksums.py rename to dandiapi/zarr/tests/test_migrate_zarr_checksums.py diff --git a/dandiapi/api/tests/test_zarr.py b/dandiapi/zarr/tests/test_zarr.py similarity index 100% rename from dandiapi/api/tests/test_zarr.py rename to dandiapi/zarr/tests/test_zarr.py diff --git a/dandiapi/api/tests/test_zarr_checksums.py b/dandiapi/zarr/tests/test_zarr_checksums.py similarity index 100% rename from dandiapi/api/tests/test_zarr_checksums.py rename to dandiapi/zarr/tests/test_zarr_checksums.py diff --git a/dandiapi/api/tests/test_zarr_upload.py b/dandiapi/zarr/tests/test_zarr_upload.py similarity index 100% rename from dandiapi/api/tests/test_zarr_upload.py rename to dandiapi/zarr/tests/test_zarr_upload.py