0

I want to test my application API using Flask + Werkzeug + SQLite in memory.

The application was configured using application factory pattern, like this:

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

And in the test I use:

   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'))
      ###

In 'config.test' file has the variable DATABASE.

In ***** I register data in the DB

and in ### I assert my test.

When I use DATABASE = 'sqlite:///test.db' works fine, but when change to DATABASE = 'sqlite:///:memory:' I get error.

Any ideias to solve this problem?

Tks.

Rangel
  • 11
  • 2
  • What is the error that you get? – dkasak Oct 08 '16 at 14:03
  • File "/Users/Rangel-Torrezan/.virtualenvs/flask-celery/lib/python2.7/site-packages/peewee.py", line 3331, in execute_sql cursor.execute(sql, params or ()) OperationalError: no such table: area It seems to be the time when try create the tables. – Rangel Oct 11 '16 at 01:21
  • I solved this problem changed FlaskDB wrapper to use connect() method. database = connect('sqlite:///:memory:'). Its necessary use a explicit wrapper. http://docs.peewee-orm.com/en/latest/peewee/database.html#flask – Rangel Oct 22 '16 at 12:51
  • you could write it as an answer to your own question and then accept it, if you have the time. – dkasak Oct 22 '16 at 14:02

0 Answers0