Skip to content

Mockgun: implement upload - #469

Open
patrickwolf wants to merge 1 commit into
shotgunsoftware:masterfrom
patrickwolf:mockgun-upload
Open

patrickwolf wants to merge 1 commit into
shotgunsoftware:masterfrom
patrickwolf:mockgun-upload

Conversation

@patrickwolf

Copy link
Copy Markdown

Problem

Mockgun.upload raises NotImplementedError, so any code that uploads (a movie to a Version, a file to a Shot) cannot be tested on Mockgun.

Change

upload now leaves the records an upload leaves on the server, without storing the file:

  • It validates like Shotgun.upload: the entity must exist, the path must be an existing non-empty file, and field_name must be a File/Link field. Each failure raises ShotgunError.
  • It creates an Attachment linked to the entity (attachment_links), with filename, display_name, file_size, file_extension, the entity's project and an optional created_at. Fields the site's schema lacks are skipped.
  • tag_list, a comma-separated string as for Shotgun.upload, sets the Attachment's tag_list to the tag names.
  • The Attachment's this_file and the entity's field_name get the same value the server gives: type, id, name, link_type: "upload", content_type, and a url of the form <server>/file_serve/attachment/<id>.
  • For a thumbnail field (thumb_image, filmstrip_thumb_image, image, filmstrip_image) the entity's image or filmstrip_image is set to that URL.
  • It returns the Attachment's id, as the server does.

Downloading the file back is a separate PR built on this one.

Tests

TestUpload: upload to a File/Link field, without a field, with tags, to a thumbnail field, and each validation error.

python -m pytest tests/test_mockgun.py

Merge order

Independent of the other Mockgun PRs (field types, default value types, limit and page), but each of them also adds its test class at the end of tests/test_mockgun.py. Whichever is merged later needs a rebase that keeps both test classes. The download PR builds on this one and goes in after it.

upload raised NotImplementedError. It now validates the path and the field as the server does and creates the records an upload leaves: an Attachment linked to the entity, holding the file's name, size and tags, and the File/Link field pointing at it. A thumbnail field sets the entity's image field. The file itself is not stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant