Skip to content

Commit 6a74c73

Browse files
committed
For #28441: FIXED version checks, better API flag tests
1 parent d5914e4 commit 6a74c73

File tree

3 files changed

+193
-64
lines changed

3 files changed

+193
-64
lines changed

shotgun_api3/shotgun.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,23 @@ def ensure_json_supported(self):
164164
'label': 'JSON API'
165165
})
166166

167-
def ensure_include_archived_projects(self):
167+
def ensure_include_archived_projects(self, value=True):
168168
"""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
169171
return self._ensure_support({
170172
'version': (5, 3, 14),
171173
'label': 'include_archived_projects parameter'
172-
})
174+
}, (value == False))
173175

174-
def ensure_include_template_projects(self):
176+
def ensure_include_template_projects(self, value=False):
175177
"""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
176180
return self._ensure_support({
177181
'version': (6, 0, 0),
178182
'label': 'include_template_projects parameter'
179-
})
183+
}, (value == True))
180184

181185
def ensure_per_project_customization(self):
182186
"""Wrapper for ensure_support"""
@@ -673,19 +677,11 @@ def _construct_flag_parameters(self,
673677
include_archived_projects,
674678
include_template_projects):
675679

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

683-
if include_template_projects:
684-
# This defaults to False on the server (no argument is sent)
685-
# So we only need to check the server version if it's True
686-
self.server_caps.ensure_include_template_projects()
687-
# Only pass it if it's True
688-
params["include_template_projects"] = True
683+
if self.server_caps.ensure_include_template_projects(include_template_projects):
684+
params["include_template_projects"] = include_template_projects
689685

690686
return params
691687

@@ -1659,6 +1655,7 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
16591655
16601656
"""
16611657

1658+
log_time = datetime.datetime.now()
16621659
LOG.debug("Starting rpc call to %s with params %s" % (
16631660
method, params))
16641661

@@ -1673,7 +1670,10 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
16731670
}
16741671
http_status, resp_headers, body = self._make_call("POST",
16751672
self.config.api_path, encoded_payload, req_headers)
1676-
LOG.debug("Completed rpc call to %s" % (method))
1673+
1674+
log_time = datetime.datetime.now() - log_time
1675+
LOG.debug("Completed rpc call to %s in %s" % (method, str(log_time)))
1676+
16771677
try:
16781678
self._parse_http_status(http_status)
16791679
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)