예제 #1
0
파일: conftest.py 프로젝트: tomhyhan/myblog
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()
예제 #2
0
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()
예제 #3
0
def initdb(drop):
    ''' init the database '''
    if drop:
        db.drop_all()
    db.create_all()
    click.echo("Initialized database")
예제 #4
0
 def setup_method(self, method):
     db.drop_all()
     db.create_all()
예제 #5
0
def teardown_module(module):
    db.drop_all()
예제 #6
0
 def setup_method(self, method):
     db.drop_all()
     db.create_all()
예제 #7
0
def teardown_module(module):
    db.drop_all()
예제 #8
0
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()