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()