@@ -172,26 +172,27 @@ def _get_client() -> QaaSClient:
172172
173173# assert len(bookings) > 0
174174
175+
175176def test_create_and_cancel_booking ():
176177 client = _get_client ()
177178
178- try :
179- platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
179+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
180180
181- assert len (platforms ) > 0
181+ assert len (platforms ) > 0
182182
183- target_platform = platforms [0 ]
183+ target_platform = platforms [0 ]
184184
185+ try :
185186 now = datetime .now (timezone .utc )
186- booking_start = now + timedelta (days = 7 )
187+ booking_start = now + timedelta (seconds = 15 )
187188 booking_finish = booking_start + timedelta (hours = 1 )
188189 booking_description = "my lovely booking"
189190
190191 session = client .create_session (
191192 platform_id = target_platform .id ,
192193 booking_demand_started_at = booking_start ,
193194 booking_demand_finished_at = booking_finish ,
194- booking_demand_description = booking_description
195+ booking_demand_description = booking_description ,
195196 )
196197
197198 assert session is not None
@@ -210,9 +211,12 @@ def test_create_and_cancel_booking():
210211
211212 while True :
212213 time .sleep (2 )
214+ session = client .get_session (session_id = session .id )
213215 booking = client .get_booking (booking_id = session .booking_id )
214216
215- assert booking .status in ["starting" , "running" ]
217+ print (session .status , booking .status )
218+
219+ assert session .status in ["starting" , "running" ]
216220 assert booking .status in ["waiting" , "validating" , "validated" ]
217221
218222 if booking .status == "validated" :
@@ -225,12 +229,176 @@ def test_create_and_cancel_booking():
225229 time .sleep (2 )
226230 booking = client .get_booking (booking_id = session .booking_id )
227231
228- assert booking .status in ["running" , "stopping" , "stopped" ]
232+ print (booking .status )
233+
229234 assert booking .status in ["cancelling" , "cancelled" ]
230235
231236 if booking .status == "cancelled" :
232237 break
233238
239+
240+ def test_create_overlaping_booking ():
241+ client = _get_client ()
242+
243+ try :
244+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
245+
246+ assert len (platforms ) > 0
247+
248+ target_platform = platforms [0 ]
249+
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"
254+
255+ session = client .create_session (
256+ platform_id = target_platform .id ,
257+ booking_demand_started_at = booking_start ,
258+ booking_demand_finished_at = booking_finish ,
259+ booking_demand_description = booking_description ,
260+ )
261+
262+ assert session == None
263+ finally :
264+ client .delete_session (session .id )
265+
266+
267+ def test_create_too_long_booking ():
268+ client = _get_client ()
269+
270+ try :
271+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
272+
273+ assert len (platforms ) > 0
274+
275+ target_platform = platforms [0 ]
276+
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"
281+
282+ session = client .create_session (
283+ platform_id = target_platform .id ,
284+ booking_demand_started_at = booking_start ,
285+ booking_demand_finished_at = booking_finish ,
286+ booking_demand_description = booking_description ,
287+ )
288+
289+ assert session == None
290+ finally :
291+ client .delete_session (session .id )
292+
293+
294+ def test_create_too_short_booking ():
295+ client = _get_client ()
296+
297+ try :
298+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
299+
300+ assert len (platforms ) > 0
301+
302+ target_platform = platforms [0 ]
303+
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"
308+
309+ session = client .create_session (
310+ platform_id = target_platform .id ,
311+ booking_demand_started_at = booking_start ,
312+ booking_demand_finished_at = booking_finish ,
313+ booking_demand_description = booking_description ,
314+ )
315+
316+ assert session == None
317+ finally :
318+ client .delete_session (session .id )
319+
320+
321+ def test_create_too_short_booking ():
322+ client = _get_client ()
323+
324+ try :
325+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
326+
327+ assert len (platforms ) > 0
328+
329+ target_platform = platforms [0 ]
330+
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"
335+
336+ session = client .create_session (
337+ platform_id = target_platform .id ,
338+ booking_demand_started_at = booking_start ,
339+ booking_demand_finished_at = booking_finish ,
340+ booking_demand_description = booking_description ,
341+ )
342+
343+ assert session == None
344+ finally :
345+ client .delete_session (session .id )
346+
347+
348+ def test_create_too_far_booking ():
349+ client = _get_client ()
350+
351+ try :
352+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
353+
354+ assert len (platforms ) > 0
355+
356+ target_platform = platforms [0 ]
357+
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"
362+
363+ session = client .create_session (
364+ platform_id = target_platform .id ,
365+ booking_demand_started_at = booking_start ,
366+ booking_demand_finished_at = booking_finish ,
367+ booking_demand_description = booking_description ,
368+ )
369+
370+ assert session == None
371+ finally :
372+ client .delete_session (session .id )
373+
374+
375+ def test_create_too_close_booking ():
376+ client = _get_client ()
377+
378+ try :
379+ platforms = client .list_platforms (name = _TEST_PLATFORM_NAME )
380+
381+ assert len (platforms ) > 0
382+
383+ target_platform = platforms [0 ]
384+
385+ 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"
389+
390+ session = client .create_session (
391+ platform_id = target_platform .id ,
392+ booking_demand_started_at = booking_start ,
393+ booking_demand_finished_at = booking_finish ,
394+ booking_demand_description = booking_description ,
395+ )
396+
397+ assert session == None
398+ finally :
399+ client .delete_session (session .id )
400+
401+
234402# def test_create_session_same_deduplication_id():
235403# client = _get_client()
236404
0 commit comments