3
3
import os
4
4
import random
5
5
import re
6
+ import time
6
7
import unittest
7
8
8
9
from . import mock
@@ -26,6 +27,11 @@ def skip(f):
26
27
return lambda self : None
27
28
28
29
30
+ THUMBNAIL_MAX_ATTEMPTS = 30
31
+ THUMBNAIL_RETRY_INTERVAL = 10
32
+ TRANSIENT_IMAGE_PATH = "images/status/transient"
33
+
34
+
29
35
class TestBase (unittest .TestCase ):
30
36
'''Base class for tests.
31
37
@@ -59,6 +65,14 @@ def setUpClass(cls):
59
65
cur_folder = os .path .dirname (os .path .abspath (__file__ ))
60
66
config_path = os .path .join (cur_folder , "config" )
61
67
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
+ )
62
76
63
77
def setUp (self , auth_mode = 'ApiUser' ):
64
78
# When running the tests from a pull request from a client, the Shotgun
@@ -90,9 +104,8 @@ def setUp(self, auth_mode='ApiUser'):
90
104
# first make an instance based on script key/name so
91
105
# we can generate a session token
92
106
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 )
96
109
self .session_token = sg .get_session_token ()
97
110
# now log in using session token
98
111
self .sg = api .Shotgun (self .config .server_url ,
@@ -234,7 +247,9 @@ def _setup_mock_data(self):
234
247
class LiveTestBase (TestBase ):
235
248
'''Test base for tests relying on connection to server.'''
236
249
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'
238
253
super (LiveTestBase , self ).setUp (auth_mode )
239
254
if self .sg .server_caps .version and \
240
255
self .sg .server_caps .version >= (3 , 3 , 0 ) and \
@@ -260,18 +275,10 @@ def setUpClass(cls):
260
275
# When running the tests from a pull request from a client, the Shotgun
261
276
# site URL won't be set, so do not attempt to connect to Shotgun.
262
277
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
+ )
275
282
cls .sg_version = tuple (sg .info ()['version' ][:3 ])
276
283
cls ._setup_db (cls .config , sg )
277
284
@@ -365,6 +372,19 @@ def gen_entity(self, entity_type, **kwargs):
365
372
rv = self .sg .delete (entity_type , entity ["id" ])
366
373
assert rv == True
367
374
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
+
368
388
369
389
class HumanUserAuthLiveTestBase (LiveTestBase ):
370
390
'''
0 commit comments