Skip to content

Commit dbb23e9

Browse files
committed
For #28441: FIXED version checks, better API flag tests
1 parent d7bf23d commit dbb23e9

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

182186
def __str__(self):
@@ -666,19 +670,11 @@ def _construct_flag_parameters(self,
666670
include_archived_projects,
667671
include_template_projects):
668672

669-
if not include_archived_projects:
670-
# This defaults to True on the server (no argument is sent)
671-
# So we only need to check the server version if it's False
672-
self.server_caps.ensure_include_archived_projects()
673-
# Only pass it if it's False
674-
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
675675

676-
if include_template_projects:
677-
# This defaults to False on the server (no argument is sent)
678-
# So we only need to check the server version if it's True
679-
self.server_caps.ensure_include_template_projects()
680-
# Only pass it if it's True
681-
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
682678

683679
return params
684680

@@ -1645,6 +1641,7 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
16451641
16461642
"""
16471643

1644+
log_time = datetime.datetime.now()
16481645
LOG.debug("Starting rpc call to %s with params %s" % (
16491646
method, params))
16501647

@@ -1659,7 +1656,10 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
16591656
}
16601657
http_status, resp_headers, body = self._make_call("POST",
16611658
self.config.api_path, encoded_payload, req_headers)
1662-
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+
16631663
try:
16641664
self._parse_http_status(http_status)
16651665
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)