@@ -159,8 +159,8 @@ def test_get_session_token(self):
159159
160160 def test_upload_download (self ):
161161 """Upload and download an attachment """
162- #upload / download only works against a live server becuase it does
163- #not use the standard http interface
162+ # upload / download only works against a live server because it does
163+ # not use the standard http interface
164164 if 'localhost' in self .server_url :
165165 print "upload / down tests skipped for localhost"
166166 return
@@ -181,10 +181,10 @@ def test_upload_download(self):
181181 orig_file = open (path , "rb" ).read ()
182182 self .assertEqual (orig_file , attach_file )
183183
184- def test_create_upload (self ):
184+ def test_upload_thumbnail_in_create (self ):
185185 """Upload a thumbnail via the create method"""
186- #upload / download only works against a live server becuase it does
187- #not use the standard http interface
186+ # upload / download only works against a live server because it does
187+ # not use the standard http interface
188188 if 'localhost' in self .server_url :
189189 print "upload via create tests skipped for localhost"
190190 return
@@ -200,100 +200,105 @@ def test_create_upload(self):
200200 'project' : self .project }
201201 new_version = self .sg .create ("Version" , data , return_fields = ['image' ])
202202 self .assertTrue (new_version is not None )
203+ self .assertTrue (isinstance (new_version , dict ))
204+ self .assertTrue (isinstance (new_version .get ('id' ), int ))
205+ self .assertEqual (new_version .get ('type' ), 'Version' )
206+ self .assertEqual (new_version .get ('project' ), self .project )
207+ self .assertTrue (isinstance (new_version .get ('image_id' ), int ))
203208 self .assertTrue (new_version .get ('image' ) is not None )
204- self .assertTrue (new_version .get ('image_id' ) is not None )
205- attach_file = \
206- self .sg .download_attachment (new_version .get ('image_id' ))
207- self .assertTrue (attach_file is not None )
208- self .assertEqual (size , len (attach_file ))
209- orig_file = open (path , "rb" ).read ()
210- self .assertEqual (orig_file , attach_file )
209+ self .assertTrue ( re .match ("http:\/\/%s\/files\/0000\/0000\/\d{4}/232/sg_logo.jpg.jpg" % (self .server_address ), new_version .get ('image' )) )
211210
212211 # test filmstrip image upload
213212 data = {'filmstrip_image' : path , 'code' : 'Test Version' ,
214213 'project' : self .project }
215214 new_version = self .sg .create ("Version" , data , return_fields = ['filmstrip_image' ])
216215 self .assertTrue (new_version is not None )
216+ self .assertTrue (isinstance (new_version , dict ))
217+ self .assertTrue (isinstance (new_version .get ('id' ), int ))
218+ self .assertEqual (new_version .get ('type' ), 'Version' )
219+ self .assertEqual (new_version .get ('project' ), self .project )
220+ self .assertTrue (isinstance (new_version .get ('filmstrip_image_id' ), int ))
217221 self .assertTrue (new_version .get ('filmstrip_image' ) is not None )
218- self .assertTrue (new_version .get ('filmstrip_image_id' ) is not None )
219- attach_file = \
220- self .sg .download_attachment (new_version .get ('filmstrip_image_id' ))
221- self .assertTrue (attach_file is not None )
222- self .assertEqual (size , len (attach_file ))
223- orig_file = open (path , "rb" ).read ()
224- self .assertEqual (orig_file , attach_file )
225- # end test_create_upload
226-
227- def test_thumbnail_url (self ):
228- #upload / download only works against a live server becuase it does
229- #not use the standard http interface
222+ # http://trunk.shotgun.vm/files/0000/0000/0170/sg_logo.jpg
223+ self .assertTrue ( re .match ("http:\/\/%s\/files\/0000\/0000\/\d{4}/sg_logo.jpg" % (self .server_address ), new_version .get ('filmstrip_image' )) )
224+ # end test_upload_thumbnail_in_create
225+
226+ def test_upload_thumbnail (self ):
227+ # simple upload thumbnail test.
228+ # upload / download only works against a live server because it does
229+ # not use the standard http interface
230230 if 'localhost' in self .server_url :
231231 print "upload / down tests skipped for localhost"
232232 return
233233
234234 this_dir , _ = os .path .split (__file__ )
235235 path = os .path .abspath (os .path .expanduser (
236236 os .path .join (this_dir ,"sg_logo.jpg" )))
237+ size = os .stat (path ).st_size
237238
238- attach_id = self .sg .upload_thumbnail ("Version" ,
239+ # upload thumbnail
240+ thumb_id = self .sg .upload_thumbnail ("Version" ,
239241 self .version ['id' ], path )
242+ self .assertTrue (isinstance (thumb_id , int ))
240243
241- attach_id2 = self .sg .upload_thumbnail ("Project" ,
242- self .version ['project' ]['id' ], path )
243-
244- response = self .sg .find (
245- 'Version' ,
244+ # check result on version
245+ version_with_thumbnail = self .sg .find_one ('Version' ,
246246 [['id' , 'is' , self .version ['id' ]]],
247- fields = ['id' , 'code' , 'image' ]
248- )
247+ fields = ['image' ])
248+ expected_version_with_thumbnail = {
249+ 'image' : 'http://%s/files/0000/0000/%04d/232/sg_logo.jpg.jpg' % (self .server_address , thumb_id ),
250+ 'type' : 'Version' ,
251+ 'id' : self .version ['id' ]
252+ }
253+ self .assertEqual (expected_version_with_thumbnail , version_with_thumbnail )
249254
250- if self .sg .server_caps .version and \
251- self .sg .server_caps .version >= (3 , 3 , 0 ) and \
252- (self .sg .server_caps .host .startswith ('0.0.0.0' ) or \
253- self .sg .server_caps .host .startswith ('127.0.0.1' )):
254- server_address = re .sub ('^0.0.0.0|127.0.0.1' , 'localhost' , self .sg .server_caps .host )
255- else :
256- server_address = self .sg .server_caps .host
257-
258- expected = [
259- {
260- 'image' : 'http://%s/files/0000/0000/%04d/232/sg_logo.jpg.jpg' % (server_address , attach_id ),
261- 'code' : 'Sg unittest version' ,
262- 'type' : 'Version' ,
263- 'id' : self .version ['id' ]
264- }
265- ]
255+ # clear thumbnail
256+ response_clear_thumbnail = self .sg .update ("Version" ,
257+ self .version ['id' ], {'image' :None })
258+ expected_clear_thumbnail = {'id' : self .version ['id' ], 'image' : None , 'type' : 'Version' }
259+ self .assertEqual (expected_clear_thumbnail , response_clear_thumbnail )
266260
267- self .assertEqual (expected , response )
261+ def test_linked_thumbnail_url (self ):
262+ #upload / download only works against a live server because it does
263+ #not use the standard http interface
264+ if 'localhost' in self .server_url :
265+ print "upload / down tests skipped for localhost"
266+ return
267+
268+ this_dir , _ = os .path .split (__file__ )
269+ path = os .path .abspath (os .path .expanduser (
270+ os .path .join (this_dir ,"sg_logo.jpg" )))
271+
272+ thumb_id = self .sg .upload_thumbnail ("Project" ,
273+ self .version ['project' ]['id' ], path )
268274
269275 response_version_with_project = self .sg .find (
270276 'Version' ,
271277 [['id' , 'is' , self .version ['id' ]]],
272- fields = ['id' , 'code' , 'image' , ' project.Project.image' ]
278+ fields = ['id' , 'code' , 'project.Project.image' ]
273279 )
274280
275281 if self .sg .server_caps .version and self .sg .server_caps .version >= (3 , 3 , 0 ):
276282 expected_version_with_project = [
277283 {
278- 'image' : 'http://%s/files/0000/0000/%04d/232/sg_logo.jpg.jpg' % (server_address , attach_id ),
279284 'code' : 'Sg unittest version' ,
280285 'type' : 'Version' ,
281286 'id' : self .version ['id' ],
282- 'project.Project.image' : 'http://%s/files/0000/0000/%04d/232/sg_logo.jpg.jpg' % (server_address , attach_id2 )
287+ 'project.Project.image' : 'http://%s/files/0000/0000/%04d/232/sg_logo.jpg.jpg' % (self . server_address , thumb_id )
283288 }
284289 ]
285290 else :
286291 expected_version_with_project = [
287292 {
288- 'image' : 'http://%s/files/0000/0000/%04d/232/sg_logo.jpg.jpg' % (server_address , attach_id ),
289293 'code' : 'Sg unittest version' ,
290294 'type' : 'Version' ,
291295 'id' : self .version ['id' ],
292- 'project.Project.image' : attach_id2
296+ 'project.Project.image' : thumb_id
293297 }
294298 ]
295299 self .assertEqual (expected_version_with_project , response_version_with_project )
296300
301+
297302 def test_deprecated_functions (self ):
298303 """Deprecated functions raise errors"""
299304 self .assertRaises (shotgun_api3 .ShotgunError , self .sg .schema , "foo" )
0 commit comments