@@ -89,11 +89,14 @@ def test_create_task(self, mock_post, api):
8989 @patch ("requests.get" )
9090 def test_wait_for_task_result_success (self , mock_get , api ):
9191 mock_response = Mock ()
92- mock_response .json .return_value = {
93- "id" : "task123" ,
94- "targets" : [{"model" : "alignment" , "status" : "completed" }],
95- "data" : "test"
96- }
92+ # Return a list of tasks (as the /tasks endpoint does)
93+ mock_response .json .return_value = [
94+ {
95+ "id" : "task123" ,
96+ "targets" : [{"model" : "alignment" , "status" : "completed" }],
97+ "data" : "test"
98+ }
99+ ]
97100 mock_get .return_value = mock_response
98101
99102 result = api .wait_for_task_result ("task123" )
@@ -105,10 +108,12 @@ def test_wait_for_task_result_success(self, mock_get, api):
105108 @patch ("requests.get" )
106109 def test_wait_for_task_result_failure (self , mock_get , api ):
107110 mock_response = Mock ()
108- mock_response .json .return_value = {
109- "id" : "task123" ,
110- "targets" : [{"model" : "alignment" , "status" : "failed" , "error" : "test error" }]
111- }
111+ mock_response .json .return_value = [
112+ {
113+ "id" : "task123" ,
114+ "targets" : [{"model" : "alignment" , "status" : "failed" , "error" : "test error" }]
115+ }
116+ ]
112117 mock_get .return_value = mock_response
113118
114119 with pytest .raises (Exception , match = "Target alignment failed: test error" ):
@@ -119,9 +124,9 @@ def test_wait_for_task_result_failure(self, mock_get, api):
119124 def test_wait_for_task_result_polling (self , mock_sleep , mock_get , api ):
120125 """Test polling behavior with in-progress status before completion"""
121126 mock_responses = [
122- Mock (json = lambda : {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}),
123- Mock (json = lambda : {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}),
124- Mock (json = lambda : {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "completed" }], "data" : "test" }),
127+ Mock (json = lambda : [ {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}] ),
128+ Mock (json = lambda : [ {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}] ),
129+ Mock (json = lambda : [ {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "completed" }], "data" : "test" }] ),
125130 ]
126131 mock_get .side_effect = mock_responses
127132
@@ -148,10 +153,12 @@ def test_wait_for_task_result_with_retries(self, mock_get, api):
148153 def test_wait_for_task_result_timeout (self , mock_time , mock_get , api ):
149154 """Test that task polling times out after configured duration"""
150155 mock_time .side_effect = [0 , api .config .timeout_minutes * 60 + 1 ] # Simulate timeout
151- mock_get .return_value = Mock (json = lambda : {
152- "id" : "task123" ,
153- "targets" : [{"model" : "alignment" , "status" : "processing" }]
154- })
156+ mock_get .return_value = Mock (json = lambda : [
157+ {
158+ "id" : "task123" ,
159+ "targets" : [{"model" : "alignment" , "status" : "processing" }]
160+ }
161+ ])
155162
156163 with pytest .raises (TranscriptionError , match = f"Transcription timed out after { api .config .timeout_minutes } minutes" ):
157164 api .wait_for_task_result ("task123" )
@@ -163,9 +170,9 @@ def test_wait_for_task_result_logs_status(self, mock_sleep, mock_time, mock_get,
163170 """Test that task polling logs status periodically"""
164171 mock_time .side_effect = [0 , 30 , 61 , 90 ] # Simulate time passing
165172 mock_get .side_effect = [
166- Mock (json = lambda : {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}),
167- Mock (json = lambda : {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}),
168- Mock (json = lambda : {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "completed" }], "data" : "test" }),
173+ Mock (json = lambda : [ {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}] ),
174+ Mock (json = lambda : [ {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "processing" }]}] ),
175+ Mock (json = lambda : [ {"id" : "task123" , "targets" : [{"model" : "alignment" , "status" : "completed" }], "data" : "test" }] ),
169176 ]
170177
171178 result = api .wait_for_task_result ("task123" )
0 commit comments