From 6f11d018ed681c82b28862e26a974b964a31463b Mon Sep 17 00:00:00 2001 From: Patrick Wolf <758811+patrickwolf@users.noreply.github.com> Date: Sun, 15 Nov 2026 22:00:00 +0000 Subject: [PATCH] Mockgun: support currency, timecode, uuid, color, password, image and jsonb fields Writing to a field of one of these types raised "Handling for Flow Production Tracking type ... is not implemented", so a schema read from a real site could not be written to. They are now validated by the Python type the server takes, and filtered and sorted like the type that holds the same values. Co-Authored-By: Claude Opus 5.5 --- shotgun_api3/lib/mockgun/mockgun.py | 16 ++++++++++++++-- tests/test_mockgun.py | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/shotgun_api3/lib/mockgun/mockgun.py b/shotgun_api3/lib/mockgun/mockgun.py index 522e162d9..f65b390c7 100644 --- a/shotgun_api3/lib/mockgun/mockgun.py +++ b/shotgun_api3/lib/mockgun/mockgun.py @@ -122,6 +122,9 @@ from .errors import MockgunError from .schema import SchemaFactory +# Field types Mockgun compares and sorts like another type that holds the same values. +_COMPARE_AS = {"currency": "float", "timecode": "number", "uuid": "text", "color": "text", "password": "text"} + # ---------------------------------------------------------------------------- # Version __version__ = "0.0.1" @@ -535,7 +538,14 @@ def _validate_entity_data(self, entity_type, data): "duration": int, "list": str, "status_list": str, - "url": dict}[sg_type] + "url": dict, + "currency": (int, float), + "timecode": int, + "uuid": str, + "color": str, + "password": str, + "image": str, + "jsonb": dict}[sg_type] except KeyError: raise ShotgunError( "Field %s.%s: Handling for Flow Production Tracking type %s is not implemented" % @@ -763,7 +773,9 @@ def _get_field_type(self, entity_type, field): field2, entity_type2, field3 = field.split(".", 2) return self._get_field_type(entity_type2, field3) except ValueError: - return self._schema[entity_type][field]["data_type"]["value"] + field_type = self._schema[entity_type][field]["data_type"]["value"] + # Filter and sort these like the type that holds the same values. + return _COMPARE_AS.get(field_type, field_type) def _row_matches_filter(self, entity_type, row, sg_filter, retired_only): diff --git a/tests/test_mockgun.py b/tests/test_mockgun.py index b12c318f7..4575703b5 100644 --- a/tests/test_mockgun.py +++ b/tests/test_mockgun.py @@ -755,5 +755,29 @@ def test_set_server_params_with_url_with_path(self): self.assertEqual(mockgun.config.api_path, "/something/api3/json") +class TestMoreFieldTypes(unittest.TestCase): + """ + Writes to and filters on field types that Mockgun used to reject. + """ + + def setUp(self): + self._mockgun = Mockgun( + "https://test.shotgunstudio.com", login="user", password="1234" + ) + + def test_color_and_image(self): + task = self._mockgun.create( + "Task", {"content": "comp", "color": "255,0,0", "image": "/tmp/thumb.jpg"} + ) + self.assertEqual(task["color"], "255,0,0") + self.assertEqual(task["image"], "/tmp/thumb.jpg") + found = self._mockgun.find("Task", [["color", "starts_with", "255"]], ["color"]) + self.assertEqual([t["id"] for t in found], [task["id"]]) + + def test_wrong_python_type_still_rejected(self): + with self.assertRaises(ShotgunError): + self._mockgun.create("Task", {"content": "comp", "color": 255}) + + if __name__ == "__main__": unittest.main()