Exemple #1
0
 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)
Exemple #2
0
def load_state(file_name="default"):
    file_name = str(file_name)
    path = "db/"
    file_ = file_name + ".db"
    try:
        if os.path.isfile(path + file_):
            Person.load_state(file_name)
            LivingSpace.load_state(file_name)
            Office.load_state(file_name)
            Allocation.load_state(file_name)
            print_pretty(
                "The current state of the application has successfully been loaded from the file: %s under the directory db."
                % file_)
        else:
            raise Exception(
                "The specified db file (%s) does not exist under the db directory."
                % 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))