def test_fellow_load_state(self): path = "db/" file_name = "mydb" file_ = file_name+".db" #clean up to avoid conflict between tests os.remove(path+file_) #clear memory stores self.clear_stores() #memory fellow1 = Fellow("osdflkjsd", "eksdlkfjk", "774881228", "Y") fellow1.register() Person.save_state(file_name) #clear memory stores self.clear_stores() #memory Person.load_state(file_name) fellow = Fellow.from_phone("774881228") #db engine = create_engine("sqlite:///"+path+file_, echo=False) Session = sessionmaker(bind=engine) session = Session() db_fellow = session.query(Person).filter_by(phonenumber="774881228").first() session.close() #compare full_fellow = [fellow.first_name, fellow.last_name, fellow.phone, fellow.type_, fellow.opt_in] full_db_fellow = [db_fellow.firstname, db_fellow.lastname, db_fellow.phonenumber, db_fellow.role, db_fellow.optin] self.assertEqual(full_db_fellow, full_fellow)
def get_person(phone): try: return Fellow.from_phone(phone) except ValueError: pass try: return Staff.from_phone(phone) except ValueError: raise ValueError("specifed phone is unknown")