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/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 28547cbe..900b9599 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 @@ -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'} @@ -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) @@ -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', @@ -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): 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 diff --git a/tests/test_api.py b/tests/test_api.py index 62b91ad7..9186d443 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, 'sg_uploaded_movie', 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']]], - ['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] @@ -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" ) @@ -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: @@ -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" ) @@ -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" @@ -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):