Skip to content

Instantly share code, notes, and snippets.

@octaflop
Created November 10, 2012 01:38
Show Gist options
  • Select an option

  • Save octaflop/4049431 to your computer and use it in GitHub Desktop.

Select an option

Save octaflop/4049431 to your computer and use it in GitHub Desktop.
Flask sqlalchemy declarative db configuration
import someapp as j
from someapp.db.database import init_db, drop_db
import unittest
import fixtures
from BeautifulSoup import BeautifulSoup as bs
appurl = "/api/%s"
header = { "content-type": "application/json" }
class JoyHikeDBCase(unittest.TestCase):
test_user1 = {
'username': 'wxillixxaxxmm3',
'email': 'wixlm3@soxxxuthpark.com',
'password': 'pxmwerxxxs3'
}
def create_app(self):
j.app.config['TESTING'] = True
from joyhikeserve.db.testdatabase import dburi as testdburi
from joyhikeserve.db.testdatabase import engine as testengine
self.dburi = testdburi
self.engine = testengine
j.app.config['DATABASE'] = self.dburi
j.app.config['SQLALCHEMY_DATABASE_URI'] = self.dburi
self.app = j.app.test_client()
def setUp(self):
self.create_app()
drop_db() # clear anything else in the db
init_db()
fixtures.install(self.engine, *fixtures.all_data)
from joyhikeserve.db.testdatabase import db_session as testsession
self.session = testsession
def tearDown(self):
drop_db()
self.session.remove()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment