Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / tests / __init__.py @ 5dbfa80d

History | View | Annotate | Download (2.16 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
import nose
13
from nose.tools import eq_, nottest
14

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

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

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

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

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

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