def test_import_ddb_file(self): runner = app.test_cli_runner() result = runner.invoke(import_file, [os.path.dirname(__file__) + "/../custom_ddb.txt"]) self.assertEqual(result.exit_code, 0) device_infos = db.session.query(DeviceInfo).all() self.assertEqual(len(device_infos), 6)
def setUp(self): app.config.update(TESTING=True, WTF_CSRF_ENABLED=False, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:') db.create_all() self.client = app.test_client() self.runner = app.test_cli_runner()
def setUp(self): self.context = app.test_request_context() self.context.push() self.client = app.test_client() self.runner = app.test_cli_runner() db.drop_all() db.create_all() print('-' * 50) print('\n' * 5)
def setUp(self): app.config.update(TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:') self.context = app.test_request_context() self.context.push() self.client = app.test_client() self.runner = app.test_cli_runner() db.create_all()
def setUp(self): app.config.update(TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:') db.create_all() user = User(name='Test', username='******') user.set_password('123') movie = Movie(title='Test Movie Title', year='2019') db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client() # 创建测试客户端 self.runner = app.test_cli_runner() # 创建测试命令运行器
def setUp(self): # 更新配置 app.config.update( TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:') # 创建数据库和表 db.create_all() # 创建测试数据,一个用户,一个电影条目 user = User(name='Nicolas Xiong', username='******') user.set_password('19990909xzc') movie = Movie(title='Test Movie Title', year='2019') # 使用 add_all() 方法一次添加多个模型类实例,传入列表 db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client() # 创建测试客户端 self.runner = app.test_cli_runner() # 创建测试命令运行器
def setUp(self) -> None: # update config app.config.update(TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:') db.create_all() user = User(name='Test', account_name='admin_test') user.set_password('456') movie = Movie(title='Test Movie Title', year=2020) db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client() self.runner = app.test_cli_runner()
def setUp(self): app.config.update( TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:///:memory:' ) id = db.Column(db.Integer, primary_key=True) db.create_all() survey=Survey(customer="Customer", employee="Employee",rating=9, comments="Good") db.session.add_all([survey]) db.session.commit() self.client=app.test_client() self.runner=app.test_cli_runner()
def setUp(self) -> None: # 更新配置 app.config.update(TESTING=True, SQLALCHEMY_DATABSE_URI='sqlite:///:memory:') # 创建数据库和表 db.create_all() # 创建测试数据,一个用户,一个电影条目 user = User(name="Test", username='******') user.set_password('123') movie = Movie(title='Test Movie Title', year='2019') db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client() self.runner = app.test_cli_runner()
def setUp(self): # 更新配置 在开发和测试时候通常配置是不一样 app.config.update( TESTING=True, # 开启测试模式 出错时候不会输出多余的信息 SQLALCHEMY_DATABASE_URI= 'sqlite:///:memory:' # SQLite内存型数据库,不会干扰开发时使用的数据库文件 ) # 创建数据库和表 db.create_all() # 创建测试数据,一个用户,一个电影信息 user = User(name='Test', username='******') user.set_password('123456') movie = Movie(title='测试电影名称', year='2020') db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client() # 创建测试客户端(模拟客户端请求) self.runner = app.test_cli_runner() # 创建测试命令运行器(触发自定义命令)
def setUp(self): # 更新配置 app.config.update( # 測試時狀態TESTING打開可以過濾一些多餘的訊息 TESTING=True, # 改使用memory當作db做測試,不會用到開發時的db SQLALCHEMY_DATABASE_URI='sqlite:///:memory:') # 用來創建db和表 db.create_all() user = User(name='Test', username='******') user.set_password('123') movie = Movie(title='Test Movie Title', year='2019') db.session.add_all([user, movie]) db.session.commit() # 創建測試客服端,來模擬瀏覽器,如果調用get()相當於對server發送GET請求 self.client = app.test_client() self.runner = app.test_cli_runner() # 創建測試命令行
def setUp(self): # 更新配置 app.config.update( TESTING=True, # 首先将 TESTING 设为 True 来开启测试模式,这样在出错时不会输出多余信息. SQLALCHEMY_DATABASE_URI= 'sqlite:///:memory:' # 这会使用 SQLite 内存型数据库,不会干扰开发时使用的数据库文件,你也可以使用不同文件名的 SQLite 数据库文件,但内存型数据库速度更快。 ) # 创建数据库和表 db.create_all() # 创建测试数据,一个用户,一个电影条目 user = User(name='Test', username='******') user.set_password('123') movie = Book(title='Test Movie Title', year='2020') # 使用 add_all() 方法一次添加多个模型类实例,传入列表 db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client( ) # 创建测试客户端 返回一个测试客户端对象,可以用来模拟客户端(浏览器),我们创建类属性 self.client 来保存它。 # 对它调用 get() 方法就相当于浏览器向服务器发送 GET 请求,调用 post() 则相当于浏览器向服务器发送 POST 请求,以此类推。 self.runner = app.test_cli_runner() # 创建测试命令运行器
def test_command(self, db_session): # test testing command :) runner = app.test_cli_runner() result = runner.invoke(tst, ['app/test_app_cli.py']) assert result.exit_code == 0 # test initdb command # create superuser and seed data result = runner.invoke( initdb, ['', '-u', 'flask', '-e', '*****@*****.**', '-p', 'flask']) assert result.exit_code == 0 assert result.exception is None # check for users both super and anon superuser = User.query.first() assert User.query.count() == 2 assert User.query.get(-1).username == 'anon' assert superuser.username == 'flask' # duplicate superuser result = runner.invoke( initdb, ['-u', 'flask', '-e', '*****@*****.**', '-p', 'flask']) assert result.exit_code == 1
def setUp(self): # 更新配置 app.config.update( # 开启测试模式 TESTING=True, # 启用SQLite内存型数据库,不会干扰开发时使用的数据文件 SQLALCEHMY_DATABASE_URI='sqlite:///:memory:') # 创建数据库和表 db.create_all() # 创建测试数据:一个用户和一个电影条目 user = User(name='Test', username='******') user.set_password('123') movie = Movie(title='Test Movie Title', year='2019') # 使用add_all()方法一次添加多个模型实例 db.session.add_all([user, movie]) db.session.commit() # 创建测试客户端, 用来模拟客户端请求 self.client = app.test_client() # 创建测试命令运行器,用来触发自定义命令 self.runner = app.test_cli_runner()
def runner() -> FlaskCliRunner: """CLI runner for Flask.""" return app.test_cli_runner()
def runner(app): """A test runner for the app's Click commands.""" return app.test_cli_runner()
def setUp(self): app.config.update(TESTING=True) self.client = app.test_client() self.runner = app.test_cli_runner()
def runner(): #A test runner for the app's Click commands. return app.test_cli_runner()