Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
Arquivo: app.py Projeto: 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.
Exemplo n.º 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.
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 7
0
 def test_get_session_wrong_name(self):
   get_session('wrong_name')
Exemplo n.º 8
0
 def test_get_session(self):
   sessions = self.kit.sessions.values()
   eq_(len(sessions), 1)
   eq_(get_session('db'), sessions[0])
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 11
0
 def test_get_session_wrong_name(self):
     get_session('wrong_name')
Exemplo n.º 12
0
 def test_get_session(self):
     sessions = self.kit.sessions.values()
     eq_(len(sessions), 1)
     eq_(get_session('db'), sessions[0])