/
conftest.py
397 lines (273 loc) · 11.2 KB
/
conftest.py
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# coding: utf-8
import os
from unittest.mock import Mock
import pytest
from boxsdk.object.collaboration import Collaboration
from boxsdk.object.collection import Collection
from boxsdk.object.comment import Comment
from boxsdk.object.device_pinner import DevicePinner
from boxsdk.object.file import File
from boxsdk.object.file_version import FileVersion
from boxsdk.object.file_version_retention import FileVersionRetention
from boxsdk.object.legal_hold import LegalHold
from boxsdk.object.folder import Folder
from boxsdk.object.folder_lock import FolderLock
from boxsdk.object.group import Group
from boxsdk.object.group_membership import GroupMembership
from boxsdk.object.legal_hold_policy import LegalHoldPolicy
from boxsdk.object.legal_hold_policy_assignment import LegalHoldPolicyAssignment
from boxsdk.object.metadata_template import MetadataTemplate
from boxsdk.object.user import User
from boxsdk.object.retention_policy import RetentionPolicy
from boxsdk.object.retention_policy_assignment import RetentionPolicyAssignment
from boxsdk.object.search import Search
from boxsdk.object.sign_request import SignRequest
from boxsdk.object.storage_policy import StoragePolicy
from boxsdk.object.storage_policy_assignment import StoragePolicyAssignment
from boxsdk.object.terms_of_service import TermsOfService
from boxsdk.object.terms_of_service_user_status import TermsOfServiceUserStatus
from boxsdk.object.collaboration_allowlist import CollaborationAllowlist
from boxsdk.object.collaboration_allowlist_entry import CollaborationAllowlistEntry
from boxsdk.object.collaboration_allowlist_exempt_target import CollaborationAllowlistExemptTarget
from boxsdk.object.webhook import Webhook
from boxsdk.object.task import Task
from boxsdk.object.task_assignment import TaskAssignment
from boxsdk.object.web_link import WebLink
from boxsdk.util.default_arg_value import SDK_VALUE_NOT_SET
# pylint:disable=redefined-outer-name
@pytest.fixture(scope='module')
def mock_group_membership_id():
return 'fake-group-membership-5'
@pytest.fixture(scope='module')
def mock_collaboration_id():
return 'collab_id1'
@pytest.fixture(scope='module')
def mock_collection_id():
return 'collection_id1'
@pytest.fixture(scope='module')
def mock_file_path():
return os.path.join('path', 'to', 'file')
@pytest.fixture(scope='function')
def mock_content_response(make_mock_box_request):
mock_box_response, mock_network_response = make_mock_box_request(content=b'Contents of a text file.')
mock_network_response.response_as_stream = raw = Mock()
raw.stream.return_value = (bytes((b,)) for b in mock_box_response.content)
return mock_box_response
@pytest.fixture(scope='function', params=[False, True])
def mock_upload_response_contains_entries(request):
"""Is the upload response formatted as {"type": "file", "id": "123", ...}, or as {"entries": [{...}]}.
The v2.0 API does the latter, but future versions might do the former. So
we'll test both.
"""
return request.param
@pytest.fixture(scope='function')
def mock_upload_response(mock_object_id, make_mock_box_request, mock_upload_response_contains_entries):
response = {'type': 'file', 'id': mock_object_id, 'description': 'Test File Description', }
if mock_upload_response_contains_entries:
response = {'entries': [response]}
mock_box_response, _ = make_mock_box_request(response=response)
return mock_box_response
@pytest.fixture()
def test_collaboration(mock_box_session, mock_collaboration_id):
return Collaboration(mock_box_session, mock_collaboration_id)
@pytest.fixture()
def test_file(mock_box_session, mock_object_id):
return File(mock_box_session, mock_object_id)
@pytest.fixture()
def test_file_version(mock_box_session):
return FileVersion(mock_box_session, 'file_version_id')
@pytest.fixture()
def test_comment(mock_box_session, mock_object_id):
return Comment(mock_box_session, mock_object_id)
@pytest.fixture()
def test_collaboration_allowlist(mock_box_session):
return CollaborationAllowlist(mock_box_session)
@pytest.fixture()
def test_collaboration_allowlist_entry(mock_box_session, mock_object_id):
return CollaborationAllowlistEntry(mock_box_session, mock_object_id)
@pytest.fixture()
def test_collaboration_allowlist_exemption(mock_box_session, mock_object_id):
return CollaborationAllowlistExemptTarget(mock_box_session, mock_object_id)
@pytest.fixture()
def test_folder(mock_box_session, mock_object_id):
return Folder(mock_box_session, mock_object_id)
@pytest.fixture()
def test_group(mock_box_session, mock_group_id):
return Group(mock_box_session, mock_group_id)
@pytest.fixture()
def test_retention_policy(mock_box_session, mock_object_id):
return RetentionPolicy(mock_box_session, mock_object_id)
@pytest.fixture()
def test_file_version_retention(mock_box_session, mock_object_id):
return FileVersionRetention(mock_box_session, mock_object_id)
@pytest.fixture()
def test_retention_policy_assignment(mock_box_session, mock_object_id):
return RetentionPolicyAssignment(mock_box_session, mock_object_id)
@pytest.fixture()
def test_group_membership(mock_box_session, mock_object_id):
return GroupMembership(mock_box_session, mock_object_id)
@pytest.fixture()
def test_legal_hold_policy(mock_box_session, mock_object_id):
return LegalHoldPolicy(mock_box_session, mock_object_id)
@pytest.fixture()
def test_legal_hold_policy_assignment(mock_box_session, mock_object_id):
return LegalHoldPolicyAssignment(mock_box_session, mock_object_id)
@pytest.fixture()
def test_legal_hold(mock_box_session, mock_object_id):
return LegalHold(mock_box_session, mock_object_id)
@pytest.fixture()
def test_search(mock_box_session):
return Search(mock_box_session)
@pytest.fixture()
def test_storage_policy(mock_box_session, mock_object_id):
return StoragePolicy(mock_box_session, mock_object_id)
@pytest.fixture()
def test_storage_policy_assignment(mock_box_session, mock_object_id):
return StoragePolicyAssignment(mock_box_session, mock_object_id)
@pytest.fixture()
def test_terms_of_service(mock_box_session, mock_object_id):
return TermsOfService(mock_box_session, mock_object_id)
@pytest.fixture()
def test_terms_of_service_user_status(mock_box_session, mock_object_id):
return TermsOfServiceUserStatus(mock_box_session, mock_object_id)
@pytest.fixture()
def test_webhook(mock_box_session, mock_object_id):
return Webhook(mock_box_session, mock_object_id)
@pytest.fixture()
def test_task(mock_box_session, mock_object_id):
return Task(mock_box_session, mock_object_id)
@pytest.fixture()
def test_task_assignment(mock_box_session, mock_object_id):
return TaskAssignment(mock_box_session, mock_object_id)
@pytest.fixture()
def test_web_link(mock_box_session, mock_object_id):
return WebLink(mock_box_session, mock_object_id)
@pytest.fixture()
def test_device_pin(mock_box_session, mock_object_id):
return DevicePinner(mock_box_session, mock_object_id)
@pytest.fixture(scope='function')
def mock_collab_response(make_mock_box_request, mock_collaboration_id):
mock_box_response, _ = make_mock_box_request(
response={'type': 'collaboration', 'id': mock_collaboration_id},
)
return mock_box_response
@pytest.fixture()
def mock_user(mock_box_session, mock_user_id):
user = User(mock_box_session, mock_user_id)
return user
@pytest.fixture()
def mock_collection(mock_box_session, mock_collection_id):
return Collection(mock_box_session, mock_collection_id)
@pytest.fixture(scope='function')
def mock_precondition_failed_response(mock_object_id, make_mock_box_request):
mock_box_response, _ = make_mock_box_request(
status_code=412,
response_ok=False,
response={'type': 'folder', 'id': mock_object_id},
)
return mock_box_response
@pytest.fixture()
def mock_group_membership_dict(mock_group_membership_id, mock_user_id, mock_group_id):
data = {
'type': 'group_membership',
'id': mock_group_membership_id,
'role': 'member',
'user': {'type': 'user', 'id': mock_user_id},
'group': {'type': 'group', 'id': mock_group_id},
}
return data
@pytest.fixture()
def mock_add_member_response(mock_group_membership_dict, make_mock_box_request):
mock_box_response, _ = make_mock_box_request(
status_code=200,
response_ok=True,
response=mock_group_membership_dict,
)
return mock_box_response
@pytest.fixture()
def if_match_header(etag):
return {'If-Match': etag} if etag is not None else None
@pytest.fixture()
def if_none_match_header(etag):
return {'If-None-Match': etag} if etag is not None else None
@pytest.fixture()
def if_match_sha1_header(etag, sha1):
headers = {}
if etag is not None:
headers['If-Match'] = etag
if sha1 is not None:
headers['Content-MD5'] = sha1
if not headers:
headers = None
return headers
@pytest.fixture(params=[None, 'etag'])
def etag(request):
return request.param
@pytest.fixture(params=[None, 'cf23df2207d99a74fbe169e3eba035e633b65d94'])
def sha1(request):
return request.param
@pytest.fixture(params=[True, False])
def preflight_check(request):
return request.param
@pytest.fixture(params=[True, False])
def upload_using_accelerator(request):
return request.param
@pytest.fixture(params=[True, False])
def preflight_fails(preflight_check, request):
return preflight_check and request.param
@pytest.fixture(params=[True, False])
def upload_using_accelerator_fails(upload_using_accelerator, request):
return upload_using_accelerator and request.param
@pytest.fixture(params=[0, 100])
def file_size(request):
return request.param
@pytest.fixture()
def mock_group(mock_box_session, mock_group_id):
group = Group(mock_box_session, mock_group_id)
return group
@pytest.fixture(params=(True, False, None))
def shared_link_can_download(request):
return request.param
@pytest.fixture(params=(True, False, None))
def shared_link_can_preview(request):
return request.param
@pytest.fixture(params=('open', None))
def shared_link_access(request):
return request.param
@pytest.fixture(params=('hunter2', None))
def shared_link_password(request):
return request.param
@pytest.fixture(params=('2018-10-31', '2018-10-31T23:59:59-07:00', None, SDK_VALUE_NOT_SET))
def shared_link_unshared_at(request):
return request.param
@pytest.fixture(params=('my-custom-vanity-name', None))
def shared_link_vanity_name(request):
return request.param
@pytest.fixture(params=[
# Test case for plain message
(
'message',
'Hello there!'
),
# Test case for tagged message
(
'tagged_message',
'@[22222:Test User] Hi!'
)
])
def comment_params(request):
return request.param
@pytest.fixture()
def test_metadata_template(mock_box_session):
fake_response = {
'type': 'metadata_template',
'scope': 'enterprise',
'templateKey': 'vContract',
}
return MetadataTemplate(mock_box_session, None, fake_response)
@pytest.fixture()
def test_folder_lock(mock_box_session, mock_object_id):
return FolderLock(mock_box_session, mock_object_id)
@pytest.fixture()
def test_sign_request(mock_box_session, mock_object_id):
return SignRequest(mock_box_session, mock_object_id)