Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve broken fixtures in dev dataset script for local Dandi #1722

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ When running the "Develop with Docker" configuration, all tox commands must be r
Run `tox` to launch the full test suite.

Individual test environments may be selectively run.
This also allows additional options to be be added.
This also allows additional options to be added.
Useful sub-commands include:
* `tox -e lint`: Run only the style checks
* `tox -e type`: Run only the type checks
Expand Down Expand Up @@ -122,7 +122,7 @@ to call.

### Creating a Token
Visit the URL `/admin` with a web browser, logging
in with the credentials entered during the `createsuperuser` setup step..
in with the credentials entered during the `createsuperuser` setup step.
Then go to `/swagger` and use `GET /auth/token` end-point.

### Supplying the Token
Expand Down
21 changes: 15 additions & 6 deletions dandiapi/api/management/commands/create_dev_dandiset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
from uuid import uuid4

from django.conf import settings
Expand All @@ -15,8 +16,13 @@
@click.command()
@click.option('--name', default='Development Dandiset')
@click.option('--owner', 'email', required=True, help='The email address of the owner')
def create_dev_dandiset(name: str, email: str):
@click.option('--first_name', default='Randi')
@click.option('--last_name', default='Dandi')
def create_dev_dandiset(name: str, email: str, first_name: str, last_name: str):
owner = User.objects.get(email=email)
owner.first_name = first_name
owner.last_name = last_name
owner.save()

version_metadata = {
'description': 'An informative description',
Expand All @@ -26,16 +32,19 @@ def create_dev_dandiset(name: str, email: str):
user=owner, embargo=False, version_name=name, version_metadata=version_metadata
)

uploaded_file = SimpleUploadedFile(name='foo/bar.txt', content=b'A' * 20)
file_size = 20
file_content = b'A' * file_size
uploaded_file = SimpleUploadedFile(name='foo/bar.txt', content=file_content)
etag = '76d36e98f312e98ff908c8c82c8dd623-0'

try:
asset_blob = AssetBlob.objects.get(etag=etag)
except AssetBlob.DoesNotExist:
# Since the SimpleUploadedFile is non-zarr asset, validation fails
# without a sha2_256 initially provided.
sha256_hash = hashlib.sha256(file_content).hexdigest()
asset_blob = AssetBlob(
blob_id=uuid4(),
blob=uploaded_file,
etag=etag,
size=20,
blob_id=uuid4(), blob=uploaded_file, etag=etag, size=file_size, sha256=sha256_hash
)
asset_blob.save()
asset_metadata = {
Expand Down