# coding: utf-8

from decouple import config
from findaconf.tests.fake_data import fake_conference, seed


def set_app(app, db=False):
    unset_app(db)
    app.config['TESTING'] = True
    app.config['WTF_CSRF_ENABLED'] = False
    if db:
        app.config['SQLALCHEMY_DATABASE_URI'] = config(
            'DATABASE_URL_TEST',
            default='sqlite:///' + app.config['BASEDIR'].child('findaconf',
                                                               'tests',
                                                               'tests.db')
        )
    test_app = app.test_client()
    if db:
        db.create_all()
        seed(app, db)
        [db.session.add(fake_conference(db)) for i in range(1, 43)]
        db.session.commit()
    return test_app


def unset_app(db=False):
    if db:
        db.session.remove()
        db.drop_all()

@@ -136,21 +136,28 @@
     
-unset_app(db)
+%0A    # set test vars
 %0A   
@@ -229,16 +229,39 @@
 = False%0A
+    %0A    # set test db%0A
     if d
@@ -585,16 +585,43 @@
       )%0A
+    %0A    # create test app%0A
     test
@@ -645,30 +645,205 @@
 lient()%0A    
-if db:
+%0A    # create and feed db tables%0A    if db:%0A        %0A        # start from a clean db%0A        db.session.remove()%0A        db.drop_all()%0A        %0A        # create tables and feed them
 %0A        db.
@@ -969,24 +969,51 @@
 on.commit()%0A
+    %0A    # return test app%0A
     return t

Fix bug that used dev db instead of test db