Skip to content

Commit

Permalink
SG-35018 Remove Ticket entity reference and prepare this to run in CI (
Browse files Browse the repository at this point in the history
…#349)

* Remove Ticket entity related tests

* Remove config

* Clean-up

* Update tests to switch from attachment to sg_uploaded_movie

* Revert removed tests

* Add Jenkins setting
  • Loading branch information
carlos-villavicencio-adsk authored Jun 19, 2024
1 parent 74c8047 commit fc9eff1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tests/config
.travis-solo
htmlcov
test-output.xml
coverage.xml

# setup related
build
Expand Down
1 change: 0 additions & 1 deletion azure-pipelines-templates/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ jobs:
SG_VERSION_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_SHOT_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_TICKET_TILE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
# Upload the code coverage result to codecov.io.
Expand Down
29 changes: 13 additions & 16 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class TestBase(unittest.TestCase):
note = None
playlist = None
task = None
ticket = None
human_password = None
server_url = None
server_address = None
Expand Down Expand Up @@ -227,9 +226,6 @@ def _setup_mock_data(self):
self.version = {'id': 5,
'code': self.config.version_code,
'type': 'Version'}
self.ticket = {'id': 6,
'title': self.config.ticket_title,
'type': 'Ticket'}
self.playlist = {'id': 7,
'code': self.config.playlist_code,
'type': 'Playlist'}
Expand Down Expand Up @@ -264,11 +260,18 @@ def setUpClass(cls):
# When running the tests from a pull request from a client, the Shotgun
# site URL won't be set, so do not attempt to connect to Shotgun.
if cls.config.server_url:
sg = api.Shotgun(
cls.config.server_url,
cls.config.script_name,
cls.config.api_key
)
if cls.config.jenkins:
sg = api.Shotgun(
cls.config.server_url,
login=cls.config.human_login,
password=cls.config.human_password
)
else:
sg = api.Shotgun(
cls.config.server_url,
cls.config.script_name,
cls.config.api_key
)
cls.sg_version = tuple(sg.info()['version'][:3])
cls._setup_db(cls.config, sg)

Expand Down Expand Up @@ -330,12 +333,6 @@ def _setup_db(cls, config, sg):
'sg_status_list': 'ip'}
cls.task = _find_or_create_entity(sg, 'Task', data, keys)

data = {'project': cls.project,
'title': cls.config.ticket_title,
'sg_priority': '3'}
keys = ['title', 'project', 'sg_priority']
cls.ticket = _find_or_create_entity(sg, 'Ticket', data, keys)

keys = ['code']
data = {'code': 'api wrapper test storage',
'mac_path': 'nowhere',
Expand Down Expand Up @@ -406,7 +403,7 @@ def config_keys(self):
'api_key', 'asset_code', 'http_proxy', 'human_login', 'human_name',
'human_password', 'mock', 'project_name', 'script_name',
'server_url', 'session_uuid', 'shot_code', 'task_content',
'version_code', 'playlist_code', 'ticket_title'
'version_code', 'playlist_code', 'jenkins'
]

def read_config(self, config_path):
Expand Down
1 change: 0 additions & 1 deletion tests/example_config
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ asset_code : Sg unittest asset
version_code : Sg unittest version
shot_code : Sg unittest shot
task_content : Sg unittest task
ticket_title : Sg unittest ticket
playlist_code : Sg unittest playlist
58 changes: 29 additions & 29 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def test_upload_download(self):
os.path.join(this_dir, "sg_logo.jpg")))
size = os.stat(path).st_size

attach_id = self.sg.upload("Ticket",
self.ticket['id'], path, 'attachments',
attach_id = self.sg.upload("Version",
self.version['id'], path, 'sg_uploaded_movie',
tag_list="monkeys, everywhere, send, help")

# test download with attachment_id
Expand Down Expand Up @@ -201,12 +201,12 @@ def test_upload_download(self):
self.assertEqual(orig_file, attach_file)

# test download with attachment hash
ticket = self.sg.find_one('Ticket', [['id', 'is', self.ticket['id']]],
['attachments'])
version = self.sg.find_one('Version', [['id', 'is', self.version['id']]],
['sg_uploaded_movie'])

# Look for the attachment we just uploaded, the attachments are not returned from latest
# to earliest.
attachment = [x for x in ticket["attachments"] if x["id"] == attach_id]
attachment = [v for k, v in version["sg_uploaded_movie"].items() if (k, v) == ("id", attach_id)]
self.assertEqual(len(attachment), 1)

attachment = attachment[0]
Expand Down Expand Up @@ -254,10 +254,10 @@ def test_upload_download(self):
# only checking that the non-ascii string encoding doesn't trip
# us up the way it used to.
self.sg.upload(
"Ticket",
self.ticket['id'],
"Version",
self.version['id'],
u_path,
'attachments',
'sg_uploaded_movie',
tag_list="monkeys, everywhere, send, help"
)

Expand All @@ -266,10 +266,10 @@ def test_upload_download(self):
# primarily a concern on Windows, as it doesn't handle that
# situation as well as OS X and Linux.
self.sg.upload(
"Ticket",
self.ticket['id'],
"Version",
self.version['id'],
u_path.encode("utf-8"),
'attachments',
'sg_uploaded_movie',
tag_list="monkeys, everywhere, send, help"
)
if six.PY2:
Expand All @@ -290,19 +290,19 @@ def test_upload_download(self):
self.assertRaises(
shotgun_api3.ShotgunError,
self.sg.upload,
"Ticket",
self.ticket['id'],
"Version",
self.version['id'],
file_path_u.encode("shift-jis"),
'attachments',
'sg_uploaded_movie',
tag_list="monkeys, everywhere, send, help"
)

# But it should work in all cases if a unicode string is used.
self.sg.upload(
"Ticket",
self.ticket['id'],
"Version",
self.version['id'],
file_path_u,
'attachments',
'sg_uploaded_movie',
tag_list="monkeys, everywhere, send, help"
)

Expand Down Expand Up @@ -330,8 +330,8 @@ def test_upload_to_sg(self, mock_send_form):
)
)
upload_id = self.sg.upload(
"Ticket",
self.ticket['id'],
"Version",
self.version['id'],
u_path,
'attachments',
tag_list="monkeys, everywhere, send, help"
Expand All @@ -345,8 +345,8 @@ def test_upload_to_sg(self, mock_send_form):
)

upload_id = self.sg.upload(
"Ticket",
self.ticket['id'],
"Version",
self.version['id'],
u_path,
'filmstrip_image',
tag_list="monkeys, everywhere, send, help",
Expand All @@ -365,8 +365,8 @@ def test_upload_to_sg(self, mock_send_form):
self.assertRaises(
shotgun_api3.ShotgunError,
self.sg.upload,
"Ticket",
self.ticket['id'],
"Version",
self.version['id'],
u_path,
'attachments',
tag_list="monkeys, everywhere, send, help"
Expand Down Expand Up @@ -1525,30 +1525,30 @@ def test_in_relation_comma_list(self):
"""
Test that 'in' relation using commas (old format) works with list fields.
"""
filters = [['sg_priority', 'in', self.ticket['sg_priority'], '1'],
filters = [['frame_count', 'in', self.version['frame_count'], 33],
['project', 'is', self.project]]

result = self._id_in_result('Ticket', filters, self.ticket['id'])
result = self._id_in_result('Version', filters, self.version['id'])
self.assertTrue(result)

def test_in_relation_list_list(self):
"""
Test that 'in' relation using list (new format) works with list fields.
"""
filters = [['sg_priority', 'in', [self.ticket['sg_priority'], '1']],
filters = [['frame_count', 'in', [self.version['frame_count'], 33]],
['project', 'is', self.project]]

result = self._id_in_result('Ticket', filters, self.ticket['id'])
result = self._id_in_result('Version', filters, self.version['id'])
self.assertTrue(result)

def test_not_in_relation_list(self):
"""
Test that 'not_in' relation using commas (old format) works with list fields.
"""
filters = [['sg_priority', 'not_in', [self.ticket['sg_priority'], '1']],
filters = [['frame_count', 'not_in', [self.version['frame_count'], 33]],
['project', 'is', self.project]]

result = self._id_in_result('Ticket', filters, self.ticket['id'])
result = self._id_in_result('Version', filters, self.version['id'])
self.assertFalse(result)

def test_in_relation_comma_multi_entity(self):
Expand Down

0 comments on commit fc9eff1

Please sign in to comment.