forked from shotgunsoftware/python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_unit.py
More file actions
275 lines (233 loc) · 10.8 KB
/
tests_unit.py
File metadata and controls
275 lines (233 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#! /opt/local/bin/python
import unittest
from mock import patch, Mock
import shotgun_api3 as api
class TestShotgunInit(unittest.TestCase):
'''Test case for Shotgun.__init__'''
def setUp(self):
self.server_path = 'http://server_path'
self.script_name = 'script_name'
self.api_key = 'api_key'
# Proxy Server Tests
def test_http_proxy_server(self):
proxy_server = "someserver.com"
http_proxy = proxy_server
sg = api.Shotgun(self.server_path,
self.script_name,
self.api_key,
http_proxy=http_proxy,
connect=False)
self.assertEquals(sg.config.proxy_server, proxy_server)
self.assertEquals(sg.config.proxy_port, 8080)
proxy_server = "123.456.789.012"
http_proxy = proxy_server
sg = api.Shotgun(self.server_path,
self.script_name,
self.api_key,
http_proxy=http_proxy,
connect=False)
self.assertEquals(sg.config.proxy_server, proxy_server)
self.assertEquals(sg.config.proxy_port, 8080)
def test_http_proxy_server_and_port(self):
proxy_server = "someserver.com"
proxy_port = 1234
http_proxy = "%s:%d" % (proxy_server, proxy_port)
sg = api.Shotgun(self.server_path,
self.script_name,
self.api_key,
http_proxy=http_proxy,
connect=False)
self.assertEquals(sg.config.proxy_server, proxy_server)
self.assertEquals(sg.config.proxy_port, proxy_port)
proxy_server = "123.456.789.012"
proxy_port = 1234
http_proxy = "%s:%d" % (proxy_server, proxy_port)
sg = api.Shotgun(self.server_path,
self.script_name,
self.api_key,
http_proxy=http_proxy,
connect=False)
self.assertEquals(sg.config.proxy_server, proxy_server)
self.assertEquals(sg.config.proxy_port, proxy_port)
def test_http_proxy_server_and_port_with_authentication(self):
proxy_server = "someserver.com"
proxy_port = 1234
proxy_user = "user"
proxy_pass = "password"
http_proxy = "%s:%s@%s:%d" % (proxy_user, proxy_pass, proxy_server,
proxy_port)
sg = api.Shotgun(self.server_path,
self.script_name,
self.api_key,
http_proxy=http_proxy,
connect=False)
self.assertEquals(sg.config.proxy_server, proxy_server)
self.assertEquals(sg.config.proxy_port, proxy_port)
self.assertEquals(sg.config.proxy_user, proxy_user)
self.assertEquals(sg.config.proxy_pass, proxy_pass)
proxy_server = "123.456.789.012"
proxy_port = 1234
proxy_user = "user"
proxy_pass = "password"
http_proxy = "%s:%s@%s:%d" % (proxy_user, proxy_pass, proxy_server,
proxy_port)
sg = api.Shotgun(self.server_path,
self.script_name,
self.api_key,
http_proxy=http_proxy,
connect=False)
self.assertEquals(sg.config.proxy_server, proxy_server)
self.assertEquals(sg.config.proxy_port, proxy_port)
self.assertEquals(sg.config.proxy_user, proxy_user)
self.assertEquals(sg.config.proxy_pass, proxy_pass)
def test_malformatted_proxy_info(self):
proxy_server = "someserver.com"
proxy_port = 1234
proxy_user = "user"
proxy_pass = "password"
http_proxy = "%s:%s@%s:%d" % (proxy_user, proxy_pass, proxy_server,
proxy_port)
conn_info = {
'base_url': self.server_path,
'script_name': self.script_name,
'api_key': self.api_key,
'connect': False,
}
conn_info['http_proxy'] = 'http://someserver.com'
self.assertRaises(ValueError, api.Shotgun, **conn_info)
conn_info['http_proxy'] = 'user@someserver.com'
self.assertRaises(ValueError, api.Shotgun, **conn_info)
conn_info['http_proxy'] = 'someserver.com:1234:5678'
self.assertRaises(ValueError, api.Shotgun, **conn_info)
class TestShotgunSummarize(unittest.TestCase):
'''Test case for _create_summary_request function and parameter
validation as it exists in Shotgun.summarize.
Does not require database connection or test data.'''
def setUp(self):
self.sg = api.Shotgun('http://server_path',
'script_name',
'api_key',
connect=False)
def test_filter_operator_none(self):
expected_logical_operator = 'and'
filter_operator = None
self._assert_filter_operator(expected_logical_operator, filter_operator)
def _assert_filter_operator(self, expected_logical_operator, filter_operator):
result = self.get_call_rpc_params(None, {'filter_operator':filter_operator})
actual_logical_operator = result['filters']['logical_operator']
self.assertEqual(expected_logical_operator, actual_logical_operator)
def test_filter_operator_all(self):
expected_logical_operator = 'and'
filter_operator = 'all'
self._assert_filter_operator(expected_logical_operator, filter_operator)
def test_filter_operator_or(self):
expected_logical_operator = 'or'
filter_operator = 'or'
self._assert_filter_operator(expected_logical_operator, filter_operator)
def test_filters(self):
path = 'path'
relation = 'relation'
value = 'value'
expected_condition = {'path':path, 'relation':relation, 'values':[value]}
args = ['',[[path, relation, value]],None]
result = self.get_call_rpc_params(args, {})
actual_condition = result['filters']['conditions'][0]
self.assertEquals(expected_condition, actual_condition)
@patch('shotgun_api3.Shotgun._call_rpc')
def get_call_rpc_params(self, args, kws, call_rpc):
'''Return params sent to _call_rpc from summarize.'''
if not args:
args = [None, [], None]
self.sg.summarize(*args, **kws)
return call_rpc.call_args[0][1]
def test_grouping(self):
result = self.get_call_rpc_params(None, {})
self.assertFalse(result.has_key('grouping'))
grouping = ['something']
kws = {'grouping':grouping}
result = self.get_call_rpc_params(None, kws)
self.assertEqual(grouping, result['grouping'])
def test_filters_type(self):
'''test_filters_type tests that filters parameter is a list'''
self.assertRaises(ValueError, self.sg.summarize, '', 'not a list', 'bad meta')
def test_grouping_type(self):
'''test_grouping_type tests that grouping parameter is a list or None'''
self.assertRaises(ValueError, self.sg.summarize, '', [], [], grouping='Not a list')
class TestShotgunBatch(unittest.TestCase):
def setUp(self):
self.sg = api.Shotgun('http://server_path',
'script_name',
'api_key',
connect=False)
def test_missing_required_key(self):
req = {}
# requires keys request_type and entity_type
self.assertRaises(api.ShotgunError, self.sg.batch, [req])
req['entity_type'] = 'Entity'
self.assertRaises(api.ShotgunError, self.sg.batch, [req])
req['request_type'] = 'not_real_type'
self.assertRaises(api.ShotgunError, self.sg.batch, [req])
# create requires data key
req['request_type'] = 'create'
self.assertRaises(api.ShotgunError, self.sg.batch, [req])
# update requires entity_id and data
req['request_type'] = 'update'
req['data'] = {}
self.assertRaises(api.ShotgunError, self.sg.batch, [req])
del req['data']
req['entity_id'] = 2334
self.assertRaises(api.ShotgunError, self.sg.batch, [req])
# delete requires entity_id
req['request_type'] = 'delete'
del req['entity_id']
self.assertRaises(api.ShotgunError, self.sg.batch, [req])
class TestServerCapabilities(unittest.TestCase):
def test_no_server_version(self):
self.assertRaises(api.ShotgunError, api.shotgun.ServerCapabilities, 'host', {})
def test_bad_version(self):
'''test_bad_meta tests passing bad meta data type'''
self.assertRaises(api.ShotgunError, api.shotgun.ServerCapabilities, 'host', {'version':(0,0,0)})
def test_dev_version(self):
serverCapabilities = api.shotgun.ServerCapabilities('host', {'version':(3,4,0,'Dev')})
self.assertEqual(serverCapabilities.version, (3,4,0))
self.assertTrue(serverCapabilities.is_dev)
serverCapabilities = api.shotgun.ServerCapabilities('host', {'version':(2,4,0)})
self.assertEqual(serverCapabilities.version, (2,4,0))
self.assertFalse(serverCapabilities.is_dev)
class TestClientCapabilities(unittest.TestCase):
def test_darwin(self):
self.assert_platform('Darwin', 'mac')
def test_windows(self):
self.assert_platform('win32','windows')
def test_linux(self):
self.assert_platform('Linux', 'linux')
def assert_platform(self, sys_ret_val, expected):
platform = api.shotgun.sys.platform
try:
api.shotgun.sys.platform = sys_ret_val
expected_local_path_field = "local_path_%s" % expected
client_caps = api.shotgun.ClientCapabilities()
self.assertEquals(client_caps.platform, expected)
self.assertEquals(client_caps.local_path_field, expected_local_path_field)
finally:
api.shotgun.sys.platform = platform
def test_no_platform(self):
platform = api.shotgun.sys.platform
try:
api.shotgun.sys.platform = "unsupported"
client_caps = api.shotgun.ClientCapabilities()
self.assertEquals(client_caps.platform, None)
self.assertEquals(client_caps.local_path_field, None)
finally:
api.shotgun.sys.platform = platform
@patch('shotgun_api3.shotgun.sys')
def test_py_version(self, mock_sys):
major = 2
minor = 7
micro = 3
mock_sys.version_info = (major, minor, micro, 'final', 0)
expected_py_version = "%s.%s" % (major, minor)
client_caps = api.shotgun.ClientCapabilities()
self.assertEquals(client_caps.py_version, expected_py_version)
if __name__ == '__main__':
unittest.main()