def setUpClass(cls): """Initialize app and create test_client""" if 'APPUSERS_CONFIG' not in os.environ: os.environ['APPUSERS_CONFIG'] = 'test_config.py' cls.app = create_app() cls.client = cls.app.test_client() with cls.app.app_context(): # Clear existing data in test database meta = db.metadata for table in reversed(meta.sorted_tables): db.session.execute(table.delete()) db.session.commit() # Create user with admin privilege admin_user = User(username='******', firstname='Admin', lastname='User', email='*****@*****.**', phone='123-444-5555') admin_user.set_password('pass') admin_user.grant_admin() # Create other Users and Groups johne = User(username='******', firstname='John', lastname='Example', email='*****@*****.**', phone='123-444-6666') lindas = User(username='******', firstname='Linda', lastname='Sample', email='*****@*****.**', phone='123-444-7777') lindas.set_password('pass') lin = User(username='******', firstname='Li', lastname='Nerd', email='*****@*****.**', phone='123-444-8888') locked = User(username='******', firstname='Locked', lastname='Account', email='*****@*****.**', phone='123-444-9999') locked.set_password('pass') locked.set_lock() devs = Group(groupname='devs', description='Developers') testers = Group(groupname='testers', description='Testers')
os.environ['APPUSERS_CONFIG'] = 'test_config.py' app = create_app() with app.app_context(): # Clear existing data in test database meta = db.metadata for table in reversed(meta.sorted_tables): db.session.execute(table.delete()) db.session.commit() # Create user with admin privilege admin_user = User(username='******', firstname='Admin', lastname='User', email='*****@*****.**', phone='123-444-5555') admin_user.set_password('pass') admin_user.grant_admin() # End of module level set-up def login(client, username, password): """Login helper function User login with application test client. Arguments: client - Flask Test Client username - string with username password - string with password