Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / tests / __init__.py @ b373a5de

History | View | Annotate | Download (2.1 KB)

1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2006-2011 CS-SI
3
# License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
4

    
5
"""Unit and functional test suite for vigiboard."""
6

    
7
from os import path, environ
8
import sys
9

    
10
import unittest
11
from tg import config
12
from paste.deploy import loadapp
13
from paste.script.appinstall import SetupCommand
14
from webtest import TestApp
15

    
16
from vigilo.models.session import metadata, DBSession
17

    
18
__all__ = ['setup_db', 'teardown_db', 'TestController']
19

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

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

    
32
class TestController(unittest.TestCase):
33
    """
34
    Base functional test case for the controllers.
35

36
    The vigiboard application instance (``self.app``) set up in this test
37
    case (and descendants) has authentication disabled, so that developers can
38
    test the protected areas independently of the :mod:`repoze.who` plugins
39
    used initially. This way, authentication can be tested once and separately.
40

41
    Check vigiboard.tests.functional.test_authentication for the repoze.who
42
    integration tests.
43

44
    This is the officially supported way to test protected areas with
45
    repoze.who-testutil (http://code.gustavonarea.net/repoze.who-testutil/).
46

47
    """
48

    
49
    application_under_test = 'main_without_authn'
50

    
51
    def setUp(self):
52
        """Method called by nose before running each test"""
53
        # Loading the application:
54
        conf_dir = config.here
55
        wsgiapp = loadapp('config:test.ini#%s' %
56
            self.application_under_test, relative_to=conf_dir)
57
        self.app = TestApp(wsgiapp)
58
        # Setting it up:
59
        test_file = path.join(conf_dir, 'test.ini')
60
        cmd = SetupCommand('setup-app')
61
        cmd.run([test_file])
62

    
63
    def tearDown(self):
64
        """Method called by nose after running each test"""
65
        # Cleaning up the database:
66
        teardown_db()
67
        del self.app