1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
"""Unit and functional test suite for pyjobsweb.""" |
3
|
|
|
|
4
|
|
|
from os import getcwd |
5
|
|
|
from paste.deploy import loadapp |
6
|
|
|
from webtest import TestApp |
7
|
|
|
from gearbox.commands.setup_app import SetupAppCommand |
8
|
|
|
from tg import config |
9
|
|
|
from tg.util import Bunch |
10
|
|
|
|
11
|
|
|
from pyjobsweb import model |
12
|
|
|
|
13
|
|
|
__all__ = ['setup_app', 'setup_db', 'teardown_db', 'TestController'] |
14
|
|
|
|
15
|
|
|
application_name = 'main_without_authn' |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
def load_app(name=application_name): |
19
|
|
|
"""Load the test application.""" |
20
|
|
|
return TestApp(loadapp('config:test.ini#%s' % name, relative_to=getcwd())) |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
def setup_app(): |
24
|
|
|
"""Setup the application.""" |
25
|
|
|
cmd = SetupAppCommand(Bunch(options=Bunch(verbose_level=1)), Bunch()) |
26
|
|
|
cmd.run(Bunch(config_file='config:test.ini', section_name=None)) |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
def setup_db(): |
30
|
|
|
"""Create the database schema (not needed when you run setup_app).""" |
31
|
|
|
engine = config['tg.app_globals'].sa_engine |
32
|
|
|
model.init_model(engine) |
33
|
|
|
model.metadata.create_all(engine) |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
def teardown_db(): |
37
|
|
|
"""Destroy the database schema.""" |
38
|
|
|
engine = config['tg.app_globals'].sa_engine |
39
|
|
|
model.metadata.drop_all(engine) |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
class TestController(object): |
43
|
|
|
"""Base functional test case for the controllers. |
44
|
|
|
|
45
|
|
|
The pyjobsweb application instance (``self.app``) set up in this test |
46
|
|
|
case (and descendants) has authentication disabled, so that developers can |
47
|
|
|
test the protected areas independently of the :mod:`repoze.who` plugins |
48
|
|
|
used initially. This way, authentication can be tested once and separately. |
49
|
|
|
|
50
|
|
|
Check pyjobsweb.tests.functional.test_authentication for the repoze.who |
51
|
|
|
integration tests. |
52
|
|
|
|
53
|
|
|
This is the officially supported way to test protected areas with |
54
|
|
|
repoze.who-testutil (http://code.gustavonarea.net/repoze.who-testutil/). |
55
|
|
|
|
56
|
|
|
""" |
57
|
|
|
application_under_test = application_name |
58
|
|
|
|
59
|
|
|
def setUp(self): |
60
|
|
|
"""Setup test fixture for each functional test method.""" |
61
|
|
|
self.app = load_app(self.application_under_test) |
62
|
|
|
setup_app() |
63
|
|
|
|
64
|
|
|
def tearDown(self): |
65
|
|
|
"""Tear down test fixture for each functional test method.""" |
66
|
|
|
model.DBSession.remove() |
67
|
|
|
teardown_db() |
68
|
|
|
|