@@ -61,15 +61,15 @@ def test_execute_single_success():
6161 mock_post .return_value = MockResponse (200 , {"result" : "success" })
6262 conn = Connection (** mock_connection_params )
6363 action = Action (top = "top" ).append (a = "a" )
64- assert conn .execute_single (action ) is True
64+ assert conn .execute_single (action ) == ( 1 , 1 )
6565
6666
6767def test_execute_single_dofirst_success ():
6868 with mock .patch ("umapi_client.connection.requests.post" ) as mock_post :
6969 mock_post .return_value = MockResponse (200 , {"result" : "success" })
7070 conn = Connection (** mock_connection_params )
7171 action = Action (top = "top" ).insert (a = "a" )
72- assert conn .execute_single (action ) is True
72+ assert conn .execute_single (action ) == ( 1 , 1 )
7373
7474
7575def test_execute_multiple_success ():
@@ -78,7 +78,7 @@ def test_execute_multiple_success():
7878 conn = Connection (** mock_connection_params )
7979 action0 = Action (top = "top0" ).append (a = "a0" ).append (b = "b" )
8080 action1 = Action (top = "top1" ).append (a = "a1" )
81- assert conn .execute_multiple ([action0 , action1 ]) == 2
81+ assert conn .execute_multiple ([action0 , action1 ]) == ( 2 , 2 )
8282
8383
8484def test_execute_multiple_dofirst_success ():
@@ -87,7 +87,7 @@ def test_execute_multiple_dofirst_success():
8787 conn = Connection (** mock_connection_params )
8888 action0 = Action (top = "top0" ).append (a = "a0" ).insert (b = "b" )
8989 action1 = Action (top = "top1" ).append (a = "a1" )
90- assert conn .execute_multiple ([action0 , action1 ]) == 2
90+ assert conn .execute_multiple ([action0 , action1 ]) == ( 2 , 2 )
9191
9292
9393def test_execute_single_error ():
@@ -98,9 +98,8 @@ def test_execute_single_error():
9898 "message" : "Test error message" }]})
9999 conn = Connection (** mock_connection_params )
100100 action = Action (top = "top" ).append (a = "a" )
101- assert conn .execute_single (action ) is False
101+ assert conn .execute_single (action ) == ( 1 , 0 )
102102 assert action .execution_errors () == [{"command" : {"a" : "a" },
103- "step" : 0 ,
104103 "errorCode" : "test.error" ,
105104 "message" : "Test error message" }]
106105
@@ -116,13 +115,11 @@ def test_execute_single_multi_error():
116115 "message" : "message2" }]})
117116 conn = Connection (** mock_connection_params )
118117 action = Action (top = "top" ).append (a = "a" )
119- assert conn .execute_single (action ) is False
118+ assert conn .execute_single (action ) == ( 1 , 0 )
120119 assert action .execution_errors () == [{"command" : {"a" : "a" },
121- "step" : 0 ,
122120 "errorCode" : "error1" ,
123121 "message" : "message1" },
124122 {"command" : {"a" : "a" },
125- "step" : 0 ,
126123 "errorCode" : "error2" ,
127124 "message" : "message2" }]
128125
@@ -135,9 +132,8 @@ def test_execute_single_dofirst_error():
135132 "message" : "Test error message" }]})
136133 conn = Connection (** mock_connection_params )
137134 action = Action (top = "top" ).insert (a = "a" )
138- assert conn .execute_single (action ) is False
135+ assert conn .execute_single (action ) == ( 1 , 0 )
139136 assert action .execution_errors () == [{"command" : {"a" : "a" },
140- "step" : 0 ,
141137 "errorCode" : "test.error" ,
142138 "message" : "Test error message" }]
143139
@@ -153,10 +149,9 @@ def test_execute_multiple_error():
153149 conn = Connection (** mock_connection_params )
154150 action0 = Action (top = "top0" ).append (a = "a0" )
155151 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 )
157153 assert action0 .execution_errors () == []
158154 assert action1 .execution_errors () == [{"command" : {"b" : "b" },
159- "step" : 1 ,
160155 "errorCode" : "test.error" ,
161156 "message" : "Test error message" }]
162157
@@ -175,14 +170,12 @@ def test_execute_multiple_multi_error():
175170 conn = Connection (** mock_connection_params )
176171 action0 = Action (top = "top0" ).append (a = "a0" )
177172 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 )
179174 assert action0 .execution_errors () == []
180175 assert action1 .execution_errors () == [{"command" : {"b" : "b" },
181- "step" : 1 ,
182176 "errorCode" : "error1" ,
183177 "message" : "message1" },
184178 {"command" : {"b" : "b" },
185- "step" : 1 ,
186179 "errorCode" : "error2" ,
187180 "message" : "message2" }]
188181
@@ -198,9 +191,37 @@ def test_execute_multiple_dofirst_error():
198191 conn = Connection (** mock_connection_params )
199192 action0 = Action (top = "top0" ).append (a = "a0" )
200193 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 )
202195 assert action0 .execution_errors () == []
203196 assert action1 .execution_errors () == [{"command" : {"a" : "a1" },
204- "step" : 1 ,
205197 "errorCode" : "test.error" ,
206198 "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