1515#
1616@pytest .fixture ()
1717def init_user_database ():
18+ if configuration .ENV != "DEV" :
19+ raise Exception ("You must set the environnement to DEV to run the tests" )
1820 app = util .create_app ()
1921 db = SQLAlchemy ()
2022 db .init_app (app .app )
@@ -25,6 +27,8 @@ def init_user_database():
2527 db .create_all ()
2628 # List of test users
2729 test_users = [
30+ {"id" : "user-1" , "freezeState" : "0.0" , "lastNotificationDate" : None },
31+ {"id" : "user-2" , "freezeState" : "0.0" , "lastNotificationDate" : None },
2832 {"id" : "valid-user" , "freezeState" : "0.0" , "lastNotificationDate" : None },
2933 {"id" : "expired-user-1" , "freezeState" : "1.0" , "lastNotificationDate" : None },
3034 {"id" : "expired-user-2" , "freezeState" : "2.0" , "lastNotificationDate" : None },
@@ -59,18 +63,18 @@ def create_post_model(user):
5963
6064@pytest .fixture ()
6165def init_vm_database ():
66+ if configuration .ENV != "DEV" :
67+ raise Exception ("You must set the environnement to DEV to run the tests" )
6268 app = util .create_app ()
6369 db = SQLAlchemy ()
6470 db .init_app (app .app )
6571 with app .app .app_context ():
66- db .session .query (model .Vm ).delete ()
67- db .session .query (model .User ).delete ()
72+ try :
73+ db .session .query (model .Vm ).delete ()
74+ except :
75+ print ("No VM to delete" )
6876 db .create_all ()
69- # List of test users
70- test_users = [
71- {"id" : "user-1" , "freezeState" : "0.0" , "lastNotificationDate" : None },
72- {"id" : "user-2" , "freezeState" : "0.0" , "lastNotificationDate" : None },
73- ]
77+
7478 # List of test VM
7579 test_vms = [
7680 {"id" : 1 , "userId" : "user-1" , "type" :"bare" , "ip" : None , "mac" : None ,"needToBeRestored" : False },
@@ -88,12 +92,9 @@ def create_vm_model(vms):
8892 return model .Vm (** vms )
8993
9094 # Create a list of objects
91- mapped_users = map (create_user_model , test_users )
92- t_users = list (mapped_users )
9395 mapped_vms = map (create_vm_model , test_vms )
9496 t_vms = list (mapped_vms )
9597
96- db .session .add_all (t_users )
9798 db .session .add_all (t_vms )
9899
99100 # Commit the changes for the users
0 commit comments