Created
March 11, 2014 02:57
-
-
Save joshma/9478687 to your computer and use it in GitHub Desktop.
Flask-Testing appears to not remove session in between client requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask.ext.sqlalchemy import SQLAlchemy | |
from flask.ext.testing import TestCase | |
app = Flask(__name__) | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' | |
db = SQLAlchemy(app) | |
@app.route('/') | |
def index(): | |
u = db.session.query(User).first() | |
print u.name # Prints 'joe' the first time, 'bob' the second. | |
u.name = 'bob' | |
return '' | |
class User(db.Model): | |
id = db.Column(db.Integer, primary_key=True) | |
name = db.Column(db.String) | |
class SessionTest(TestCase): | |
def create_app(self): | |
return app | |
def test_remove(self): | |
db.drop_all() | |
db.create_all() | |
u = User() | |
u.name = 'joe' | |
db.session.add(u) | |
db.session.commit() | |
client = app.test_client() | |
client.get('/') | |
client.get('/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment