@@ -185,7 +185,7 @@ def test_create_and_cancel_booking():
185185 try :
186186 now = datetime .now (timezone .utc )
187187 booking_start = now + timedelta (seconds = 15 )
188- booking_finish = booking_start + timedelta (hours = 1 )
188+ booking_finish = booking_start + timedelta (seconds = 20 )
189189 booking_description = "my lovely booking"
190190
191191 session = client .create_session (
@@ -231,7 +231,7 @@ def test_create_and_cancel_booking():
231231
232232 print (booking .status )
233233
234- assert booking .status in ["cancelling" , "cancelled" ]
234+ assert booking .status in ["validated" , " cancelling" , "cancelled" ]
235235
236236 if booking .status == "cancelled" :
237237 break
@@ -240,18 +240,18 @@ def test_create_and_cancel_booking():
240240def test_create_overlaping_booking ():
241241 client = _get_client ()
242242
243- try :
244- platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
243+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
245244
246- assert len (platforms ) > 0
245+ assert len (platforms ) > 0
247246
248- target_platform = platforms [0 ]
247+ target_platform = platforms [0 ]
249248
250- now = datetime .now (timezone .utc )
251- booking_start = now + timedelta (days = 1 )
252- booking_finish = booking_start + timedelta (hours = 1 )
253- booking_description = "my overlaping booking"
249+ now = datetime .now (timezone .utc )
250+ booking_start = now + timedelta (days = 1 )
251+ booking_finish = booking_start + timedelta (hours = 1 )
252+ booking_description = "my overlaping booking"
254253
254+ try :
255255 session = client .create_session (
256256 platform_id = target_platform .id ,
257257 booking_demand_started_at = booking_start ,
@@ -260,143 +260,237 @@ def test_create_overlaping_booking():
260260 )
261261
262262 assert session == None
263- finally :
264- client . delete_session ( session . id )
263+ except Exception as e :
264+ assert "existing booking" in str ( e )
265265
266266
267267def test_create_too_long_booking ():
268268 client = _get_client ()
269269
270- try :
271- platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
270+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
272271
273- assert len (platforms ) > 0
272+ assert len (platforms ) > 0
274273
275- target_platform = platforms [0 ]
274+ target_platform = platforms [0 ]
276275
277- now = datetime .now (timezone .utc )
278- booking_start = now + timedelta (minutes = 1 )
279- booking_finish = booking_start + timedelta (hours = 10 )
280- booking_description = "my too long booking"
276+ now = datetime .now (timezone .utc )
277+ booking_start = now + timedelta (minutes = 1 )
278+ booking_finish = booking_start + timedelta (hours = 10 )
279+ booking_description = "my too long booking"
281280
282- session = client .create_session (
281+ try :
282+ _ = client .create_session (
283283 platform_id = target_platform .id ,
284284 booking_demand_started_at = booking_start ,
285285 booking_demand_finished_at = booking_finish ,
286286 booking_demand_description = booking_description ,
287287 )
288-
289- assert session == None
290- finally :
291- client .delete_session (session .id )
288+ except Exception as e :
289+ assert "max_duration not respected" in str (e )
292290
293291
294292def test_create_too_short_booking ():
295293 client = _get_client ()
296294
297- try :
298- platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
295+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
299296
300- assert len (platforms ) > 0
297+ assert len (platforms ) > 0
301298
302- target_platform = platforms [0 ]
299+ target_platform = platforms [0 ]
303300
304- now = datetime .now (timezone .utc )
305- booking_start = now + timedelta (minutes = 1 )
306- booking_finish = booking_start + timedelta (seconds = 10 )
307- booking_description = "my lovely booking"
301+ now = datetime .now (timezone .utc )
302+ booking_start = now + timedelta (minutes = 1 )
303+ booking_finish = booking_start + timedelta (seconds = 10 )
304+ booking_description = "my lovely booking"
308305
309- session = client .create_session (
306+ try :
307+ _ = client .create_session (
310308 platform_id = target_platform .id ,
311309 booking_demand_started_at = booking_start ,
312310 booking_demand_finished_at = booking_finish ,
313311 booking_demand_description = booking_description ,
314312 )
315-
316- assert session == None
317- finally :
318- client .delete_session (session .id )
313+ except Exception as e :
314+ assert "min_duration not respected" in str (e )
319315
320316
321- def test_create_too_short_booking ():
317+ def test_create_too_far_booking ():
322318 client = _get_client ()
323319
324- try :
325- platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
320+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
326321
327- assert len (platforms ) > 0
322+ assert len (platforms ) > 0
328323
329- target_platform = platforms [0 ]
324+ target_platform = platforms [0 ]
330325
331- now = datetime .now (timezone .utc )
332- booking_start = now + timedelta (minutes = 1 )
333- booking_finish = booking_start + timedelta (seconds = 10 )
334- booking_description = "my lovely booking"
326+ now = datetime .now (timezone .utc )
327+ booking_start = now + timedelta (days = 30 )
328+ booking_finish = booking_start + timedelta (hours = 2 )
329+ booking_description = "my lovely booking"
335330
336- session = client .create_session (
331+ try :
332+ _ = client .create_session (
337333 platform_id = target_platform .id ,
338334 booking_demand_started_at = booking_start ,
339335 booking_demand_finished_at = booking_finish ,
340336 booking_demand_description = booking_description ,
341337 )
338+ except Exception as e :
339+ assert "max_planification_duration not respected" in str (e )
342340
343- assert session == None
344- finally :
345- client .delete_session (session .id )
346341
347-
348- def test_create_too_far_booking ():
342+ def test_create_too_close_booking ():
349343 client = _get_client ()
350344
351- try :
352- platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
345+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
353346
354- assert len (platforms ) > 0
347+ assert len (platforms ) > 0
355348
356- target_platform = platforms [0 ]
349+ target_platform = platforms [0 ]
357350
358- now = datetime .now (timezone .utc )
359- booking_start = now + timedelta (days = 30 )
360- booking_finish = booking_start + timedelta (hours = 2 )
361- booking_description = "my lovely booking"
351+ now = datetime .now (timezone .utc )
352+ booking_start = now + timedelta (seconds = 10 )
353+ booking_finish = booking_start + timedelta (hours = 2 )
354+ booking_description = "my lovely booking"
362355
363- session = client .create_session (
356+ try :
357+ _ = client .create_session (
364358 platform_id = target_platform .id ,
365359 booking_demand_started_at = booking_start ,
366360 booking_demand_finished_at = booking_finish ,
367361 booking_demand_description = booking_description ,
368362 )
363+ except Exception as e :
364+ assert "min_planification_duration not respected" in str (e )
369365
370- assert session == None
371- finally :
372- client .delete_session (session .id )
373366
367+ def test_cannot_start_not_booked_session_during_booked_session_is_running ():
368+ client = _get_client ()
374369
375- def test_create_too_close_booking ():
370+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
371+
372+ assert len (platforms ) > 0
373+
374+ target_platform = platforms [0 ]
375+
376+ now = datetime .now (timezone .utc )
377+ booking_start = now + timedelta (seconds = 20 )
378+ booking_finish = booking_start + timedelta (seconds = 20 )
379+ booking_description = "my booking"
380+
381+ booked_session = client .create_session (
382+ platform_id = target_platform .id ,
383+ booking_demand_started_at = booking_start ,
384+ booking_demand_finished_at = booking_finish ,
385+ booking_demand_description = booking_description ,
386+ )
387+
388+ time .sleep (23 )
389+
390+ not_booked_session = client .create_session (
391+ platform_id = target_platform .id ,
392+ )
393+
394+ while True :
395+ time .sleep (2 )
396+ not_booked_session = client .get_session (session_id = not_booked_session .id )
397+
398+ booked_session = client .get_session (session_id = booked_session .id )
399+
400+ assert not_booked_session .status in ["starting" ]
401+ assert booked_session .status in ["starting" , "running" , "stopping" , "stopped" ]
402+
403+ if booked_session .status == "stopped" :
404+ break
405+
406+ while True :
407+ time .sleep (2 )
408+ not_booked_session = client .get_session (session_id = not_booked_session .id )
409+
410+ assert not_booked_session .status in ["starting" , "running" ]
411+
412+ if booked_session .status == "running" :
413+ break
414+
415+ client .delete_session (not_booked_session .id )
416+
417+
418+ def test_not_booked_session_is_killed_when_booked_session_starts ():
376419 client = _get_client ()
377420
421+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
422+
423+ assert len (platforms ) > 0
424+
425+ target_platform = platforms [0 ]
426+
378427 try :
379- platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
428+ not_booked_session_1 = client .create_session (
429+ platform_id = target_platform .id ,
430+ )
380431
381- assert len (platforms ) > 0
432+ assert not_booked_session_1
433+
434+ not_booked_session_2 = client .create_session (
435+ platform_id = target_platform .id ,
436+ )
382437
383- target_platform = platforms [ 0 ]
438+ assert not_booked_session_2
384439
385440 now = datetime .now (timezone .utc )
386- booking_start = now + timedelta (seconds = 10 )
387- booking_finish = booking_start + timedelta (hours = 2 )
388- booking_description = "my lovely booking"
441+ booking_start = now + timedelta (seconds = 20 )
442+ booking_finish = booking_start + timedelta (seconds = 20 )
443+ booking_description = "my booking"
389444
390- session = client .create_session (
445+ booked_session = client .create_session (
391446 platform_id = target_platform .id ,
392447 booking_demand_started_at = booking_start ,
393448 booking_demand_finished_at = booking_finish ,
394449 booking_demand_description = booking_description ,
395450 )
396451
397- assert session == None
452+ while True :
453+ time .sleep (2 )
454+ not_booked_session_1 = client .get_session (
455+ session_id = not_booked_session_1 .id
456+ )
457+ not_booked_session_2 = client .get_session (
458+ session_id = not_booked_session_2 .id
459+ )
460+
461+ assert not_booked_session_1 .status in ["starting" , "running" ]
462+ assert not_booked_session_2 .status in ["starting" , "running" ]
463+
464+ if (
465+ not_booked_session_1 .status == "running"
466+ and not_booked_session_2 .status == "running"
467+ ):
468+ break
469+
470+ time .sleep (25 )
471+
472+ while True :
473+ time .sleep (2 )
474+ not_booked_session_1 = client .get_session (
475+ session_id = not_booked_session_1 .id
476+ )
477+ not_booked_session_2 = client .get_session (
478+ session_id = not_booked_session_2 .id
479+ )
480+
481+ assert not_booked_session_1 .status in ["running" , "stopping" , "stopped" ]
482+ assert not_booked_session_2 .status in ["running" , "stopping" , "stopped" ]
483+
484+ if (
485+ not_booked_session_1 .status == "stopped"
486+ and not_booked_session_2 .status == "stopped"
487+ ):
488+ break
489+
398490 finally :
399- client .delete_session (session .id )
491+ client .delete_session (not_booked_session_1 .id )
492+ client .delete_session (not_booked_session_2 .id )
493+ client .delete_session (booked_session .id )
400494
401495
402496# def test_create_session_same_deduplication_id():
0 commit comments