vigiboard / vigiboard / tests / __init__.py @ 747e30c3
History | View | Annotate | Download (2.06 KB)
1 | 57f7cb3f | Gabriel DE PERTHUIS | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | """Unit and functional test suite for vigiboard."""
|
||
3 | |||
4 | 477d2eb1 | Gabriel DE PERTHUIS | from os import path, environ |
5 | 57f7cb3f | Gabriel DE PERTHUIS | import sys |
6 | |||
7 | 747e30c3 | Francois POIROTTE | import unittest |
8 | 57f7cb3f | Gabriel DE PERTHUIS | from tg import config |
9 | from paste.deploy import loadapp |
||
10 | from paste.script.appinstall import SetupCommand |
||
11 | from routes import url_for |
||
12 | from webtest import TestApp |
||
13 | |||
14 | e7e3d45e | Francois POIROTTE | from vigilo.models.session import metadata, DBSession |
15 | 7365fb51 | Francois POIROTTE | |
16 | 57f7cb3f | Gabriel DE PERTHUIS | __all__ = ['setup_db', 'teardown_db', 'TestController', 'url_for'] |
17 | |||
18 | def setup_db(): |
||
19 | """Method used to build a database"""
|
||
20 | 5dbfa80d | Francois POIROTTE | print "Creating model" |
21 | engine = config['pylons.app_globals'].sa_engine
|
||
22 | metadata.create_all(engine) |
||
23 | 57f7cb3f | Gabriel DE PERTHUIS | |
24 | def teardown_db(): |
||
25 | """Method used to destroy a database"""
|
||
26 | 5dbfa80d | Francois POIROTTE | print "Destroying model" |
27 | engine = config['pylons.app_globals'].sa_engine
|
||
28 | metadata.drop_all(engine) |
||
29 | 57f7cb3f | Gabriel DE PERTHUIS | |
30 | 747e30c3 | Francois POIROTTE | class TestController(unittest.TestCase): |
31 | 57f7cb3f | Gabriel DE PERTHUIS | """
|
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 | d3c47597 | Francois POIROTTE | |
49 | 57f7cb3f | Gabriel DE PERTHUIS | def setUp(self): |
50 | """Method called by nose before running each test"""
|
||
51 | # Loading the application:
|
||
52 | conf_dir = config.here |
||
53 | 5dbfa80d | Francois POIROTTE | wsgiapp = loadapp('config:test.ini#%s' %
|
54 | self.application_under_test, relative_to=conf_dir)
|
||
55 | 57f7cb3f | Gabriel DE PERTHUIS | self.app = TestApp(wsgiapp)
|
56 | # Setting it up:
|
||
57 | test_file = path.join(conf_dir, 'test.ini')
|
||
58 | cmd = SetupCommand('setup-app')
|
||
59 | cmd.run([test_file]) |
||
60 | |||
61 | def tearDown(self): |
||
62 | """Method called by nose after running each test"""
|
||
63 | # Cleaning up the database:
|
||
64 | teardown_db() |
||
65 | d3c47597 | Francois POIROTTE | del self.app |