def test_office_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 office1 = Office('ooskks9') Office.add(office1) Office.save_state(file_name) #db engine = create_engine("sqlite:///" + path + file_, echo=False) Session = sessionmaker(bind=engine) session = Session() db_office = session.query(Room).filter_by( roomname='ooskks9'.upper()).first() #clear memory stores self.clear_stores() #memory Office.load_state(file_name) office = Office.from_name('ooskks9') #compare full_office = [office.name, office.capacity, office.type_] full_db_office = [ db_office.roomname, db_office.roomcapacity, db_office.roomtype ] session.close() self.assertEqual(full_db_office, full_office)
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))