Skip to content

Commit 70128b5

Browse files
authored
Merge pull request #29 from adobe-apiplatform/v2
Move v2.0.1 to master
2 parents 4bfa16b + d7ca690 commit 70128b5

File tree

9 files changed

+111
-77
lines changed

9 files changed

+111
-77
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from setuptools import setup, find_packages
2222

2323
setup(name='umapi-client',
24-
version='2.0',
24+
version='2.0.1',
2525
description='Client for the User Management API (UMAPI) from Adobe - see https://adobe.ly/2h1pHgV',
2626
long_description=('The User Management API (aka the UMAPI) is an Adobe-hosted network service '
2727
'which provides Adobe Enterprise customers the ability to manage their users. This '

tests/test_actions.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ def test_action_create_two_dofirst():
5858

5959

6060
def test_execute_single_success_immediate():
61-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
61+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
6262
mock_post.return_value = MockResponse(200, {"result": "success"})
6363
conn = Connection(**mock_connection_params)
6464
action = Action(top="top").append(a="a")
6565
assert conn.execute_single(action, immediate=True) == (0, 1, 1)
6666

6767

6868
def test_execute_single_success_queued():
69-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
69+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
7070
mock_post.return_value = MockResponse(200, {"result": "success"})
7171
conn = Connection(throttle_actions=2, **mock_connection_params)
7272
action = Action(top="top").append(a="a")
@@ -75,7 +75,7 @@ def test_execute_single_success_queued():
7575

7676

7777
def test_execute_single_error_queued_throttled():
78-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
78+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
7979
mock_post.side_effect = [MockResponse(200, {"result": "success"}),
8080
MockResponse(200, {"result": "partial",
8181
"completed": 1,
@@ -93,7 +93,7 @@ def test_execute_single_error_queued_throttled():
9393

9494

9595
def test_execute_single_error_immediate_throttled():
96-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
96+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
9797
mock_post.return_value = MockResponse(200, {"result": "partial",
9898
"completed": 1,
9999
"notCompleted": 1,
@@ -105,15 +105,15 @@ def test_execute_single_error_immediate_throttled():
105105

106106

107107
def test_execute_single_dofirst_success_immediate():
108-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
108+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
109109
mock_post.return_value = MockResponse(200, {"result": "success"})
110110
conn = Connection(**mock_connection_params)
111111
action = Action(top="top").insert(a="a")
112112
assert conn.execute_single(action, immediate=True) == (0, 1, 1)
113113

114114

115115
def test_execute_single_error_immediate():
116-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
116+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
117117
mock_post.return_value = MockResponse(200, {"result": "error",
118118
"errors": [{"index": 0, "step": 0,
119119
"errorCode": "test.error",
@@ -128,7 +128,7 @@ def test_execute_single_error_immediate():
128128

129129

130130
def test_execute_single_multi_error_immediate():
131-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
131+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
132132
mock_post.return_value = MockResponse(200, {"result": "error",
133133
"errors": [{"index": 0, "step": 0,
134134
"errorCode": "error1",
@@ -150,7 +150,7 @@ def test_execute_single_multi_error_immediate():
150150

151151

152152
def test_execute_single_dofirst_error_immediate():
153-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
153+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
154154
mock_post.return_value = MockResponse(200, {"result": "error",
155155
"errors": [{"index": 0, "step": 0,
156156
"errorCode": "test.error",
@@ -165,7 +165,7 @@ def test_execute_single_dofirst_error_immediate():
165165

166166

167167
def test_execute_multiple_success():
168-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
168+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
169169
mock_post.return_value = MockResponse(200, {"result": "success"})
170170
conn = Connection(**mock_connection_params)
171171
action0 = Action(top="top0").append(a="a0").append(b="b")
@@ -174,7 +174,7 @@ def test_execute_multiple_success():
174174

175175

176176
def test_execute_multiple_success_queued():
177-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
177+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
178178
mock_post.return_value = MockResponse(200, {"result": "success"})
179179
conn = Connection(**mock_connection_params)
180180
action0 = Action(top="top0").append(a="a0").append(b="b")
@@ -184,7 +184,7 @@ def test_execute_multiple_success_queued():
184184

185185

186186
def test_execute_multiple_dofirst_success():
187-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
187+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
188188
mock_post.return_value = MockResponse(200, {"result": "success"})
189189
conn = Connection(**mock_connection_params)
190190
action0 = Action(top="top0").append(a="a0").insert(b="b")
@@ -193,7 +193,7 @@ def test_execute_multiple_dofirst_success():
193193

194194

195195
def test_execute_multiple_error():
196-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
196+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
197197
mock_post.return_value = MockResponse(200, {"result": "partial",
198198
"completed": 1,
199199
"notCompleted": 1,
@@ -212,7 +212,7 @@ def test_execute_multiple_error():
212212

213213

214214
def test_execute_multiple_multi_error():
215-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
215+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
216216
mock_post.return_value = MockResponse(200, {"result": "error",
217217
"completed": 1,
218218
"notCompleted": 1,
@@ -238,7 +238,7 @@ def test_execute_multiple_multi_error():
238238

239239

240240
def test_execute_multiple_dofirst_error():
241-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
241+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
242242
mock_post.return_value = MockResponse(200, {"result": "error",
243243
"completed": 1,
244244
"notCompleted": 1,
@@ -257,7 +257,7 @@ def test_execute_multiple_dofirst_error():
257257

258258

259259
def test_execute_multiple_single_queued_throttle_actions():
260-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
260+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
261261
mock_post.side_effect = [MockResponse(200, {"result": "success"}),
262262
MockResponse(200, {"result": "partial",
263263
"completed": 1,
@@ -291,7 +291,7 @@ def test_execute_multiple_single_queued_throttle_actions():
291291

292292

293293
def test_execute_multiple_queued_throttle_actions_error():
294-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
294+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
295295
mock_post.return_value = MockResponse(500)
296296
conn = Connection(throttle_actions=2, **mock_connection_params)
297297
action0 = Action(top="top0").append(a="a0")

tests/test_connections.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,116 +30,130 @@
3030

3131

3232
def test_remote_status_success():
33-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
33+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
3434
mock_get.return_value = MockResponse(200, body={"build": "2559", "version": "2.1.54", "state":"LIVE"})
3535
conn = Connection(**mock_connection_params)
3636
_, remote_status = conn.status(remote=True)
3737
assert remote_status == {"endpoint": "https://test/", "build": "2559", "version": "2.1.54", "state":"LIVE"}
3838

3939

4040
def test_remote_status_failure():
41-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
41+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
4242
mock_get.return_value = MockResponse(404, text="404 Not Found")
4343
conn = Connection(**mock_connection_params)
4444
_, remote_status = conn.status(remote=True)
4545
assert remote_status["status"].startswith("Unexpected")
4646

4747

4848
def test_remote_status_timeout():
49-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
49+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
5050
mock_get.side_effect = requests.Timeout
5151
conn = Connection(**mock_connection_params)
5252
_, remote_status = conn.status(remote=True)
5353
assert remote_status["status"].startswith("Unreachable")
5454

5555

5656
def test_get_success():
57-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
57+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
5858
mock_get.return_value = MockResponse(200, body=["test", "body"])
5959
conn = Connection(**mock_connection_params)
6060
assert conn.make_call("").json() == ["test", "body"]
6161

6262

63+
def test_get_success_test_mode():
64+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
65+
mock_get.return_value = MockResponse(200, body=["test", "body"])
66+
conn = Connection(test_mode=True, **mock_connection_params)
67+
assert conn.make_call("").json() == ["test", "body"]
68+
69+
6370
def test_post_success():
64-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
71+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
6572
mock_post.return_value = MockResponse(200, body=["test", "body"])
6673
conn = Connection(**mock_connection_params)
6774
assert conn.make_call("", [3, 5]).json() == ["test", "body"]
6875

6976

77+
def test_post_success_test_mode():
78+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
79+
mock_post.return_value = MockResponse(200, body=["test", "body"])
80+
conn = Connection(test_mode=True, **mock_connection_params)
81+
assert conn.make_call("", [3, 5]).json() == ["test", "body"]
82+
83+
7084
def test_get_timeout():
71-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
85+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
7286
mock_get.side_effect = requests.Timeout
7387
conn = Connection(**mock_connection_params)
7488
pytest.raises(UnavailableError, conn.make_call, "")
7589

7690

7791
def test_post_timeout():
78-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
92+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
7993
mock_post.side_effect = requests.Timeout
8094
conn = Connection(**mock_connection_params)
8195
pytest.raises(UnavailableError, conn.make_call, "", [3, 5])
8296

8397

8498
def test_get_retry_header_1():
85-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
99+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
86100
mock_get.return_value = MockResponse(429, headers={"Retry-After": "1"})
87101
conn = Connection(**mock_connection_params)
88102
pytest.raises(UnavailableError, conn.make_call, "")
89103

90104

91105
def test_post_retry_header_1():
92-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
106+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
93107
mock_post.return_value = MockResponse(429, headers={"Retry-After": "1"})
94108
conn = Connection(**mock_connection_params)
95109
pytest.raises(UnavailableError, conn.make_call, "", "[3, 5]")
96110

97111

98112
def test_get_retry_header_time_2():
99-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
113+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
100114
mock_get.return_value = MockResponse(502, headers={"Retry-After": formatdate(time.time() + 2.5)})
101115
conn = Connection(**mock_connection_params)
102116
pytest.raises(UnavailableError, conn.make_call, "")
103117

104118

105119
def test_post_retry_header_time_2():
106-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
120+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
107121
mock_post.return_value = MockResponse(502, headers={"Retry-After": formatdate(time.time() + 2.5)})
108122
conn = Connection(**mock_connection_params)
109123
pytest.raises(UnavailableError, conn.make_call, "", "[3, 5]")
110124

111125

112126
def test_get_retry_header_0():
113-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
127+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
114128
mock_get.return_value = MockResponse(503, headers={"Retry-After": "0"})
115129
conn = Connection(**mock_connection_params)
116130
pytest.raises(UnavailableError, conn.make_call, "")
117131

118132

119133
def test_post_retry_header_0():
120-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
134+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
121135
mock_post.return_value = MockResponse(503, headers={"Retry-After": "0"})
122136
conn = Connection(**mock_connection_params)
123137
pytest.raises(UnavailableError, conn.make_call, "", "[3, 5]")
124138

125139

126140
def test_get_retry_no_header():
127-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
141+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
128142
mock_get.return_value = MockResponse(504)
129143
conn = Connection(**mock_connection_params)
130144
pytest.raises(UnavailableError, conn.make_call, "")
131145

132146

133147
def test_post_retry_no_header():
134-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
148+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
135149
mock_post.return_value = MockResponse(504)
136150
conn = Connection(**mock_connection_params)
137151
pytest.raises(UnavailableError, conn.make_call, "", "[3, 5]")
138152

139153

140154
# log_stream fixture defined in conftest.py
141155
def test_get_retry_logging(log_stream):
142-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
156+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
143157
mock_get.return_value = MockResponse(429, headers={"Retry-After": "3"})
144158
stream, logger = log_stream
145159
params = dict(mock_connection_params)
@@ -160,7 +174,7 @@ def test_get_retry_logging(log_stream):
160174

161175
# log_stream fixture defined in conftest.py
162176
def test_post_retry_logging(log_stream):
163-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
177+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
164178
mock_post.return_value = MockResponse(429, headers={"Retry-After": "3"})
165179
stream, logger = log_stream
166180
params = dict(mock_connection_params)
@@ -180,28 +194,28 @@ def test_post_retry_logging(log_stream):
180194

181195

182196
def test_get_server_fail():
183-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
197+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
184198
mock_get.return_value = MockResponse(500, text="500 test server failure")
185199
conn = Connection(**mock_connection_params)
186200
pytest.raises(ServerError, conn.make_call, "")
187201

188202

189203
def test_post_server_fail():
190-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
204+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
191205
mock_post.return_value = MockResponse(500, text="500 test server failure")
192206
conn = Connection(**mock_connection_params)
193207
pytest.raises(ServerError, conn.make_call, "", "[3, 5]")
194208

195209

196210
def test_get_request_fail():
197-
with mock.patch("umapi_client.connection.requests.get") as mock_get:
211+
with mock.patch("umapi_client.connection.requests.Session.get") as mock_get:
198212
mock_get.return_value = MockResponse(400, text="400 test request failure")
199213
conn = Connection(**mock_connection_params)
200214
pytest.raises(RequestError, conn.make_call, "")
201215

202216

203217
def test_post_request_fail():
204-
with mock.patch("umapi_client.connection.requests.post") as mock_post:
218+
with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
205219
mock_post.return_value = MockResponse(400, text="400 test request failure")
206220
conn = Connection(**mock_connection_params)
207221
pytest.raises(RequestError, conn.make_call, "", "[3, 5]")

0 commit comments

Comments
 (0)