def _change_application_auth(self, mode: str = None): self.app_context.pop() if mode is not None: self.app = create_test_app(AUTH_MODE=mode) else: self.app = create_test_app() self.app_context = self.app.app_context() self.app_context.push() self.client = self.app.test_client()
def setUp(self): self.app = create_test_app() self.app_context = self.app.app_context() self.app_context.push() self.client = self.app.test_client() self.maxDiff = None
def _pre_setup(self): self.app = create_test_app() self.client = self.app.test_client self.app_context = self.app.app_context() self.app_context.push() self.db = db db.create_all()
def setUp(self): self.app = create_test_app(TestingConfig) # Push an app context for the app instance just created # app_context (current_app) and request_context (current_user) self.app_context = self.app.app_context() self.app_context.push() self.client = self.app.test_client() db.create_all()
def setUp(self): #create app self.app = create_test_app() #init with app test1 db.init_app(self.app) #bind context self.app.app_context().push() #create instance for tests self.instance = Inventory(**{ "value" : "+55 86 90000-0000", "monthyPrice" : 15, "currency" : "R$", "setupPrice" : 25, }) self.instance.save()
def setUp(self): create_test_app() db.create_all()
import os import unittest from app import create_test_app app = create_test_app() # Support running integration tests @app.cli.command() def test(): """Run integration tests.""" tests = unittest.TestLoader().discover( os.path.join(os.path.dirname(__file__), "tests")) unittest.TextTestRunner(verbosity=2).run(tests) # Support PyCharm debugging if "PYCHARM_HOSTED" in os.environ: # Exempting Bandit security issue (binding to all network interfaces) # # All interfaces option used because the network available within the container can vary across providers # This is only used when debugging with PyCharm. A standalone web server is used in production. app.run(host="0.0.0.0", port=9000, debug=True, use_debugger=False, use_reloader=False) # nosec
def setUp(self): self.app = create_test_app() self.app_context = self.app.app_context() self.app_context.push() db.create_all()
def create_app(self): return create_test_app("testing")
def setUp(self): self.app = create_test_app() self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.client = self.app.test_client(use_cookies=True)
def setUp(self): self.app = create_test_app() self.client = self.app.test_client() db.init_app(self.app) db.create_all()
def create_app(self): global TESTS TESTS = 0 app = create_test_app() test_db.init_app(app) return app
def create_app(self): app = create_test_app() test_db.init_app(app) return app
class BaseCase(TestCase): ''' All tests should ultimately inherit from this BaseCase test case to ensure proper setup and teardown of the test case ''' dbpath = os.path.dirname(os.path.abspath(__file__)) + '/unittest.db' with open(dbpath, 'w') as f: pass app = create_test_app(dbpath) def setUp(self): with self.app.test_request_context(): db.create_all() def tearDown(self): if os.path.isfile(self.dbpath): os.remove(self.dbpath) def _add_to_db(self, obj): with self.app.test_request_context(): db.session.add(obj) db.session.commit() def add_role(self, name): role = Role(name=name) self._add_to_db(role) def add_std_user(self, username, password, email): user = User(username=username, password=password, email=email, image_file='') self._add_to_db(user) def add_admin_user(self, username, password, email): with self.app.test_request_context(): role_existance = Role.query.filter_by(name='admin').first() if not role_existance: self.add_role('admin') with self.app.test_request_context(): role_existance = Role.query.filter_by(name='admin').first() user = User(username=username, password=password, email=email, image_file='') self._add_to_db(user) with self.app.test_request_context(): user = User.query.filter_by(username=username).first() userRole = UserRoles(user_id=user.id, role_id=role_existance.id) self._add_to_db(userRole) def login_as_user_id(self, user_id): '''Makes the session authenticated as the first user in the db (admin)''' with self.app.test_client() as tester: with tester.session_transaction() as sess: sess['user_id'] = str(user_id) sess[ '_fresh'] = True # https://flask-login.readthedocs.org/en/latest/#fresh-logins return tester def generate_url(self, blueprint, **kwargs): '''Allows the user to generate urls using url_for''' with self.app.test_request_context(): if not kwargs: url = url_for(blueprint) return url else: url = url_for(blueprint, **kwargs) return url def anonymous_user(self): with self.app.test_client() as tester: return tester def get_flashed_messages(self, tester, type='danger'): with tester.session_transaction() as session: return dict(session['_flashes']).get(type) def add_base_users(self): self.add_role('admin') self.add_std_user('stduser', hash_password('pass'), '*****@*****.**') self.add_admin_user('adminuser', hash_password('pass'), '*****@*****.**') with self.app.test_request_context(): self.std_user = User.query.filter_by(username='******').first() self.admin_user = User.query.filter_by( username='******').first()
#using activated venv, so no shebang import os import unittest from app import create_test_app from models import User, Student, Group, Mentor, Session, SessionAction, Payment from flask.ext.sqlalchemy import SQLAlchemy app = create_test_app() db = SQLAlchemy(app) class TestCase(unittest.TestCase): def setUp(self): app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL'] app.config['WTF_CSRF_ENABLED'] = False self.app = app.test_client() db.create_all() def tearDown(self): db.session.remove() db.drop_all() def test_pop(self): u = User(username='******', email='*****@*****.**') db.session.add(u) db.session.commit() def test_parents_to_students(self): u1 = User(username='******', email='*****@*****.**') u2 = User(username='******',email='*****@*****.**')
def setUp(self): self.app, api = create_test_app() self.client = self.app.test_client() prepare_app(api)
def test_app(): app = create_test_app() app.include_router(user_router()) yield app # testing happens here