successfully ported everything to a flesh shabti template. shortnames work now,...
[zzz-floof.git] / floof / 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.script.appinstall import SetupCommand
14 from pylons import config, url
15 from routes.util import URLGenerator
16 from webtest import TestApp
17
18 import pylons.test
19 from elixir import *
20 from floof.model import *
21 from floof.model import meta
22 from floof import model as model
23 from sqlalchemy import engine_from_config
24
25 __all__ = ['environ', 'url', 'TestController', 'TestModel']
26
27
28 # Invoke websetup with the current config file
29 # SetupCommand('setup-app').run([config['__file__']])
30
31 # additional imports ...
32 import os
33 from paste.deploy import appconfig
34 from floof.config.environment import load_environment
35
36 here_dir = os.path.dirname(__file__)
37 conf_dir = os.path.dirname(os.path.dirname(here_dir))
38
39 test_file = os.path.join(conf_dir, 'test.ini')
40 conf = appconfig('config:' + test_file)
41 load_environment(conf.global_conf, conf.local_conf)
42 environ = {}
43
44 engine = engine_from_config(config, 'sqlalchemy.')
45 model.init_model(engine)
46 metadata = elixir.metadata
47 Session = elixir.session = meta.Session
48
49 class Individual(Entity):
50 """Table 'Individual'.
51
52 >>> me = Individual('Groucho')
53
54 # 'name' field is converted to lowercase
55 >>> me.name
56 'groucho'
57 """
58 name = Field(String(20), unique=True)
59 favorite_color = Field(String(20))
60
61 def __init__(self, name, favorite_color=None):
62 self.name = str(name).lower()
63 self.favorite_color = favorite_color
64
65 setup_all()
66
67 def setup():
68 pass
69
70 def teardown():
71 pass
72
73 class TestModel(TestCase):
74 def setUp(self):
75 setup_all(True)
76
77 def tearDown(self):
78 drop_all(engine)
79
80
81 class TestController(TestCase):
82
83 def __init__(self, *args, **kwargs):
84 if pylons.test.pylonsapp:
85 wsgiapp = pylons.test.pylonsapp
86 else:
87 wsgiapp = loadapp('config:%s' % config['__file__'])
88 self.app = TestApp(wsgiapp)
89 url._push_object(URLGenerator(config['routes.map'], environ))
90 TestCase.__init__(self, *args, **kwargs)