Skip to content

Commit bc7d40b

Browse files
author
Mandy Hampton
committed
unit tests for new code related to thumbnail uploading on create/update passing
1 parent 075a85e commit bc7d40b

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

shotgun_api3/shotgun.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,19 @@ def create(self, entity_type, data, return_fields=None):
557557
upload_filmstrip_image = data.pop('filmstrip_image')
558558
# end if
559559

560+
temp_return_fields = [item for item in return_fields]
561+
if upload_image and "image" in temp_return_fields:
562+
temp_return_fields.remove("image")
563+
# end if
564+
565+
if upload_filmstrip_image and "filmstrip_image" in temp_return_fields:
566+
temp_return_fields.remove("filmstrip_image")
567+
# end if
568+
560569
params = {
561570
"type" : entity_type,
562571
"fields" : self._dict_to_list(data),
563-
"return_fields" : return_fields or ["id"]
572+
"return_fields" : temp_return_fields or ["id"]
564573
}
565574

566575
record = self._call_rpc("create", params, first=True)
@@ -570,6 +579,9 @@ def create(self, entity_type, data, return_fields=None):
570579
image_id = self.upload_thumbnail(entity_type, result['id'],
571580
upload_image)
572581
result['image_id'] = image_id
582+
# end if
583+
584+
if "image" in return_fields:
573585
image = self.find_one(entity_type, [['id', 'is', result.get('id')]],
574586
fields=['image'])
575587
result['image'] = image.get('image')
@@ -578,6 +590,9 @@ def create(self, entity_type, data, return_fields=None):
578590
if upload_filmstrip_image:
579591
filmstrip_id = self.upload_filmstrip_thumbnail(entity_type, result['id'], upload_filmstrip_image)
580592
result['filmstrip_image_id'] = filmstrip_id
593+
# end if
594+
595+
if "filmstrip_image" in return_fields:
581596
filmstrip = self.find_one(entity_type,
582597
[['id', 'is', result.get('id')]],
583598
fields=['filmstrip_image'])
@@ -1060,7 +1075,7 @@ def download_attachment(self, attachment_id):
10601075
urllib2.install_opener(opener)
10611076

10621077
url = urlparse.urlunparse((self.config.scheme, self.config.server,
1063-
"/file_serve/attachment/%s" % urllib.quote(str(attachment_id)),
1078+
"/file_serve/%s" % urllib.quote(str(attachment_id)),
10641079
None, None, None))
10651080

10661081
try:

tests/test_api.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ def test_create_upload(self):
174174
size = os.stat(path).st_size
175175

176176
# test thumbnail upload
177-
data = {'image': path, 'name': 'Test Version'}
177+
data = {'image': path, 'code': 'Test Version',
178+
'project': self.project}
178179
new_version = self.sg.create("Version", data, return_fields=['image'])
179180
self.assertTrue(new_version is not None)
180181
self.assertTrue(new_version.get('image') is not None)
@@ -183,26 +184,20 @@ def test_create_upload(self):
183184
self.sg.download_attachment(new_version.get('image_id'))
184185
self.assertTrue(attach_file is not None)
185186
self.assertEqual(size, len(attach_file))
186-
orig_file.open(path, "rb").read()
187+
orig_file = open(path, "rb").read()
187188
self.assertEqual(orig_file, attach_file)
188189

189190
# test filmstrip image upload
190-
data = {'filmstrip_image': path, 'name': 'Test Version'}
191-
new_version = self.sg.create("Version", data, return_fields=['image'])
191+
data = {'filmstrip_image': path, 'code': 'Test Version',
192+
'project': self.project}
193+
new_version = self.sg.create("Version", data, return_fields=['filmstrip_image'])
192194
self.assertTrue(new_version is not None)
193195
self.assertTrue(new_version.get('filmstrip_image') is not None)
194196
self.assertTrue(new_version.get('filmstrip_image_id') is not None)
195197
attach_file =\
196198
self.sg.download_attachment(new_version.get('filmstrip_image_id'))
197199
self.assertTrue(attach_file is not None)
198200
self.assertEqual(size, len(attach_file))
199-
orig_file.open(path, "rb").read()
200-
self.assertEqual(orig_file, attach_file)
201-
202-
attach_file = self.sg.download_attachment(attach_id)
203-
self.assertTrue(attach_file is not None)
204-
self.assertEqual(size, len(attach_file))
205-
206201
orig_file = open(path, "rb").read()
207202
self.assertEqual(orig_file, attach_file)
208203
# end test_create_upload
@@ -248,7 +243,6 @@ def test_thumbnail_url(self):
248243
}
249244
]
250245

251-
print expected, response
252246
self.assertEqual(expected, response)
253247

254248
response_version_with_project = self.sg.find(
@@ -320,7 +314,6 @@ def test_ensure_unicode(self):
320314
self.config.api_key,
321315
ensure_ascii=False)
322316
result = sg_unicode.find_one('Note', [['id','is',self.note['id']]], fields=['content'])
323-
print result
324317
self.assertTrue(_has_unicode(result))
325318

326319
def test_work_schedule(self):

tests/test_api_long.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def test_automated_find(self):
1515
limit = 1
1616
page = 1
1717
for entity_type in all_entities:
18-
if entity_type in ("Asset", "Task", "Shot", "Attachment"):
18+
if entity_type in ("Asset", "Task", "Shot", "Attachment",
19+
"Candidate"):
1920
continue
2021
print "Finding entity type", entity_type
2122

0 commit comments

Comments
 (0)