def setUp(self): app.config.from_object('tests.config') self.app = app.test_client() db.session.close() db.drop_all( ) # http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/basic_use.html db.create_all() seed_core(db) db.session.commit() self.payload = { 'payload': json.dumps({ 'salary': 50000, 'email': '*****@*****.**', 'years_experience': 1, 'years_with_current_employer': 1, 'number_of_employers': 1, 'employment_type': EmploymentType.query.first().id, 'location': EmploymentType.query.first().id, 'education': EmploymentType.query.first().id, 'perks': [], 'roles': [{ 'id': Tech.query.first().id }], 'techs': [{ 'name': 'Not already in DB' }], 'verification_request': { 'profile_url': 'https://www.linkedin.com/in/test', 'employer_name': 'Test Company', 'note': 'Test note' } }) }
def resetdatabase(): st = "using config settings: {}".format( os.getenv('FLASK_CONFIG') or 'default') click.echo(st) db.drop_all() db.create_all() click.echo("database was reset")
def drop_db(): """After get address /drop-all DB will be erased from data""" if request.method == 'GET': db.drop_all() db.create_all() flash('DB successfully dropped', "success") return redirect(url_for('index'))
def db_init(): """Initialize the database.""" db.drop_all() db.create_all() db.session.commit() print("Database was successfully initialized...") return None
def db_init(): """Initialize the database.""" db.drop_all() db.create_all() db.session.commit() print("Successfully (re)created all databases...") return None
def client(): """ 返回 flask client """ from src.config.config import chaos_db, redis_url, log_db if ("sqlite" not in chaos_db or "127.0.0.1" not in redis_url or "sqlite" not in log_db): raise Exception("单元测试请配置环境变量") from src.main import app app.config.update({ "SQLALCHEMY_POOL_SIZE": None, "SQLALCHEMY_POOL_TIMEOUT": None }) from src import db app.config["TESTING"] = True app.config["SERVER_NAME"] = "127.0.0.1:5000" ctx = app.app_context() ctx.push() db.create_all() yield app.test_client() db.session.remove() db.drop_all() ctx.pop()
def db(app, request): """ Returns function initialized database so db is cleared after each test. """ with app.app_context(): _db.drop_all() _db.create_all()
def test_database(): db.create_all() yield db # testing happens here # remove db after testing is done db.session.remove() db.drop_all()
def client(): c = app.test_client() with app.app_context(): db.create_all() yield c db.session.close() db.drop_all()
def auth_client(): c = app.test_client() with app.app_context(): db.create_all() c.token = os.getenv("TEST_TOKEN") yield c db.session.close() db.drop_all()
def fake_data(): with app.app_context(): db.drop_all() db.create_all() fakeUser() fakeCourse() fakeRecord()
def setUp(self): app.config["TESTING"] = True app.config["WTF_CSRF_ENABLED"] = False app.config["DEBUG"] = False app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + TEST_DB self.app = app.test_client() db.drop_all() db.create_all()
def setUp(self) -> None: app.config['TESTING'] = True app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' self.app = app.test_client() db.drop_all() db.create_all()
def test(): with app.app_context(): db.reflect() db.drop_all() db.create_all() os.system("pytest -x")
def tearDown(cls): db.session.remove() db.drop_all() cls.app_context.pop() try: os.remove('../testdb.db') except Exception as e: print(e) print("Test db unable to be deleted, please delete manually.")
def test_database(): # Before test, firstly prepare database. db.create_all() print("[fixture] In test_database(), before yield") yield db # testing happens here print("[fixture] In test_database(), after yield") db.session.remove() # After test, finally close the database. db.drop_all()
def test_admin_command(self): db.drop_all() db.create_all() result = self.runner.invoke( args=['admin', '--username', 'bzh', '--password', '123456']) self.assertIn('Creating user ...', result.output) self.assertIn('Done!', result.output) self.assertEqual(User.query.count(), 1) self.assertEqual(User.query.first().username, 'bzh') self.assertTrue(User.query.first().validate_password('123456'))
def regenerate_all(): # reset database db.drop_all() db.create_all() add_roles() add_users() add_projects() add_issues() add_messages() add_comments()
def database(test_app, request): """Test database to perform all ops on, cleaned after tests have been finished""" # create all tables db.create_all() return db # tear down all tables db.drop_all()
def app(): """Creates a new app instance.""" app = create_app(config_class=Testing) with app.app_context(): db.create_all() yield app with app.app_context(): db.session.remove() db.drop_all()
def setUp(self): app.config.from_object('tests.config') db.session.close() db.drop_all( ) # http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/basic_use.html db.create_all() self.perks = [ Perk('Yearly Bonus', listed=True), Perk('Food / Drinks', listed=True) ] for perk in self.perks: db.session.add(perk) self.locations = [ Location('London, Ontario'), Location('Near London, Ontario') ] for location in self.locations: db.session.add(location) self.employment_types = [ EmploymentType('Full-Time'), EmploymentType('Part-Time'), EmploymentType('Independent Contractor') ] for employment_type in self.employment_types: db.session.add(employment_type) self.roles = [ Role('Web: Backend', listed=True), Role('Web: Frontend', listed=True), Role('Web: Full-Stack', listed=True) ] for role in self.roles: db.session.add(role) self.education_levels = [ Education('High School'), Education('College / University') ] for education_level in self.education_levels: db.session.add(education_level) self.techs = [ Tech('Python', listed=True), Tech('PHP', listed=True), Tech('Java', listed=True) ] for tech in self.techs: db.session.add(tech) db.session.commit()
def api(request): api = build_api() with api.app_context(): if not request.config.getoption("--nodb"): print("\n\033[35mDROPPING DATABASE AND RESEED\033[0m\n") db.drop_all() db.create_all() seed_db_data() else: print("\n\033[33mDatabase Not Dropped\033[0m\n") yield api db.session.remove()
def database(): # initiate database db.create_all() # commit changes db.session.commit() # tests happen here yield db # teardown db.session.remove() db.drop_all()
def db(app): """ Setup the database, this gets executed for every function :param app: Pytest fixture :return: SQLAlchemy database session """ _db.drop_all() _db.create_all() _db.session.commit() add_user(name='admin', username='******', email='*****@*****.**') return _db
def test_admin_view_dev(): os.environ["FLASK_ENV"] = "development" assert os.getenv("FLASK_ENV") == "development" app = create_app() app.config.from_object("src.config.TestingConfig") with app.app_context(): db.session.remove() db.drop_all() db.create_all() client = app.test_client() resp = client.get("/admin/user/") assert resp.status_code == 200 assert os.getenv("FLASK_ENV") == "development"
def setUpHelper(self): """Configure test app and upload sample data""" app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost/malb-test' self.app = app.test_client() self.TEST_USERNAME = TEST_USERNAME self.TEST_MALKEY = TEST_MALKEY self.TEST_MAL = TEST_MAL db.drop_all() db.create_all() MALB.synchronize_with_mal('quetzalcoatl384', 'cXVldHphbGNvYXRsMzg0OnBhc3N3b3Jk', 4448103) MALB.upload_aa_data('../data/aaresults0.txt')
def db_init(): """Initialize the database.""" db.drop_all() db.create_all() db.session.commit() set_model_perms(User) set_model_perms(Profile, ['edit', 'view']) set_model_perms(Group) set_model_perms(grp_members, is_table=True) set_model_perms(grp_perms, is_table=True) set_model_perms(user_perms, is_table=True) print("Database was successfully initialized...") return None
def create_db(): db.drop_all() db.create_all() source = Source('wikidich', 'https://wikidich.com/') category = Category('Tiên hiệp') author = Author('Ngô Thiên') book = Book('Ngã Thị Phong Thiên') chapter = Chapter(1, 'lời giới thiệu', 'this is content') # append relation book.chapters.append(chapter) book.categories.append(category) book.authors.append(author) source.books.append(book) db.session.add_all([book, chapter, category, author, source]) db.session.commit()
def authenticated_client(): c = app.test_client() with app.app_context(): db.create_all() res = c.post( '/api/register', data={ 'email': '*****@*****.**', 'password': '******', }, headers={ 'content-type': 'application/x-www-form-urlencoded' }) c.access_token = json.loads(res.data.decode()).get('access_token') yield c db.session.close() db.drop_all()
def recreate_db(): db.drop_all() db.create_all() db.session.commit()
def tearDown(self): """Remove all test data""" db.session.remove() db.drop_all()
def tearDown(self): db.session.remove() db.drop_all() # delete or reset db tables
from src import db from src import models db.drop_all() db.create_all() u = models.User('lee','123456') a = ''' ======================================== Every beauty start with ugly ======================================== Zero ---- Here, we start ''' b = models.Article(a) db.session.add(b) db.session.add(u) db.session.commit()
def tearDown(self): db.session.remove() db.drop_all()