Skip to content

Commit fc9eff1

Browse files
SG-35018 Remove Ticket entity reference and prepare this to run in CI (#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
1 parent 74c8047 commit fc9eff1

File tree

5 files changed

+43
-47
lines changed

5 files changed

+43
-47
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tests/config
2626
.travis-solo
2727
htmlcov
2828
test-output.xml
29+
coverage.xml
2930

3031
# setup related
3132
build

azure-pipelines-templates/run-tests.yml

-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ jobs:
129129
SG_VERSION_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
130130
SG_SHOT_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
131131
SG_TASK_CONTENT: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
132-
SG_TICKET_TILE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
133132
SG_PLAYLIST_CODE: CI-$(python_api_human_login)-${{parameters.name}}-$(python.version)
134133
135134
# Upload the code coverage result to codecov.io.

tests/base.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class TestBase(unittest.TestCase):
3939
note = None
4040
playlist = None
4141
task = None
42-
ticket = None
4342
human_password = None
4443
server_url = None
4544
server_address = None
@@ -227,9 +226,6 @@ def _setup_mock_data(self):
227226
self.version = {'id': 5,
228227
'code': self.config.version_code,
229228
'type': 'Version'}
230-
self.ticket = {'id': 6,
231-
'title': self.config.ticket_title,
232-
'type': 'Ticket'}
233229
self.playlist = {'id': 7,
234230
'code': self.config.playlist_code,
235231
'type': 'Playlist'}
@@ -264,11 +260,18 @@ def setUpClass(cls):
264260
# When running the tests from a pull request from a client, the Shotgun
265261
# site URL won't be set, so do not attempt to connect to Shotgun.
266262
if cls.config.server_url:
267-
sg = api.Shotgun(
268-
cls.config.server_url,
269-
cls.config.script_name,
270-
cls.config.api_key
271-
)
263+
if cls.config.jenkins:
264+
sg = api.Shotgun(
265+
cls.config.server_url,
266+
login=cls.config.human_login,
267+
password=cls.config.human_password
268+
)
269+
else:
270+
sg = api.Shotgun(
271+
cls.config.server_url,
272+
cls.config.script_name,
273+
cls.config.api_key
274+
)
272275
cls.sg_version = tuple(sg.info()['version'][:3])
273276
cls._setup_db(cls.config, sg)
274277

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

333-
data = {'project': cls.project,
334-
'title': cls.config.ticket_title,
335-
'sg_priority': '3'}
336-
keys = ['title', 'project', 'sg_priority']
337-
cls.ticket = _find_or_create_entity(sg, 'Ticket', data, keys)
338-
339336
keys = ['code']
340337
data = {'code': 'api wrapper test storage',
341338
'mac_path': 'nowhere',
@@ -406,7 +403,7 @@ def config_keys(self):
406403
'api_key', 'asset_code', 'http_proxy', 'human_login', 'human_name',
407404
'human_password', 'mock', 'project_name', 'script_name',
408405
'server_url', 'session_uuid', 'shot_code', 'task_content',
409-
'version_code', 'playlist_code', 'ticket_title'
406+
'version_code', 'playlist_code', 'jenkins'
410407
]
411408

412409
def read_config(self, config_path):

tests/example_config

-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ asset_code : Sg unittest asset
3434
version_code : Sg unittest version
3535
shot_code : Sg unittest shot
3636
task_content : Sg unittest task
37-
ticket_title : Sg unittest ticket
3837
playlist_code : Sg unittest playlist

tests/test_api.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def test_upload_download(self):
171171
os.path.join(this_dir, "sg_logo.jpg")))
172172
size = os.stat(path).st_size
173173

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

178178
# test download with attachment_id
@@ -201,12 +201,12 @@ def test_upload_download(self):
201201
self.assertEqual(orig_file, attach_file)
202202

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

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

212212
attachment = attachment[0]
@@ -254,10 +254,10 @@ def test_upload_download(self):
254254
# only checking that the non-ascii string encoding doesn't trip
255255
# us up the way it used to.
256256
self.sg.upload(
257-
"Ticket",
258-
self.ticket['id'],
257+
"Version",
258+
self.version['id'],
259259
u_path,
260-
'attachments',
260+
'sg_uploaded_movie',
261261
tag_list="monkeys, everywhere, send, help"
262262
)
263263

@@ -266,10 +266,10 @@ def test_upload_download(self):
266266
# primarily a concern on Windows, as it doesn't handle that
267267
# situation as well as OS X and Linux.
268268
self.sg.upload(
269-
"Ticket",
270-
self.ticket['id'],
269+
"Version",
270+
self.version['id'],
271271
u_path.encode("utf-8"),
272-
'attachments',
272+
'sg_uploaded_movie',
273273
tag_list="monkeys, everywhere, send, help"
274274
)
275275
if six.PY2:
@@ -290,19 +290,19 @@ def test_upload_download(self):
290290
self.assertRaises(
291291
shotgun_api3.ShotgunError,
292292
self.sg.upload,
293-
"Ticket",
294-
self.ticket['id'],
293+
"Version",
294+
self.version['id'],
295295
file_path_u.encode("shift-jis"),
296-
'attachments',
296+
'sg_uploaded_movie',
297297
tag_list="monkeys, everywhere, send, help"
298298
)
299299

300300
# But it should work in all cases if a unicode string is used.
301301
self.sg.upload(
302-
"Ticket",
303-
self.ticket['id'],
302+
"Version",
303+
self.version['id'],
304304
file_path_u,
305-
'attachments',
305+
'sg_uploaded_movie',
306306
tag_list="monkeys, everywhere, send, help"
307307
)
308308

@@ -330,8 +330,8 @@ def test_upload_to_sg(self, mock_send_form):
330330
)
331331
)
332332
upload_id = self.sg.upload(
333-
"Ticket",
334-
self.ticket['id'],
333+
"Version",
334+
self.version['id'],
335335
u_path,
336336
'attachments',
337337
tag_list="monkeys, everywhere, send, help"
@@ -345,8 +345,8 @@ def test_upload_to_sg(self, mock_send_form):
345345
)
346346

347347
upload_id = self.sg.upload(
348-
"Ticket",
349-
self.ticket['id'],
348+
"Version",
349+
self.version['id'],
350350
u_path,
351351
'filmstrip_image',
352352
tag_list="monkeys, everywhere, send, help",
@@ -365,8 +365,8 @@ def test_upload_to_sg(self, mock_send_form):
365365
self.assertRaises(
366366
shotgun_api3.ShotgunError,
367367
self.sg.upload,
368-
"Ticket",
369-
self.ticket['id'],
368+
"Version",
369+
self.version['id'],
370370
u_path,
371371
'attachments',
372372
tag_list="monkeys, everywhere, send, help"
@@ -1525,30 +1525,30 @@ def test_in_relation_comma_list(self):
15251525
"""
15261526
Test that 'in' relation using commas (old format) works with list fields.
15271527
"""
1528-
filters = [['sg_priority', 'in', self.ticket['sg_priority'], '1'],
1528+
filters = [['frame_count', 'in', self.version['frame_count'], 33],
15291529
['project', 'is', self.project]]
15301530

1531-
result = self._id_in_result('Ticket', filters, self.ticket['id'])
1531+
result = self._id_in_result('Version', filters, self.version['id'])
15321532
self.assertTrue(result)
15331533

15341534
def test_in_relation_list_list(self):
15351535
"""
15361536
Test that 'in' relation using list (new format) works with list fields.
15371537
"""
1538-
filters = [['sg_priority', 'in', [self.ticket['sg_priority'], '1']],
1538+
filters = [['frame_count', 'in', [self.version['frame_count'], 33]],
15391539
['project', 'is', self.project]]
15401540

1541-
result = self._id_in_result('Ticket', filters, self.ticket['id'])
1541+
result = self._id_in_result('Version', filters, self.version['id'])
15421542
self.assertTrue(result)
15431543

15441544
def test_not_in_relation_list(self):
15451545
"""
15461546
Test that 'not_in' relation using commas (old format) works with list fields.
15471547
"""
1548-
filters = [['sg_priority', 'not_in', [self.ticket['sg_priority'], '1']],
1548+
filters = [['frame_count', 'not_in', [self.version['frame_count'], 33]],
15491549
['project', 'is', self.project]]
15501550

1551-
result = self._id_in_result('Ticket', filters, self.ticket['id'])
1551+
result = self._id_in_result('Version', filters, self.version['id'])
15521552
self.assertFalse(result)
15531553

15541554
def test_in_relation_comma_multi_entity(self):

0 commit comments

Comments
 (0)