@@ -61,15 +61,15 @@ def test_execute_single_success():
61
61
mock_post .return_value = MockResponse (200 , {"result" : "success" })
62
62
conn = Connection (** mock_connection_params )
63
63
action = Action (top = "top" ).append (a = "a" )
64
- assert conn .execute_single (action ) is True
64
+ assert conn .execute_single (action ) == ( 1 , 1 )
65
65
66
66
67
67
def test_execute_single_dofirst_success ():
68
68
with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
69
69
mock_post .return_value = MockResponse (200 , {"result" : "success" })
70
70
conn = Connection (** mock_connection_params )
71
71
action = Action (top = "top" ).insert (a = "a" )
72
- assert conn .execute_single (action ) is True
72
+ assert conn .execute_single (action ) == ( 1 , 1 )
73
73
74
74
75
75
def test_execute_multiple_success ():
@@ -78,7 +78,7 @@ def test_execute_multiple_success():
78
78
conn = Connection (** mock_connection_params )
79
79
action0 = Action (top = "top0" ).append (a = "a0" ).append (b = "b" )
80
80
action1 = Action (top = "top1" ).append (a = "a1" )
81
- assert conn .execute_multiple ([action0 , action1 ]) == 2
81
+ assert conn .execute_multiple ([action0 , action1 ]) == ( 2 , 2 )
82
82
83
83
84
84
def test_execute_multiple_dofirst_success ():
@@ -87,7 +87,7 @@ def test_execute_multiple_dofirst_success():
87
87
conn = Connection (** mock_connection_params )
88
88
action0 = Action (top = "top0" ).append (a = "a0" ).insert (b = "b" )
89
89
action1 = Action (top = "top1" ).append (a = "a1" )
90
- assert conn .execute_multiple ([action0 , action1 ]) == 2
90
+ assert conn .execute_multiple ([action0 , action1 ]) == ( 2 , 2 )
91
91
92
92
93
93
def test_execute_single_error ():
@@ -98,9 +98,8 @@ def test_execute_single_error():
98
98
"message" : "Test error message" }]})
99
99
conn = Connection (** mock_connection_params )
100
100
action = Action (top = "top" ).append (a = "a" )
101
- assert conn .execute_single (action ) is False
101
+ assert conn .execute_single (action ) == ( 1 , 0 )
102
102
assert action .execution_errors () == [{"command" : {"a" : "a" },
103
- "step" : 0 ,
104
103
"errorCode" : "test.error" ,
105
104
"message" : "Test error message" }]
106
105
@@ -116,13 +115,11 @@ def test_execute_single_multi_error():
116
115
"message" : "message2" }]})
117
116
conn = Connection (** mock_connection_params )
118
117
action = Action (top = "top" ).append (a = "a" )
119
- assert conn .execute_single (action ) is False
118
+ assert conn .execute_single (action ) == ( 1 , 0 )
120
119
assert action .execution_errors () == [{"command" : {"a" : "a" },
121
- "step" : 0 ,
122
120
"errorCode" : "error1" ,
123
121
"message" : "message1" },
124
122
{"command" : {"a" : "a" },
125
- "step" : 0 ,
126
123
"errorCode" : "error2" ,
127
124
"message" : "message2" }]
128
125
@@ -135,9 +132,8 @@ def test_execute_single_dofirst_error():
135
132
"message" : "Test error message" }]})
136
133
conn = Connection (** mock_connection_params )
137
134
action = Action (top = "top" ).insert (a = "a" )
138
- assert conn .execute_single (action ) is False
135
+ assert conn .execute_single (action ) == ( 1 , 0 )
139
136
assert action .execution_errors () == [{"command" : {"a" : "a" },
140
- "step" : 0 ,
141
137
"errorCode" : "test.error" ,
142
138
"message" : "Test error message" }]
143
139
@@ -153,10 +149,9 @@ def test_execute_multiple_error():
153
149
conn = Connection (** mock_connection_params )
154
150
action0 = Action (top = "top0" ).append (a = "a0" )
155
151
action1 = Action (top = "top1" ).append (a = "a1" ).append (b = "b" )
156
- assert conn .execute_multiple ([action0 , action1 ]) == 1
152
+ assert conn .execute_multiple ([action0 , action1 ]) == ( 2 , 1 )
157
153
assert action0 .execution_errors () == []
158
154
assert action1 .execution_errors () == [{"command" : {"b" : "b" },
159
- "step" : 1 ,
160
155
"errorCode" : "test.error" ,
161
156
"message" : "Test error message" }]
162
157
@@ -175,14 +170,12 @@ def test_execute_multiple_multi_error():
175
170
conn = Connection (** mock_connection_params )
176
171
action0 = Action (top = "top0" ).append (a = "a0" )
177
172
action1 = Action (top = "top1" ).append (a = "a1" ).append (b = "b" )
178
- assert conn .execute_multiple ([action0 , action1 ]) == 1
173
+ assert conn .execute_multiple ([action0 , action1 ]) == ( 2 , 1 )
179
174
assert action0 .execution_errors () == []
180
175
assert action1 .execution_errors () == [{"command" : {"b" : "b" },
181
- "step" : 1 ,
182
176
"errorCode" : "error1" ,
183
177
"message" : "message1" },
184
178
{"command" : {"b" : "b" },
185
- "step" : 1 ,
186
179
"errorCode" : "error2" ,
187
180
"message" : "message2" }]
188
181
@@ -198,9 +191,37 @@ def test_execute_multiple_dofirst_error():
198
191
conn = Connection (** mock_connection_params )
199
192
action0 = Action (top = "top0" ).append (a = "a0" )
200
193
action1 = Action (top = "top1" ).append (a = "a1" ).insert (b = "b" )
201
- assert conn .execute_multiple ([action0 , action1 ]) == 1
194
+ assert conn .execute_multiple ([action0 , action1 ]) == ( 2 , 1 )
202
195
assert action0 .execution_errors () == []
203
196
assert action1 .execution_errors () == [{"command" : {"a" : "a1" },
204
- "step" : 1 ,
205
197
"errorCode" : "test.error" ,
206
198
"message" : "Test error message" }]
199
+
200
+
201
+ def test_execute_single_throttle_commands ():
202
+ with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
203
+ mock_post .return_value = MockResponse (200 , {"result" : "partial" ,
204
+ "completed" : 1 ,
205
+ "notCompleted" : 1 ,
206
+ "errors" : [{"index" : 1 , "step" : 0 , "errorCode" : "test" }]})
207
+ conn = Connection (throttle_commands = 2 , ** mock_connection_params )
208
+ action = Action (top = "top0" ).append (a = "a0" ).append (a = "a1" ).append (a = "a2" )
209
+ assert conn .execute_single (action ) == (2 , 1 )
210
+ assert action .execution_errors () == [{"command" : {"a" : "a2" }, "errorCode" : "test" }]
211
+
212
+
213
+ def test_execute_multiple_throttle_actions ():
214
+ with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
215
+ mock_post .side_effect = [MockResponse (200 , {"result" : "success" }),
216
+ MockResponse (200 , {"result" : "partial" ,
217
+ "completed" : 0 ,
218
+ "notCompleted" : 1 ,
219
+ "errors" : [{"index" : 0 , "step" : 0 , "errorCode" : "test" }]})]
220
+ conn = Connection (throttle_actions = 2 , ** mock_connection_params )
221
+ action0 = Action (top = "top0" ).append (a = "a0" )
222
+ action1 = Action (top = "top1" ).append (a = "a1" )
223
+ action2 = Action (top = "top2" ).append (a = "a2" )
224
+ assert conn .execute_multiple ([action0 , action1 , action2 ]) == (3 , 2 )
225
+ assert action0 .execution_errors () == []
226
+ assert action1 .execution_errors () == []
227
+ assert action2 .execution_errors () == [{"command" : {"a" : "a2" }, "errorCode" : "test" }]
0 commit comments