def test_livingspace_load_state(self): path = "db/" file_name = "mydb" file_ = file_name+".db" #clean up to avoid conflict between tests os.remove(path+file_) self.clear_stores() #memory livingspace1 = LivingSpace('oju5nf89') LivingSpace.add(livingspace1) LivingSpace.save_state(file_name) #db engine = create_engine("sqlite:///"+path+file_, echo=False) Session = sessionmaker(bind=engine) session = Session() db_livingspace = session.query(Room).filter_by(roomname='oju5nf89'.upper()).first() #clear memory stores self.clear_stores() #memory LivingSpace.load_state(file_name) livingspace = LivingSpace.from_name('oju5nf89') #compare full_livingspace = [livingspace.name, livingspace.capacity, livingspace.type_] full_db_livingspace = [db_livingspace.roomname, db_livingspace.roomcapacity, db_livingspace.roomtype] session.close() self.assertEqual(full_db_livingspace, full_livingspace)
def save_state(file_name="default"): file_name = str(file_name) path = "db/" file_ = file_name + ".db" try: if os.path.isfile(path + file_): os.remove(path + file_) Person.save_state(file_name) LivingSpace.save_state(file_name) Office.save_state(file_name) Allocation.save_state(file_name) print_pretty( "The current state of the application has successfully been saved in the db directory under the file: %s." % file_) except exc.DBAPIError: print_pretty( str("There is currently a problem with the specified file please try a different one." )) except Exception as e: print_pretty(str(e))