Skip to content

Commit

Permalink
SG-30702 Skip SG-MIM entities (shotgunsoftware#285)
Browse files Browse the repository at this point in the history
* Skip MIM entities

* Apply black formatter

* Add notes and clean-up
  • Loading branch information
carlos-villavicencio-adsk authored Apr 24, 2023
1 parent 091821f commit abad460
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tests/config
.cache
.travis-solo
htmlcov
test-output.xml

# setup related
build
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines-templates/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
# Specifies which version of Python we want to use. That's where the strategy comes in.
# Each job will share this set of steps, but each of them will receive a different
# $(python.version)
# TODO: We should provide `githubToken` if we want to download a python release.
# Otherwise we may hit the GitHub anonymous download limit.
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
Expand Down
90 changes: 58 additions & 32 deletions tests/test_api_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class TestShotgunApiLong(base.LiveTestBase):

def test_automated_find(self):
"""Called find for each entity type and read all fields"""

Expand All @@ -35,8 +34,16 @@ def test_automated_find(self):
limit = 1
page = 1
for entity_type in all_entities:
if entity_type in ("Asset", "Task", "Shot", "Attachment",
"Candidate"):
if entity_type in (
"Asset",
"Task",
"Shot",
"Attachment",
"Candidate",
"MimProject",
"MimEntity",
"MimField",
):
continue
print("Finding entity type %s" % entity_type)

Expand All @@ -54,21 +61,27 @@ def test_automated_find(self):
# Since no_sorting is not exposed to us, we'll have to rely on
# this as a safeguard against trying to sort by a field with
# allow_sorting=false.
if field['data_type']["value"] in sortable_types:
if field["data_type"]["value"] in sortable_types:
order_field = field_name
break
# TODO for our test project, we haven't populated these entities....
order = None
if order_field:
order = [{'field_name': order_field, 'direction': direction}]
order = [{"field_name": order_field, "direction": direction}]
if "project" in fields:
filters = [['project', 'is', self.project]]
filters = [["project", "is", self.project]]
else:
filters = []

records = self.sg.find(entity_type, filters, fields=list(fields.keys()),
order=order, filter_operator=filter_operator,
limit=limit, page=page)
records = self.sg.find(
entity_type,
filters,
fields=list(fields.keys()),
order=order,
filter_operator=filter_operator,
limit=limit,
page=page,
)

self.assertTrue(isinstance(records, list))

Expand Down Expand Up @@ -117,13 +130,12 @@ def test_schema(self):
human_field_name = "Monkey " + str(random.getrandbits(24))

properties = {"description": "How many monkeys were needed"}
new_field_name = self.sg.schema_field_create("Version", "number", human_field_name,
properties=properties)
new_field_name = self.sg.schema_field_create(
"Version", "number", human_field_name, properties=properties
)

properties = {"description": "How many monkeys turned up"}
ret_val = self.sg.schema_field_update("Version",
new_field_name,
properties)
ret_val = self.sg.schema_field_update("Version", new_field_name, properties)
self.assertTrue(ret_val)

ret_val = self.sg.schema_field_delete("Version", new_field_name)
Expand All @@ -132,42 +144,56 @@ def test_schema(self):
def test_schema_with_project(self):
"""Called schema functions with project"""

project_entity = {'type': 'Project', 'id': 0}
project_entity = {"type": "Project", "id": 0}

if not self.sg.server_caps.version or self.sg.server_caps.version < (5, 4, 4):

# server does not support this!
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_entity_read, project_entity)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_read, project_entity)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_field_read, 'Version', None, project_entity)
self.assertRaises(shotgun_api3.ShotgunError, self.sg.schema_field_read, 'Version', 'user', project_entity)
self.assertRaises(
shotgun_api3.ShotgunError, self.sg.schema_entity_read, project_entity
)
self.assertRaises(
shotgun_api3.ShotgunError, self.sg.schema_read, project_entity
)
self.assertRaises(
shotgun_api3.ShotgunError,
self.sg.schema_field_read,
"Version",
None,
project_entity,
)
self.assertRaises(
shotgun_api3.ShotgunError,
self.sg.schema_field_read,
"Version",
"user",
project_entity,
)

else:

schema = self.sg.schema_entity_read(project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('Project' in schema)
self.assertTrue('visible' in schema['Project'])
self.assertTrue("Project" in schema)
self.assertTrue("visible" in schema["Project"])

schema = self.sg.schema_read(project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('Version' in schema)
self.assertFalse('visible' in schema)
self.assertTrue("Version" in schema)
self.assertFalse("visible" in schema)

schema = self.sg.schema_field_read('Version', project_entity=project_entity)
schema = self.sg.schema_field_read("Version", project_entity=project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('user' in schema)
self.assertTrue('visible' in schema['user'])
self.assertTrue("user" in schema)
self.assertTrue("visible" in schema["user"])

schema = self.sg.schema_field_read('Version', 'user', project_entity)
schema = self.sg.schema_field_read("Version", "user", project_entity)
self.assertTrue(schema, dict)
self.assertTrue(len(schema) > 0)
self.assertTrue('user' in schema)
self.assertTrue('visible' in schema['user'])
self.assertTrue("user" in schema)
self.assertTrue("visible" in schema["user"])


if __name__ == '__main__':
if __name__ == "__main__":
base.unittest.main()

0 comments on commit abad460

Please sign in to comment.