Skip to content

Commit bd5245d

Browse files
SG-35018 Condition auth for Jenkins environment (#350)
* Condition auth for Jenkins environment * Add prints * Add more debug logic * Use session token for Jenkins * Add debug info * More debug info * Revert f4e51cb * Remove redundant code * Revert * Unskip old tests. Skip datetime tests for Jenkins. * Condition test for SG_JENKINS * Improve test * Revert unskip * Add durations to pytest * Address feedback * Refactor find_one_await_thumbnail invocation * Remove duplicate line * Unskip test * Update .coveragerc * Addressing feedback
1 parent fc9eff1 commit bd5245d

File tree

5 files changed

+117
-95
lines changed

5 files changed

+117
-95
lines changed

.coveragerc

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ source=shotgun_api3
1717
omit=
1818
shotgun_api3/lib/httplib2/*
1919
shotgun_api3/lib/six.py
20+
shotgun_api3/lib/certify/*
21+
shotgun_api3/lib/pyparsing.py

azure-pipelines-templates/run-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
# for example 'Windows - 2.7'
9797
- bash: |
9898
cp ./tests/example_config ./tests/config
99-
pytest -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)"
99+
pytest --durations=0 -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)"
100100
displayName: Running tests
101101
env:
102102
# Pass the values needed to authenticate with the Flow Production Tracking site and create some entities.

tests/base.py

+36-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import random
55
import re
6+
import time
67
import unittest
78

89
from . 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+
2935
class 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):
234247
class 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

369389
class HumanUserAuthLiveTestBase(LiveTestBase):
370390
'''

0 commit comments

Comments
 (0)