def test_teardown_handler(self): from app import Visit @teardown_handler def handler(session, app, options): session.remove() # don't commit with self.kit.flasks[0].test_request_context('/'): session = get_session('db') visit = Visit(id=1) session.add(visit) del self.kit._teardown_handler
"""Basic kit example. This example implements a very simple page view tracker. It comprises of a single Flask view and SQLAlchemy table to store the visits to our view. """ from datetime import datetime from kit import Flask, get_session from sqlalchemy import Column, DateTime, Integer from sqlalchemy.ext.declarative import declarative_base app = Flask(__name__) session = get_session("db") # SQLAlchemy # ========== # # First, we use SQLAlchemy declarative to create the table where we will # keep track of the visits. This is very similar to what you can find in # the tutorial (http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html). Base = declarative_base() class Visit(Base): """Simple model to track visits.
"""Basic kit example. This example implements a very simple page view tracker. It comprises of a single Flask view and SQLAlchemy table to store the visits to our view. """ from datetime import datetime from kit import Flask, get_session from sqlalchemy import Column, DateTime, Integer from sqlalchemy.ext.declarative import declarative_base app = Flask(__name__) session = get_session('db') # SQLAlchemy # ========== # # First, we use SQLAlchemy declarative to create the table where we will # keep track of the visits. This is very similar to what you can find in # the tutorial (http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html). Base = declarative_base() class Visit(Base): """Simple model to track visits. Each visit contains an ``id`` and the date it was added to the database.
def test_session_integrity(self): from app import Visit with self.kit.flasks[0].test_request_context('/'): session = get_session('db') visit = Visit(id=1) session.add(visit)
def test_session_query(self): from app import Visit self.client.get('/') # make sure at least one visit session = get_session('db') visit = session.query(Visit).first() eq_(visit.id, 1)
def test_get_session_wrong_name(self): get_session('wrong_name')
def test_get_session(self): sessions = self.kit.sessions.values() eq_(len(sessions), 1) eq_(get_session('db'), sessions[0])