-
Notifications
You must be signed in to change notification settings - Fork 214
/
test_with_shared_link.py
145 lines (128 loc) · 4.32 KB
/
test_with_shared_link.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
# coding: utf-8
from unittest.mock import call
import pytest
from boxsdk.config import API, Client
from boxsdk.util.shared_link import get_shared_link_header
@pytest.fixture
def shared_link():
return 'https://app.box.com/s/q2i1024dvguiads6mzj2avsq9hmz43du'
@pytest.fixture(params=(None, 'shared_link_password'))
def shared_link_password(request):
return request.param
@pytest.fixture
def box_api_headers(shared_link, shared_link_password, access_token):
# pylint:disable=redefined-outer-name
box_api_header = get_shared_link_header(shared_link, shared_link_password)['BoxApi']
return {
'Authorization': f'Bearer {access_token}',
'BoxApi': box_api_header,
'User-Agent': Client.USER_AGENT_STRING,
'X-Box-UA': Client.BOX_UA_STRING,
}
def test_client_with_shared_link_causes_box_api_header_to_be_added(
box_client,
mock_box_network,
generic_successful_response,
shared_link,
shared_link_password,
box_api_headers,
):
# pylint:disable=redefined-outer-name
mock_box_network.session.request.side_effect = [
generic_successful_response,
]
box_client.with_shared_link(shared_link, shared_link_password).folder('0').get()
assert mock_box_network.session.request.mock_calls == [
call(
'GET',
f'{API.BASE_API_URL}/folders/0',
headers=box_api_headers,
params=None,
),
]
def test_folder_object_with_shared_link_causes_box_api_header_to_be_added(
box_client,
mock_box_network,
generic_successful_response,
shared_link,
shared_link_password,
box_api_headers,
):
# pylint:disable=redefined-outer-name
mock_box_network.session.request.side_effect = [
generic_successful_response,
]
box_client.folder('0').with_shared_link(shared_link, shared_link_password).get()
assert mock_box_network.session.request.mock_calls == [
call(
'GET',
f'{API.BASE_API_URL}/folders/0',
headers=box_api_headers,
params=None,
),
]
def test_group_membership_object_with_shared_link_causes_box_api_header_to_be_added(
box_client,
mock_box_network,
generic_successful_response,
shared_link,
shared_link_password,
box_api_headers,
):
# pylint:disable=redefined-outer-name
mock_box_network.session.request.side_effect = [
generic_successful_response,
]
box_client.group_membership('0').with_shared_link(shared_link, shared_link_password).get()
assert mock_box_network.session.request.mock_calls == [
call(
'GET',
f'{API.BASE_API_URL}/group_memberships/0',
headers=box_api_headers,
params=None,
),
]
def test_events_endpoint_with_shared_link_causes_box_api_header_to_be_added(
box_client,
mock_box_network,
generic_successful_response,
shared_link,
shared_link_password,
box_api_headers,
):
# pylint:disable=redefined-outer-name
mock_box_network.session.request.side_effect = [
generic_successful_response,
]
stream_position = 1348790499819
options = {'url': f'{API.BASE_API_URL}/events', 'retry_timeout': 60}
box_client.events().with_shared_link(shared_link, shared_link_password).long_poll(options, stream_position)
assert mock_box_network.session.request.mock_calls == [
call(
'GET',
options['url'],
headers=box_api_headers,
timeout=options['retry_timeout'],
params={'stream_position': stream_position},
),
]
def test_metadata_endpoint_with_shared_link_causes_box_api_header_to_be_added(
box_client,
mock_box_network,
generic_successful_response,
shared_link,
shared_link_password,
box_api_headers,
):
# pylint:disable=redefined-outer-name
mock_box_network.session.request.side_effect = [
generic_successful_response,
]
box_client.file('0').metadata().with_shared_link(shared_link, shared_link_password).get()
assert mock_box_network.session.request.mock_calls == [
call(
'GET',
f'{API.BASE_API_URL}/files/0/metadata/global/properties',
headers=box_api_headers,
),
]