Peewee Flask Test API在内存中

时间:2016-10-08 13:39:17

标签: python sqlite peewee flask-peewee flask-testing

我想在内存中使用Flask + Werkzeug + SQLite测试我的应用程序API。

使用应用程序工厂模式配置应用程序,如下所示:

def create_app(config_name):

    application = Flask(__name__)
    application.config.from_object(config_name)


    db = FlaskDB(application)
    database.initialize(db.database)
    db.database.commit()
    register_admin_blueprints(application)
    *****

    return application

在测试中我使用:

   def setUp(self):
      app = create_app('config.test')
      self.app = app.test_client()
      self.app.testing = True
      self.headers = [('Content-Type', 'application/json')]


   def test_should_be_possible_list_all_areas(self):
      response = self.app.get('/api/1/area')
      response_json = json.loads(response.data.decode('utf-8'))
      ###

在' config.test ' file有变量DATABASE。

在*****中我在数据库中注册数据

并在###中断言我的测试。

当我使用 DATABASE =' sqlite:///test.db' 工作正常,但更改为DATABASE =' sqlite:// /:记忆:' 我收到错误。

解决这个问题的任何想法?

韩国社交协会

0 个答案:

没有答案
相关问题