Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / tests / __init__.py @ e6029893

History | View | Annotate | Download (2.15 KB)

1
# -*- coding: utf-8 -*-
2
"""Unit and functional test suite for vigiboard."""
3

    
4
from os import path, environ
5
import sys
6

    
7
from tg import config
8
from paste.deploy import loadapp
9
from paste.script.appinstall import SetupCommand
10
from routes import url_for
11
from webtest import TestApp
12
from nose.tools import eq_, nottest
13

    
14
from vigilo.models.configure import metadata, DBSession
15

    
16
__all__ = ['setup_db', 'teardown_db', 'TestController', 'url_for']
17

    
18
def setup_db():
19
    """Method used to build a database"""
20
    print "Creating model"
21
    engine = config['pylons.app_globals'].sa_engine
22
    metadata.create_all(engine)
23

    
24
def teardown_db():
25
    """Method used to destroy a database"""
26
    print "Destroying model"
27
    engine = config['pylons.app_globals'].sa_engine
28
    metadata.drop_all(engine)
29

    
30
class TestController(object):
31
    """
32
    Base functional test case for the controllers.
33
    
34
    The vigiboard application instance (``self.app``) set up in this test 
35
    case (and descendants) has authentication disabled, so that developers can
36
    test the protected areas independently of the :mod:`repoze.who` plugins
37
    used initially. This way, authentication can be tested once and separately.
38
    
39
    Check vigiboard.tests.functional.test_authentication for the repoze.who
40
    integration tests.
41
    
42
    This is the officially supported way to test protected areas with
43
    repoze.who-testutil (http://code.gustavonarea.net/repoze.who-testutil/).
44
    
45
    """
46
    
47
    application_under_test = 'main_without_authn'
48

    
49
    def __init__(self):
50
        object.__init__(self)
51
    
52
    def setUp(self):
53
        """Method called by nose before running each test"""
54
        # Loading the application:
55
        setup_db()
56
        conf_dir = config.here
57
        wsgiapp = loadapp('config:test.ini#%s' %
58
            self.application_under_test, relative_to=conf_dir)
59
        self.app = TestApp(wsgiapp)
60
        # Setting it up:
61
        test_file = path.join(conf_dir, 'test.ini')
62
        cmd = SetupCommand('setup-app')
63
        cmd.run([test_file])
64
    
65
    def tearDown(self):
66
        """Method called by nose after running each test"""
67
        # Cleaning up the database:
68
        teardown_db()
69
        del self.app
70