Skip to content

SG-35018 Condition auth for Jenkins environment #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ source=shotgun_api3
omit=
shotgun_api3/lib/httplib2/*
shotgun_api3/lib/six.py
shotgun_api3/lib/certify/*
shotgun_api3/lib/pyparsing.py
2 changes: 1 addition & 1 deletion azure-pipelines-templates/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
# for example 'Windows - 2.7'
- bash: |
cp ./tests/example_config ./tests/config
pytest -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)"
pytest --durations=0 -v --cov shotgun_api3 --cov-report xml --test-run-title="${{parameters.name}}-$(python.version)"
displayName: Running tests
env:
# Pass the values needed to authenticate with the Flow Production Tracking site and create some entities.
Expand Down
52 changes: 36 additions & 16 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import random
import re
import time
import unittest

from . import mock
Expand All @@ -26,6 +27,11 @@ def skip(f):
return lambda self: None


THUMBNAIL_MAX_ATTEMPTS = 30
THUMBNAIL_RETRY_INTERVAL = 10
TRANSIENT_IMAGE_PATH = "images/status/transient"


class TestBase(unittest.TestCase):
'''Base class for tests.

Expand Down Expand Up @@ -59,6 +65,14 @@ def setUpClass(cls):
cur_folder = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(cur_folder, "config")
cls.config.read_config(config_path)
if cls.config.jenkins:
cls.auth_args = dict(
login=cls.config.human_login, password=cls.config.human_password
)
else:
cls.auth_args = dict(
script_name=cls.config.script_name, api_key=cls.config.api_key
)

def setUp(self, auth_mode='ApiUser'):
# When running the tests from a pull request from a client, the Shotgun
Expand Down Expand Up @@ -90,9 +104,8 @@ def setUp(self, auth_mode='ApiUser'):
# first make an instance based on script key/name so
# we can generate a session token
sg = api.Shotgun(self.config.server_url,
self.config.script_name,
self.config.api_key,
http_proxy=self.config.http_proxy)
http_proxy=self.config.http_proxy,
**self.auth_args)
self.session_token = sg.get_session_token()
# now log in using session token
self.sg = api.Shotgun(self.config.server_url,
Expand Down Expand Up @@ -234,7 +247,9 @@ def _setup_mock_data(self):
class LiveTestBase(TestBase):
'''Test base for tests relying on connection to server.'''

def setUp(self, auth_mode='ApiUser'):
def setUp(self, auth_mode=None):
if not auth_mode:
auth_mode = 'HumanUser' if self.config.jenkins else 'ApiUser'
super(LiveTestBase, self).setUp(auth_mode)
if self.sg.server_caps.version and \
self.sg.server_caps.version >= (3, 3, 0) and \
Expand All @@ -260,18 +275,10 @@ def setUpClass(cls):
# When running the tests from a pull request from a client, the Shotgun
# site URL won't be set, so do not attempt to connect to Shotgun.
if cls.config.server_url:
if cls.config.jenkins:
sg = api.Shotgun(
cls.config.server_url,
login=cls.config.human_login,
password=cls.config.human_password
)
else:
sg = api.Shotgun(
cls.config.server_url,
cls.config.script_name,
cls.config.api_key
)
sg = api.Shotgun(
cls.config.server_url,
**cls.auth_args,
)
cls.sg_version = tuple(sg.info()['version'][:3])
cls._setup_db(cls.config, sg)

Expand Down Expand Up @@ -365,6 +372,19 @@ def gen_entity(self, entity_type, **kwargs):
rv = self.sg.delete(entity_type, entity["id"])
assert rv == True

def find_one_await_thumbnail(self, entity_type, filters, fields=["image"], thumbnail_field_name="image", **kwargs):
attempts = 0
while attempts < THUMBNAIL_MAX_ATTEMPTS:
result = self.sg.find_one(entity_type, filters, fields=fields, **kwargs)
if TRANSIENT_IMAGE_PATH in result.get(thumbnail_field_name, ""):
return result

time.sleep(THUMBNAIL_RETRY_INTERVAL)
attempts += 1
else:
if self.config.jenkins:
self.skipTest("Jenkins test timed out waiting for thumbnail")


class HumanUserAuthLiveTestBase(LiveTestBase):
'''
Expand Down
Loading
Loading