def init_db(): db.drop_all() db.create_all() # adding test user data hashed_pass1 = bcrypt.generate_password_hash('password') hashed_pass2 = bcrypt.generate_password_hash('testing') user = User(username='******', email='*****@*****.**', password=hashed_pass1) user1 = User(username='******', email='*****@*****.**', password=hashed_pass2) db.session.add(user) db.session.add(user1) db.session.commit() # adding testing project data project = Project(title='test', content='test', user_id=user.id, id=1) project1 = Project(title='test', content='test', user_id=user1.id, id=2) db.session.add(project) db.session.add(project1) db.session.commit() #adding test article data article = Article(title='test', content='test', user_id=user.id, id=1) article1 = Article(title='test', content='test', user_id=user1.id, id=2) db.session.add(article) db.session.add(article1) db.session.commit() #adding test comment data reply = Reply(content='test_comment', username=user.username, project_id=project.id) db.session.add(reply) db.session.commit() #adding test reply data tore = Tore(content='test_reply', username=user.username, reply_id=reply.id) db.session.add(tore) db.session.commit() # tests happen HERE! yield db db.drop_all()
def init_db(scope="session"): db.session.close() db.drop_all() db.create_all() # adding test user data hashed_pass1 = bcrypt.generate_password_hash("password").decode("utf-8") hashed_pass2 = bcrypt.generate_password_hash("testing").decode("utf-8") user = User(username="******", email="*****@*****.**", password=hashed_pass1) user1 = User(username="******", email="*****@*****.**", password=hashed_pass2) db.session.add(user) db.session.add(user1) db.session.commit() # adding testing project data project = Project(title="test", content="test", user_id=user.id) project1 = Project(title="test", content="test", user_id=user1.id) db.session.add(project) db.session.add(project1) db.session.commit() #adding test article data article = Article(title="test", content="test", user_id=user.id) article1 = Article(title="test", content="test", user_id=user1.id) db.session.add(article) db.session.add(article1) db.session.commit() #adding test comment data reply = Reply(content="test_comment",username=user.username, project_id=project.id) db.session.add(reply) db.session.commit() #adding test reply data tore = Tore(content="test_reply",username=user.username, reply_id=reply.id) db.session.add(tore) db.session.commit() # tests happen HERE! yield db db.session.close() db.drop_all()
def initdb(drop): ''' init the database ''' if drop: db.drop_all() db.create_all() click.echo("Initialized database")
def setup_method(self, method): db.drop_all() db.create_all()
def teardown_module(module): db.drop_all()
from myblog import db, bcrypt, testing_myblog, create_myblog import psycopg2 import sqlalchemy import os app = testing_myblog() with app.app_context(): db.drop_all() db.create_all() db.drop_all() # db.create_all() # engine = sqlalchemy.create_engine('postgresql://*****:*****@localhost:5432') # conn = engine.connect() # conn.execute("commit") # conn.execute(f"create database testing" ) # conn.close()