33import os
44import random
55import re
6+ import time
67import unittest
78
89from . import mock
@@ -26,6 +27,11 @@ def skip(f):
2627 return lambda self : None
2728
2829
30+ THUMBNAIL_MAX_ATTEMPTS = 30
31+ THUMBNAIL_RETRY_INTERVAL = 10
32+ TRANSIENT_IMAGE_PATH = "images/status/transient"
33+
34+
2935class TestBase (unittest .TestCase ):
3036 '''Base class for tests.
3137
@@ -59,6 +65,14 @@ def setUpClass(cls):
5965 cur_folder = os .path .dirname (os .path .abspath (__file__ ))
6066 config_path = os .path .join (cur_folder , "config" )
6167 cls .config .read_config (config_path )
68+ if cls .config .jenkins :
69+ cls .auth_args = dict (
70+ login = cls .config .human_login , password = cls .config .human_password
71+ )
72+ else :
73+ cls .auth_args = dict (
74+ script_name = cls .config .script_name , api_key = cls .config .api_key
75+ )
6276
6377 def setUp (self , auth_mode = 'ApiUser' ):
6478 # When running the tests from a pull request from a client, the Shotgun
@@ -90,9 +104,8 @@ def setUp(self, auth_mode='ApiUser'):
90104 # first make an instance based on script key/name so
91105 # we can generate a session token
92106 sg = api .Shotgun (self .config .server_url ,
93- self .config .script_name ,
94- self .config .api_key ,
95- http_proxy = self .config .http_proxy )
107+ http_proxy = self .config .http_proxy ,
108+ ** self .auth_args )
96109 self .session_token = sg .get_session_token ()
97110 # now log in using session token
98111 self .sg = api .Shotgun (self .config .server_url ,
@@ -234,7 +247,9 @@ def _setup_mock_data(self):
234247class LiveTestBase (TestBase ):
235248 '''Test base for tests relying on connection to server.'''
236249
237- def setUp (self , auth_mode = 'ApiUser' ):
250+ def setUp (self , auth_mode = None ):
251+ if not auth_mode :
252+ auth_mode = 'HumanUser' if self .config .jenkins else 'ApiUser'
238253 super (LiveTestBase , self ).setUp (auth_mode )
239254 if self .sg .server_caps .version and \
240255 self .sg .server_caps .version >= (3 , 3 , 0 ) and \
@@ -260,18 +275,10 @@ def setUpClass(cls):
260275 # When running the tests from a pull request from a client, the Shotgun
261276 # site URL won't be set, so do not attempt to connect to Shotgun.
262277 if cls .config .server_url :
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- )
278+ sg = api .Shotgun (
279+ cls .config .server_url ,
280+ ** cls .auth_args ,
281+ )
275282 cls .sg_version = tuple (sg .info ()['version' ][:3 ])
276283 cls ._setup_db (cls .config , sg )
277284
@@ -365,6 +372,19 @@ def gen_entity(self, entity_type, **kwargs):
365372 rv = self .sg .delete (entity_type , entity ["id" ])
366373 assert rv == True
367374
375+ def find_one_await_thumbnail (self , entity_type , filters , fields = ["image" ], thumbnail_field_name = "image" , ** kwargs ):
376+ attempts = 0
377+ while attempts < THUMBNAIL_MAX_ATTEMPTS :
378+ result = self .sg .find_one (entity_type , filters , fields = fields , ** kwargs )
379+ if TRANSIENT_IMAGE_PATH in result .get (thumbnail_field_name , "" ):
380+ return result
381+
382+ time .sleep (THUMBNAIL_RETRY_INTERVAL )
383+ attempts += 1
384+ else :
385+ if self .config .jenkins :
386+ self .skipTest ("Jenkins test timed out waiting for thumbnail" )
387+
368388
369389class HumanUserAuthLiveTestBase (LiveTestBase ):
370390 '''
0 commit comments