vigiboard / vigiboard / tests / __init__.py @ d7540235
History | View | Annotate | Download (2.36 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 | 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 | d4656036 | Gabriel DE PERTHUIS | import nose |
13 | from nose.tools import eq_, nottest |
||
14 | 57f7cb3f | Gabriel DE PERTHUIS | |
15 | d7540235 | Aurelien BOMPARD | from vigilo.common.conf import settings |
16 | 57f7cb3f | Gabriel DE PERTHUIS | from vigiboard import model |
17 | |||
18 | __all__ = ['setup_db', 'teardown_db', 'TestController', 'url_for'] |
||
19 | |||
20 | def setup_db(): |
||
21 | """Method used to build a database"""
|
||
22 | d3c47597 | Francois POIROTTE | model.metadata.create_all() |
23 | 57f7cb3f | Gabriel DE PERTHUIS | |
24 | def teardown_db(): |
||
25 | """Method used to destroy a database"""
|
||
26 | d3c47597 | Francois POIROTTE | model.metadata.drop_all() |
27 | 57f7cb3f | Gabriel DE PERTHUIS | |
28 | |||
29 | class TestController(object): |
||
30 | """
|
||
31 | Base functional test case for the controllers.
|
||
32 |
|
||
33 | The vigiboard application instance (``self.app``) set up in this test
|
||
34 | case (and descendants) has authentication disabled, so that developers can
|
||
35 | test the protected areas independently of the :mod:`repoze.who` plugins
|
||
36 | used initially. This way, authentication can be tested once and separately.
|
||
37 |
|
||
38 | Check vigiboard.tests.functional.test_authentication for the repoze.who
|
||
39 | integration tests.
|
||
40 |
|
||
41 | This is the officially supported way to test protected areas with
|
||
42 | repoze.who-testutil (http://code.gustavonarea.net/repoze.who-testutil/).
|
||
43 |
|
||
44 | """
|
||
45 | |||
46 | application_under_test = 'main_without_authn'
|
||
47 | d3c47597 | Francois POIROTTE | |
48 | def __init__(self): |
||
49 | object.__init__(self) |
||
50 | 57f7cb3f | Gabriel DE PERTHUIS | |
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' % self.application_under_test, |
||
56 | 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 | d3c47597 | Francois POIROTTE | del self.app |
68 | d4656036 | Gabriel DE PERTHUIS | |
69 | def runtests(): |
||
70 | d3c47597 | Francois POIROTTE | """This is the method called when running unit tests."""
|
71 | d4656036 | Gabriel DE PERTHUIS | # XXX hard-coded path.
|
72 | a2d3e48e | Aurelien BOMPARD | sys.argv[1:0] = ['--with-pylons', '../vigiboard/test.ini', |
73 | '--with-coverage', '--cover-inclusive', |
||
74 | '--cover-erase', '--cover-package', 'vigiboard', |
||
75 | 'vigiboard.tests' ]
|
||
76 | d4656036 | Gabriel DE PERTHUIS | nose.main() |