1 # Copyright (C) 2010, Red Hat, Inc.
2 # Written by Darryl L. Pierce
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 """Unit and functional test suite for server."""
24 from paste
.deploy
import loadapp
25 from paste
.script
.appinstall
import SetupCommand
26 from routes
import url_for
27 from webtest
import TestApp
28 from nose
.tools
import eq_
30 from ovirtserver
import model
32 __all__
= ['setup_db', 'teardown_db', 'TestController', 'url_for']
35 """Method used to build a database"""
36 engine
= config
['pylons.app_globals'].sa_engine
37 model
.init_model(engine
)
38 model
.metadata
.create_all(engine
)
41 """Method used to destroy a database"""
42 engine
= config
['pylons.app_globals'].sa_engine
43 model
.metadata
.drop_all(engine
)
46 class TestController(object):
48 Base functional test case for the controllers.
50 The server application instance (``self.app``) set up in this test
51 case (and descendants) has authentication disabled, so that developers can
52 test the protected areas independently of the :mod:`repoze.who` plugins
53 used initially. This way, authentication can be tested once and separately.
55 Check ovirtserver.tests.functional.test_authentication for the repoze.who
58 This is the officially supported way to test protected areas with
59 repoze.who-testutil (http://code.gustavonarea.net/repoze.who-testutil/).
63 application_under_test
= 'main_without_authn'
66 """Method called by nose before running each test"""
67 # Loading the application:
68 conf_dir
= config
.here
69 wsgiapp
= loadapp('config:test.ini#%s' % self
.application_under_test
,
71 self
.app
= TestApp(wsgiapp
)
73 test_file
= path
.join(conf_dir
, 'test.ini')
74 cmd
= SetupCommand('setup-app')
78 """Method called by nose after running each test"""
79 # Cleaning up the database: