test_paste.py :  » Database » SQLObject » SQLObject-0.12.4 » sqlobject » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » SQLObject 
SQLObject » SQLObject 0.12.4 » sqlobject » tests » test_paste.py
from dbtest import *
from sqlobject import sqlhub,SQLObject,StringCol
try:
    from sqlobject.wsgi_middleware import make_middleware
except ImportError:
    disabled = True

class NameOnly(SQLObject):
    name = StringCol()

def makeapp(abort=False, begin=False, fail=False):
    def app(environ, start_response):
        NameOnly(name='app1')
        if fail == 'early':
            assert 0
        start_response('200 OK', [('content-type', 'text/plain')])
        if begin:
            environ['sqlobject.begin']()
        NameOnly(name='app2')
        if abort:
            environ['sqlobject.abort']()
        if fail:
            assert 0
        return ['ok']
    return app

def makestack(abort=False, begin=False, fail=False, **kw):
    app = makeapp(abort=abort, begin=begin, fail=fail)
    app = make_middleware(app, {}, database=getConnectionURI(), **kw)
    return app

def runapp(**kw):
    print '-'*8
    app = makestack(**kw)
    env = {}
    def start_response(*args):
        pass
    try:
        list(app(env, start_response))
        return True
    except AssertionError:
        return False

def setup():
    setupClass(NameOnly)
    getConnection().query('DELETE FROM name_only')
    NameOnly._connection = sqlhub

def names():
    names = [n.name for n in NameOnly.select(connection=getConnection())]
    names.sort()
    return names

def test_fail():
    setup()
    assert not runapp(fail=True, use_transaction=True)
    assert names() == []
    setup()
    assert not runapp(fail=True, use_transaction=False)
    assert names() == ['app1', 'app2']
    setup()
    assert not runapp(fail=True, begin=True, use_transaction=True)
    assert names() == ['app1']

def test_other():
    setup()
    assert runapp(fail=False, begin=True, use_transaction=True)
    assert names() == ['app1', 'app2']
    setup()
    # @@: Dammit, I can't get these to pass because I can't get the
    # stupid table to clear itself.  setupClass() sucks.  When I
    # fix it I'll take this disabling out:
    return
    assert names() == []
    assert runapp(fail=False, begin=True, abort=True, use_transaction=True)
    assert names() == ['app1']
    setup()
    assert runapp(use_transaction=True)
    assert names() == ['app1', 'app2']
    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.