@@ -141,10 +141,38 @@ def test_delete_org_crawl_running(
141
141
f"{ API_PREFIX } /orgs/{ non_default_org_id } " , headers = admin_auth_headers
142
142
)
143
143
assert r .status_code == 200
144
- assert r .json ()["deleted" ]
144
+ data = r .json ()
145
+ assert data ["deleted" ]
145
146
146
- time .sleep (5 )
147
+ job_id = data ["id" ]
148
+
149
+ # Check that background job is launched and eventually succeeds
150
+ max_attempts = 18
151
+ attempts = 1
152
+ while True :
153
+ try :
154
+ r = requests .get (
155
+ f"{ API_PREFIX } /orgs/all/jobs/{ job_id } " , headers = admin_auth_headers
156
+ )
157
+ assert r .status_code == 200
158
+ success = r .json ()["success" ]
147
159
160
+ if success :
161
+ break
162
+
163
+ if success is False :
164
+ assert False
165
+
166
+ if attempts >= max_attempts :
167
+ assert False
168
+
169
+ time .sleep (10 )
170
+ except :
171
+ pass
172
+
173
+ attempts += 1
174
+
175
+ # Check that org was deleted
148
176
r = requests .get (f"{ API_PREFIX } /orgs" , headers = admin_auth_headers )
149
177
data = r .json ()
150
178
for org in data ["items" ]:
@@ -159,10 +187,38 @@ def test_delete_org_qa_running(
159
187
f"{ API_PREFIX } /orgs/{ non_default_org_id } " , headers = admin_auth_headers
160
188
)
161
189
assert r .status_code == 200
162
- assert r .json ()["deleted" ]
190
+ data = r .json ()
191
+ assert data ["deleted" ]
163
192
164
- time .sleep (5 )
193
+ job_id = data ["id" ]
194
+
195
+ # Check that background job is launched and eventually succeeds
196
+ max_attempts = 18
197
+ attempts = 1
198
+ while True :
199
+ try :
200
+ r = requests .get (
201
+ f"{ API_PREFIX } /orgs/all/jobs/{ job_id } " , headers = admin_auth_headers
202
+ )
203
+ assert r .status_code == 200
204
+ success = r .json ()["success" ]
205
+
206
+ if success :
207
+ break
165
208
209
+ if success is False :
210
+ assert False
211
+
212
+ if attempts >= max_attempts :
213
+ assert False
214
+
215
+ time .sleep (10 )
216
+ except :
217
+ pass
218
+
219
+ attempts += 1
220
+
221
+ # Check that org was deleted
166
222
r = requests .get (f"{ API_PREFIX } /orgs" , headers = admin_auth_headers )
167
223
data = r .json ()
168
224
for org in data ["items" ]:
@@ -177,10 +233,38 @@ def test_delete_org_profile_running(
177
233
f"{ API_PREFIX } /orgs/{ non_default_org_id } " , headers = admin_auth_headers
178
234
)
179
235
assert r .status_code == 200
180
- assert r .json ()["deleted" ]
236
+ data = r .json ()
237
+ assert data ["deleted" ]
181
238
182
- time .sleep (5 )
239
+ job_id = data ["id" ]
240
+
241
+ # Check that background job is launched and eventually succeeds
242
+ max_attempts = 18
243
+ attempts = 1
244
+ while True :
245
+ try :
246
+ r = requests .get (
247
+ f"{ API_PREFIX } /orgs/all/jobs/{ job_id } " , headers = admin_auth_headers
248
+ )
249
+ assert r .status_code == 200
250
+ success = r .json ()["success" ]
251
+
252
+ if success :
253
+ break
254
+
255
+ if success is False :
256
+ assert False
257
+
258
+ if attempts >= max_attempts :
259
+ assert False
260
+
261
+ time .sleep (10 )
262
+ except :
263
+ pass
264
+
265
+ attempts += 1
183
266
267
+ # Check that org was deleted
184
268
r = requests .get (f"{ API_PREFIX } /orgs" , headers = admin_auth_headers )
185
269
data = r .json ()
186
270
for org in data ["items" ]:
0 commit comments