ovirt-node 2.2.0 release
[ovirt-node.git] / server / ovirtserver / tests / __init__.py
blob7c1a4a975323416e495f90739084414c5c4a1651
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."""
20 from os import path
21 import sys
23 from tg import config
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']
34 def setup_db():
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)
40 def teardown_db():
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):
47 """
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
56 integration tests.
58 This is the officially supported way to test protected areas with
59 repoze.who-testutil (http://code.gustavonarea.net/repoze.who-testutil/).
61 """
63 application_under_test = 'main_without_authn'
65 def setUp(self):
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,
70 relative_to=conf_dir)
71 self.app = TestApp(wsgiapp)
72 # Setting it up:
73 test_file = path.join(conf_dir, 'test.ini')
74 cmd = SetupCommand('setup-app')
75 cmd.run([test_file])
77 def tearDown(self):
78 """Method called by nose after running each test"""
79 # Cleaning up the database:
80 teardown_db()