]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/tests/__init__.py
483da968296feaf5c8b83f082fa6989a5d14a06e
[bluechips.git] / bluechips / tests / __init__.py
1 """Pylons application test package
2
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`
5 command.
6
7 This module initializes the application via ``websetup`` (`paster
8 setup-app`) and provides the base testing objects.
9 """
10 from unittest import TestCase
11
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
17
18 from bluechips import model
19 from bluechips.model import meta
20
21 __all__ = ['url_for', 'TestController', 'sample_users']
22
23 sample_users = [u'Alice', u'Bob', u'Charlie', u'Dave', u'Eve']
24
25 def setUpPackage():
26     # Invoke websetup with the current config file
27     SetupCommand('setup-app').run([config['__file__']])
28     
29     test_user = model.User()
30     test_user.username = u'root'
31     test_user.name = u'Charlie Root'
32     test_user.resident = True
33     meta.Session.save(test_user)
34     meta.Session.commit()
35
36 def tearDownPackage():
37     meta.metadata.drop_all()
38
39 class TestController(TestCase):
40
41     def __init__(self, *args, **kwargs):
42         wsgiapp = loadapp('config:%s' % config['__file__'])
43         self.app = TestApp(wsgiapp)
44         TestCase.__init__(self, *args, **kwargs)