@@ -243,7 +243,7 @@ def test_upload_download(self):
243243 # test upload of non-ascii, unicode path
244244 u_path = os .path .abspath (
245245 os .path .expanduser (
246- glob .glob (os .path .join (six .text_type (this_dir ), u'No*l .jpg' ))[0 ]
246+ glob .glob (os .path .join (six .text_type (this_dir ), "Noëlご .jpg" ))[0 ]
247247 )
248248 )
249249
@@ -310,6 +310,67 @@ def test_upload_download(self):
310310 # cleanup
311311 os .remove (file_path )
312312
313+ @patch ('shotgun_api3.Shotgun._send_form' )
314+ def test_upload_to_sg (self , mock_send_form ):
315+ """
316+ Upload an attachment tests for _upload_to_sg()
317+ """
318+ if "localhost" in self .server_url :
319+ self .skipTest ("upload / down tests skipped for localhost" )
320+
321+ self .sg .server_info ["s3_direct_uploads_enabled" ] = False
322+ mock_send_form .method .assert_called_once ()
323+ mock_send_form .return_value = "1\n :123\n asd"
324+ this_dir , _ = os .path .split (__file__ )
325+ u_path = os .path .abspath (
326+ os .path .expanduser (
327+ glob .glob (os .path .join (six .text_type (this_dir ), "Noëlご.jpg" ))[0 ]
328+ )
329+ )
330+ upload_id = self .sg .upload (
331+ "Ticket" ,
332+ self .ticket ['id' ],
333+ u_path ,
334+ 'attachments' ,
335+ tag_list = "monkeys, everywhere, send, help"
336+ )
337+ mock_send_form_args , _ = mock_send_form .call_args
338+ display_name_to_send = mock_send_form_args [1 ].get ("display_name" , "" )
339+ self .assertTrue (isinstance (upload_id , int ))
340+ self .assertFalse (
341+ display_name_to_send .startswith ("b'" ) and
342+ display_name_to_send .endswith ("'" )
343+ )
344+
345+ upload_id = self .sg .upload (
346+ "Ticket" ,
347+ self .ticket ['id' ],
348+ u_path ,
349+ 'filmstrip_image' ,
350+ tag_list = "monkeys, everywhere, send, help" ,
351+ )
352+ self .assertTrue (isinstance (upload_id , int ))
353+ mock_send_form_args , _ = mock_send_form .call_args
354+ display_name_to_send = mock_send_form_args [1 ].get ("display_name" , "" )
355+ self .assertTrue (isinstance (upload_id , int ))
356+ self .assertFalse (
357+ display_name_to_send .startswith ("b'" ) and
358+ display_name_to_send .endswith ("'" )
359+ )
360+
361+ mock_send_form .method .assert_called_once ()
362+ mock_send_form .return_value = "2\n It can't be upload"
363+ self .assertRaises (
364+ shotgun_api3 .ShotgunError ,
365+ self .sg .upload ,
366+ "Ticket" ,
367+ self .ticket ['id' ],
368+ u_path ,
369+ 'attachments' ,
370+ tag_list = "monkeys, everywhere, send, help"
371+ )
372+ self .sg .server_info ["s3_direct_uploads_enabled" ] = True
373+
313374 def test_upload_thumbnail_in_create (self ):
314375 """Upload a thumbnail via the create method"""
315376 this_dir , _ = os .path .split (__file__ )
0 commit comments