Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / tests / __init__.py @ d3c47597

History | View | Annotate | Download (2.32 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 vigiboard import model
16

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

    
19
def setup_db():
20
    """Method used to build a database"""
21
    model.metadata.create_all()
22

    
23
def teardown_db():
24
    """Method used to destroy a database"""
25
    model.metadata.drop_all()
26

    
27

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

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

    
68
def runtests():
69
    """This is the method called when running unit tests."""
70
    # XXX hard-coded path.
71
    sys.argv[1:0] = ['--with-pylons', '../vigiboard/test.ini', 
72
                     '--with-coverage', '--cover-inclusive',
73
                     '--cover-erase', '--cover-package', 'vigiboard',
74
                     'vigiboard.tests' ]
75
    nose.main()
76