Example #1
0
  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
Example #2
0
    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
Example #3
0
File: app.py Project: mtth/kit
"""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.
Example #4
0
"""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.
Example #5
0
 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)
Example #6
0
 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)
Example #7
0
 def test_get_session_wrong_name(self):
   get_session('wrong_name')
Example #8
0
 def test_get_session(self):
   sessions = self.kit.sessions.values()
   eq_(len(sessions), 1)
   eq_(get_session('db'), sessions[0])
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 def test_get_session_wrong_name(self):
     get_session('wrong_name')
Example #12
0
 def test_get_session(self):
     sessions = self.kit.sessions.values()
     eq_(len(sessions), 1)
     eq_(get_session('db'), sessions[0])