示例#1
0
 def tearDown(self):
     """该方法会在测试代码执行完后执行,相当于做测试后的扫尾工作"""
     # # 清除记录的测试任务
     db.session.remove()
     # # 清除数据库数据
     db.drop_all()
     self.app_context.pop()
示例#2
0
 def setUp(self):
     """该方法会首先执行,相当于做测试前的准备工作,一般初始化数据使用"""
     self.app = create_app()
     # 使用flask提供的测试客户端进行测试,flask自带测试客户端,直接模拟终端请求
     self.client = self.app.test_client()
     # 开启测试模式
     self.app.debug = True
     # # 对应修改成自己测试数据库
     self.app.config["SQLALCHEMY_DATABASE_URI"] = DB_PATH
     # 先清空并创建表
     self.app_context = self.app.app_context()
     self.app_context.push()
     # 清空表
     db.drop_all()
     # 创建表
     db.create_all()
示例#3
0
文件: manage.py 项目: wdpedwin/testaa
def drop_database():
    db.drop_all()
    return "删除库中所有模型类对应的表"
示例#4
0
from models.user import db, User
from models.quiz import Quiz, Question
from add_questions import add_questions

# set an environmental variable to use a different database for tests

os.environ['DATABASE_URL'] = "postgresql:///plant_quizzes_test"

# import app

from app import app

# Create tables once for all tests --- in each test, we'll delete the data
# and create fresh new clean test data

db.drop_all()
db.create_all()


class QuizModelTestCase(TestCase):
    """Test quiz model."""
    def setUp(self):
        """Clear any errors, clear tables, add test quizzes, create test client."""

        db.session.rollback()
        User.query.delete()
        Quiz.query.delete()
        Question.query.delete()

        add_questions('test/test_quiz_questions.csv', 'test family')
示例#5
0
def drop_databases():
    db.drop_all()
    return '删除数据库中的所有模型表成功'
示例#6
0
def drop_database():
    db.drop_all()
    return "drop数据库中的所有模型表成功"
示例#7
0
 def setUp(self):
     db.drop_all()
     db.create_all()