Skip to content

Commit 4157455

Browse files
committed
For #28441: FIXED version checks, better API flag tests
1 parent 9acca61 commit 4157455

File tree

3 files changed

+199
-69
lines changed

3 files changed

+199
-69
lines changed

shotgun_api3/shotgun.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __init__(self, host, meta):
137137
self.ensure_json_supported()
138138

139139

140-
def _ensure_support(self, feature):
140+
def _ensure_support(self, feature, raise_hell=True):
141141
"""Checks the server version supports a given feature, raises an
142142
exception if it does not.
143143
@@ -147,10 +147,11 @@ def _ensure_support(self, feature):
147147
"""
148148

149149
if not self.version or self.version < feature['version']:
150-
raise ShotgunError(
151-
"%s requires server version %s or higher, "\
152-
"server is %s" % (feature['label'], _version_str(feature['version']), _version_str(self.version))
153-
)
150+
if raise_hell:
151+
raise ShotgunError(
152+
"%s requires server version %s or higher, "\
153+
"server is %s" % (feature['label'], _version_str(feature['version']), _version_str(self.version))
154+
)
154155
return False
155156
else:
156157
return True
@@ -163,19 +164,23 @@ def ensure_json_supported(self):
163164
'label': 'JSON API'
164165
})
165166

166-
def ensure_include_archived_projects(self):
167+
def ensure_include_archived_projects(self, value=True):
167168
"""Wrapper for ensure_support"""
169+
# This defaults to True on the server
170+
# So we only need to raise a version error if it's False
168171
return self._ensure_support({
169172
'version': (5, 3, 14),
170173
'label': 'include_archived_projects parameter'
171-
})
174+
}, (value == False))
172175

173-
def ensure_include_template_projects(self):
176+
def ensure_include_template_projects(self, value=False):
174177
"""Wrapper for ensure_support"""
178+
# This defaults to False on the server
179+
# So we only need to raise a version error if it's True
175180
return self._ensure_support({
176181
'version': (6, 0, 0),
177182
'label': 'include_template_projects parameter'
178-
})
183+
}, (value == True))
179184

180185

181186
def __str__(self):
@@ -665,19 +670,11 @@ def _construct_flag_parameters(self,
665670
include_archived_projects,
666671
include_template_projects):
667672

668-
if not include_archived_projects:
669-
# This defaults to True on the server (no argument is sent)
670-
# So we only need to check the server version if it's False
671-
self.server_caps.ensure_include_archived_projects()
672-
# Only pass it if it's False
673-
params["include_archived_projects"] = False
673+
if self.server_caps.ensure_include_archived_projects(include_archived_projects):
674+
params["include_archived_projects"] = include_archived_projects
674675

675-
if include_template_projects:
676-
# This defaults to False on the server (no argument is sent)
677-
# So we only need to check the server version if it's True
678-
self.server_caps.ensure_include_template_projects()
679-
# Only pass it if it's True
680-
params["include_template_projects"] = True
676+
if self.server_caps.ensure_include_template_projects(include_template_projects):
677+
params["include_template_projects"] = include_template_projects
681678

682679
return params
683680

@@ -1644,6 +1641,7 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
16441641
16451642
"""
16461643

1644+
log_time = datetime.datetime.now()
16471645
LOG.debug("Starting rpc call to %s with params %s" % (
16481646
method, params))
16491647

@@ -1658,7 +1656,10 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
16581656
}
16591657
http_status, resp_headers, body = self._make_call("POST",
16601658
self.config.api_path, encoded_payload, req_headers)
1661-
LOG.debug("Completed rpc call to %s" % (method))
1659+
1660+
log_time = datetime.datetime.now() - log_time
1661+
LOG.debug("Completed rpc call to %s in %s" % (method, str(log_time)))
1662+
16621663
try:
16631664
self._parse_http_status(http_status)
16641665
except ProtocolError, e:

tests/base.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import unittest
44
from ConfigParser import ConfigParser
55

6-
76
import mock
87

98
import shotgun_api3 as api
109
from shotgun_api3.shotgun import json
1110
from shotgun_api3.shotgun import ServerCapabilities
1211

12+
import logging
13+
1314
CONFIG_PATH = 'tests/config'
1415

1516
class TestBase(unittest.TestCase):
@@ -35,6 +36,10 @@ def __init__(self, *args, **kws):
3536

3637

3738
def setUp(self, auth_mode='ApiUser'):
39+
40+
self.LOG = logging.getLogger("shotgun_api3")
41+
self.LOG.setLevel(logging.WARN)
42+
3843
self.config = SgTestConfig()
3944
self.config.read_config(CONFIG_PATH)
4045
self.human_login = self.config.human_login
@@ -185,10 +190,14 @@ def _setup_mock_data(self):
185190

186191
class LiveTestBase(TestBase):
187192
'''Test base for tests relying on connection to server.'''
193+
188194
def setUp(self, auth_mode='ApiUser'):
189195
super(LiveTestBase, self).setUp(auth_mode)
196+
190197
self.sg_version = self.sg.info()['version'][:3]
198+
191199
self._setup_db(self.config)
200+
192201
if self.sg.server_caps.version and \
193202
self.sg.server_caps.version >= (3, 3, 0) and \
194203
(self.sg.server_caps.host.startswith('0.0.0.0') or \
@@ -197,17 +206,22 @@ def setUp(self, auth_mode='ApiUser'):
197206
else:
198207
self.server_address = self.sg.server_caps.host
199208

209+
200210
def _setup_db(self, config):
201211
data = {'name':self.config.project_name}
202212
self.project = _find_or_create_entity(self.sg, 'Project', data)
203213

214+
self.template_project = _find_or_create_entity(self.sg, 'Project', {
215+
'name': 'Template Project',
216+
'is_template': True
217+
})
218+
204219
data = {'name':self.config.human_name,
205220
'login':self.config.human_login,
206221
'password_proxy':self.config.human_password}
207222
if self.sg_version >= (3, 0, 0):
208223
data['locked_until'] = None
209224

210-
211225
self.human_user = _find_or_create_entity(self.sg, 'HumanUser', data)
212226

213227
data = {'code':self.config.asset_code,
@@ -256,6 +270,12 @@ def _setup_db(self, config):
256270
keys = ['title','project', 'sg_priority']
257271
self.ticket = _find_or_create_entity(self.sg, 'Ticket', data, keys)
258272

273+
data = {'project': self.template_project,
274+
'title': self.config.ticket_title,
275+
'sg_priority': '1'}
276+
keys = ['title', 'project', 'sg_priority']
277+
self.template_ticket = _find_or_create_entity(self.sg, 'Ticket', data, keys)
278+
259279
keys = ['code']
260280
data = {'code':'api wrapper test storage',
261281
'mac_path':'nowhere',

0 commit comments

Comments
 (0)