Skip to content
Open
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
16 changes: 14 additions & 2 deletions shotgun_api3/lib/mockgun/mockgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" %
Expand Down Expand Up @@ -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):

Expand Down
24 changes: 24 additions & 0 deletions tests/test_mockgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,5 +755,29 @@
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"}

Check warning on line 770 in tests/test_mockgun.py

View check run for this annotation

ShotGrid Chorus / security/bandit

B108: hardcoded_tmp_directory

Probable insecure usage of temp file/directory. secure coding id: SEC-PY-AUTHZ-003.
)
self.assertEqual(task["color"], "255,0,0")
self.assertEqual(task["image"], "/tmp/thumb.jpg")

Check warning on line 773 in tests/test_mockgun.py

View check run for this annotation

ShotGrid Chorus / security/bandit

B108: hardcoded_tmp_directory

Probable insecure usage of temp file/directory. secure coding id: SEC-PY-AUTHZ-003.
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()
Loading