1 """Pylons application test package
3 This package assumes the Pylons environment is already loaded, such as
4 when this script is imported from the `nosetests --with-pylons=test.ini`
7 This module initializes the application via ``websetup`` (`paster
8 setup-app`) and provides the base testing objects.
10 from unittest import TestCase
12 from paste.deploy import loadapp
13 from paste.fixture import TestApp
14 from paste.script.appinstall import SetupCommand
15 from pylons import config
16 from routes import url_for
18 import bluechips.model
19 from bluechips.model import meta
20 from bluechips.model.types import Currency
24 __all__ = ['url_for', 'TestController',
25 'createUsers', 'createExpenditures',
26 'deleteUsers', 'deleteExpenditures']
28 sample_users = [u'Alice', u'Bob', u'Charlie', u'Dave', u'Eve']
31 # Invoke websetup with the current config file
32 SetupCommand('setup-app').run([config['__file__']])
34 u1 = bluechips.model.User(u'root', u'Charlie Root', True)
35 u1.email = u'charlie@example.com'
36 u1.password = u'charliepass'
37 u2 = bluechips.model.User(u'ben', u'Ben Bitdiddle', True)
38 u3 = bluechips.model.User(u'gotta', u'Gotta Lisp', True)
39 u4 = bluechips.model.User(u'rich', u'Rich Scheme', True)
41 for u in (u1, u2, u3, u4):
45 def tearDownPackage():
46 meta.metadata.drop_all()
48 class TestController(TestCase):
50 def __init__(self, *args, **kwargs):
51 wsgiapp = loadapp('config:%s' % config['__file__'])
52 self.app = TestApp(wsgiapp)
53 TestCase.__init__(self, *args, **kwargs)
55 def createUsers(n=None):
57 n = random.randint(2, 5)
59 u = bluechips.model.User(sample_users[i].lower(), resident=True)
63 def createExpenditures(n=None):
65 n = random.randint(5, 20)
66 users = meta.Session.query(bluechips.model.User).all()
68 e = bluechips.model.Expenditure(random.choice(users),
69 Currency(random.randint(1000, 100000)))
75 map(meta.Session.delete, meta.Session.query(bluechips.model.User))
77 def deleteExpenditures():
78 map(meta.Session.delete, meta.Session.query(bluechips.model.Expenditure))