didip (owner)

Revisions

gist: 125670 Download_button fork
public
Description:
My Default tests/__init__.py
Public Clone URL: git://gist.github.com/125670.git
Embed All Files: show embed
tests/__init__py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from unittest import TestCase
from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from pylons import config, url
from routes.util import URLGenerator
from webtest import TestApp
import pylons.test
 
import sys, os.path
ROOT_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
TEST_INI = os.path.join(ROOT_PATH, 'test.ini')
sys.path.append(ROOT_PATH)
 
from project.config.environment import load_sql_engine
 
__all__ = ['environ', 'url', 'TestController', 'TestModel']
 
# Invoke websetup with the current config file
SetupCommand('setup-app').run([config.get('__file__', TEST_INI)])
 
environ = {}
 
class TestController(TestCase):
 
  def __init__(self, *args, **kwargs):
    if pylons.test.pylonsapp:
      wsgiapp = pylons.test.pylonsapp
    else:
      wsgiapp = loadapp('config:%s' % config['__file__'])
    self.app = TestApp(wsgiapp)
    url._push_object(URLGenerator(config['routes.map'], environ))
    TestCase.__init__(self, *args, **kwargs)
        
class TestModel(TestCase):
  
  def __init__(self, *args, **kwargs):
    self.engine = load_sql_engine(config)
    TestCase.__init__(self, *args, **kwargs)
    
  def clear_db(self):
    from project.model import meta
    meta.metadata.drop_all(bind=self.engine, checkfirst=True)
    meta.metadata.create_all(bind=self.engine)
    meta.tokyo.clear()