Revision 04cd2200
Migration des tests vers gearbox
Pour la compatibilité ascendante avec TG 2.3.
Change-Id: I1865506a1e255477f187f779eac5464e0ac5d391
vigiboard/tests/__init__.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
"""Unit and functional test suite for vigiboard.""" |
6 | 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 |
|
7 |
from vigilo.turbogears.test import setup_db, teardown_db |
|
8 |
from vigilo.turbogears.test import TestController as TestTGController |
|
17 | 9 |
|
18 | 10 |
__all__ = ['setup_db', 'teardown_db', 'TestController'] |
19 | 11 |
|
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 |
|
68 |
|
|
12 |
class TestController(TestTGController): |
|
69 | 13 |
def get_rows(self, response): |
70 | 14 |
return response.lxml.xpath( |
71 | 15 |
'//table[contains(concat(" ", @class, " "), " vigitable ")]' |
Also available in: Unified diff