From cebfd79b1628d9eec2ea86b1a7cb53f029d0b364 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Fri, 14 Jun 2024 12:39:35 -0500 Subject: [PATCH 1/6] Remove Ticket entity related tests --- .gitignore | 1 + tests/base.py | 9 ------- tests/test_api.py | 66 +++++++++++++---------------------------------- 3 files changed, 19 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index f8adaad5..3e6ff329 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ tests/config .travis-solo htmlcov test-output.xml +coverage.xml # setup related build diff --git a/tests/base.py b/tests/base.py index 28547cbe..950c23d3 100644 --- a/tests/base.py +++ b/tests/base.py @@ -227,9 +227,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'} @@ -330,12 +327,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', diff --git a/tests/test_api.py b/tests/test_api.py index 62b91ad7..1c8dc0c2 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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, 'attachments', tag_list="monkeys, everywhere, send, help") # test download with attachment_id @@ -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']]], + version = self.sg.find_one('Version', [['id', 'is', self.version['id']]], ['attachments']) # 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 = [x for x in version["attachments"] if x["id"] == attach_id] self.assertEqual(len(attachment), 1) attachment = attachment[0] @@ -254,8 +254,8 @@ 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', tag_list="monkeys, everywhere, send, help" @@ -266,8 +266,8 @@ 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', tag_list="monkeys, everywhere, send, help" @@ -290,8 +290,8 @@ 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', tag_list="monkeys, everywhere, send, help" @@ -299,8 +299,8 @@ def test_upload_download(self): # 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', tag_list="monkeys, everywhere, send, help" @@ -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" @@ -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", @@ -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" @@ -1521,36 +1521,6 @@ def test_not_in_relation_float(self): result = self._id_in_result('Version', filters, self.version['id']) self.assertFalse(result) - 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'], - ['project', 'is', self.project]] - - result = self._id_in_result('Ticket', filters, self.ticket['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']], - ['project', 'is', self.project]] - - result = self._id_in_result('Ticket', filters, self.ticket['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']], - ['project', 'is', self.project]] - - result = self._id_in_result('Ticket', filters, self.ticket['id']) - self.assertFalse(result) - def test_in_relation_comma_multi_entity(self): """ Test that 'in' relation using commas (old format) works with multi_entity fields. From 2c9349aa5931e060db25dd087357eb85513c05cd Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Fri, 14 Jun 2024 12:41:16 -0500 Subject: [PATCH 2/6] Remove config --- tests/base.py | 2 +- tests/example_config | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/base.py b/tests/base.py index 950c23d3..2a6954fe 100644 --- a/tests/base.py +++ b/tests/base.py @@ -397,7 +397,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' ] def read_config(self, config_path): diff --git a/tests/example_config b/tests/example_config index 064eaba6..cb04aefa 100644 --- a/tests/example_config +++ b/tests/example_config @@ -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 From d6f1434eb41e57ff5d55b3b36ec3868796c482d4 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Fri, 14 Jun 2024 12:42:12 -0500 Subject: [PATCH 3/6] Clean-up --- azure-pipelines-templates/run-tests.yml | 1 - tests/base.py | 1 - 2 files changed, 2 deletions(-) diff --git a/azure-pipelines-templates/run-tests.yml b/azure-pipelines-templates/run-tests.yml index 34345a33..8fb33a6d 100644 --- a/azure-pipelines-templates/run-tests.yml +++ b/azure-pipelines-templates/run-tests.yml @@ -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. diff --git a/tests/base.py b/tests/base.py index 2a6954fe..a59510d5 100644 --- a/tests/base.py +++ b/tests/base.py @@ -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 From 22ad83d496e20a6a98535894f9d375cbf6170aaa Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Fri, 14 Jun 2024 13:45:34 -0500 Subject: [PATCH 4/6] Update tests to switch from attachment to sg_uploaded_movie --- tests/test_api.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 1c8dc0c2..592d64fc 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -172,7 +172,7 @@ def test_upload_download(self): size = os.stat(path).st_size attach_id = self.sg.upload("Version", - self.version['id'], path, 'attachments', + self.version['id'], path, 'sg_uploaded_movie', tag_list="monkeys, everywhere, send, help") # test download with attachment_id @@ -202,11 +202,11 @@ def test_upload_download(self): # test download with attachment hash version = self.sg.find_one('Version', [['id', 'is', self.version['id']]], - ['attachments']) + ['sg_uploaded_movie']) # Look for the attachment we just uploaded, the attachments are not returned from latest # to earliest. - attachment = [x for x in version["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] @@ -257,7 +257,7 @@ def test_upload_download(self): "Version", self.version['id'], u_path, - 'attachments', + 'sg_uploaded_movie', tag_list="monkeys, everywhere, send, help" ) @@ -269,7 +269,7 @@ def test_upload_download(self): "Version", self.version['id'], u_path.encode("utf-8"), - 'attachments', + 'sg_uploaded_movie', tag_list="monkeys, everywhere, send, help" ) if six.PY2: @@ -293,7 +293,7 @@ def test_upload_download(self): "Version", self.version['id'], file_path_u.encode("shift-jis"), - 'attachments', + 'sg_uploaded_movie', tag_list="monkeys, everywhere, send, help" ) @@ -302,7 +302,7 @@ def test_upload_download(self): "Version", self.version['id'], file_path_u, - 'attachments', + 'sg_uploaded_movie', tag_list="monkeys, everywhere, send, help" ) From 40c8da671a0af31fff7528f79b8847480f468281 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Wed, 19 Jun 2024 12:30:03 -0500 Subject: [PATCH 5/6] Revert removed tests --- tests/test_api.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_api.py b/tests/test_api.py index 592d64fc..9186d443 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1521,6 +1521,36 @@ def test_not_in_relation_float(self): result = self._id_in_result('Version', filters, self.version['id']) self.assertFalse(result) + def test_in_relation_comma_list(self): + """ + Test that 'in' relation using commas (old format) works with list fields. + """ + filters = [['frame_count', 'in', self.version['frame_count'], 33], + ['project', 'is', self.project]] + + 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 = [['frame_count', 'in', [self.version['frame_count'], 33]], + ['project', 'is', self.project]] + + 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 = [['frame_count', 'not_in', [self.version['frame_count'], 33]], + ['project', 'is', self.project]] + + result = self._id_in_result('Version', filters, self.version['id']) + self.assertFalse(result) + def test_in_relation_comma_multi_entity(self): """ Test that 'in' relation using commas (old format) works with multi_entity fields. From a2ca6e5f16f31b604a8c0db89342f9a5469431eb Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Wed, 19 Jun 2024 14:45:18 -0500 Subject: [PATCH 6/6] Add Jenkins setting --- tests/base.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/base.py b/tests/base.py index a59510d5..900b9599 100644 --- a/tests/base.py +++ b/tests/base.py @@ -260,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) @@ -396,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' + 'version_code', 'playlist_code', 'jenkins' ] def read_config(self, config_path):