Skip to content

Commit

Permalink
For #28441: FIXED version checks, better API flag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nemoDreamer committed Apr 3, 2015
1 parent d5914e4 commit 6a74c73
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 64 deletions.
34 changes: 17 additions & 17 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,23 @@ def ensure_json_supported(self):
'label': 'JSON API'
})

def ensure_include_archived_projects(self):
def ensure_include_archived_projects(self, value=True):
"""Wrapper for ensure_support"""
# This defaults to True on the server
# So we only need to raise a version error if it's False
return self._ensure_support({
'version': (5, 3, 14),
'label': 'include_archived_projects parameter'
})
}, (value == False))

def ensure_include_template_projects(self):
def ensure_include_template_projects(self, value=False):
"""Wrapper for ensure_support"""
# This defaults to False on the server
# So we only need to raise a version error if it's True
return self._ensure_support({
'version': (6, 0, 0),
'label': 'include_template_projects parameter'
})
}, (value == True))

def ensure_per_project_customization(self):
"""Wrapper for ensure_support"""
Expand Down Expand Up @@ -673,19 +677,11 @@ def _construct_flag_parameters(self,
include_archived_projects,
include_template_projects):

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

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

return params

Expand Down Expand Up @@ -1659,6 +1655,7 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
"""

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

Expand All @@ -1673,7 +1670,10 @@ def _call_rpc(self, method, params, include_auth_params=True, first=False):
}
http_status, resp_headers, body = self._make_call("POST",
self.config.api_path, encoded_payload, req_headers)
LOG.debug("Completed rpc call to %s" % (method))

log_time = datetime.datetime.now() - log_time
LOG.debug("Completed rpc call to %s in %s" % (method, str(log_time)))

try:
self._parse_http_status(http_status)
except ProtocolError, e:
Expand Down
24 changes: 22 additions & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import unittest
from ConfigParser import ConfigParser


import mock

import shotgun_api3 as api
from shotgun_api3.shotgun import json
from shotgun_api3.shotgun import ServerCapabilities

import logging

CONFIG_PATH = 'tests/config'

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


def setUp(self, auth_mode='ApiUser'):

self.LOG = logging.getLogger("shotgun_api3")
self.LOG.setLevel(logging.WARN)

self.config = SgTestConfig()
self.config.read_config(CONFIG_PATH)
self.human_login = self.config.human_login
Expand Down Expand Up @@ -185,10 +190,14 @@ def _setup_mock_data(self):

class LiveTestBase(TestBase):
'''Test base for tests relying on connection to server.'''

def setUp(self, auth_mode='ApiUser'):
super(LiveTestBase, self).setUp(auth_mode)

self.sg_version = self.sg.info()['version'][:3]

self._setup_db(self.config)

if self.sg.server_caps.version and \
self.sg.server_caps.version >= (3, 3, 0) and \
(self.sg.server_caps.host.startswith('0.0.0.0') or \
Expand All @@ -197,17 +206,22 @@ def setUp(self, auth_mode='ApiUser'):
else:
self.server_address = self.sg.server_caps.host


def _setup_db(self, config):
data = {'name':self.config.project_name}
self.project = _find_or_create_entity(self.sg, 'Project', data)

self.template_project = _find_or_create_entity(self.sg, 'Project', {
'name': 'Template Project',
'is_template': True
})

data = {'name':self.config.human_name,
'login':self.config.human_login,
'password_proxy':self.config.human_password}
if self.sg_version >= (3, 0, 0):
data['locked_until'] = None


self.human_user = _find_or_create_entity(self.sg, 'HumanUser', data)

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

data = {'project': self.template_project,
'title': self.config.ticket_title,
'sg_priority': '1'}
keys = ['title', 'project', 'sg_priority']
self.template_ticket = _find_or_create_entity(self.sg, 'Ticket', data, keys)

keys = ['code']
data = {'code':'api wrapper test storage',
'mac_path':'nowhere',
Expand Down
Loading

0 comments on commit 6a74c73

Please sign in to comment.