source: cows/trunk/cows/test/testapp/tests/__init__.py @ 4613

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/test/testapp/tests/__init__.py@4613
Revision 4613, 1.2 KB checked in by spascoe, 12 years ago (diff)

Improved testing for COWS.

To effectively test COWS you need a Pylons application. I've created a
mini pylons app in cows/test/testapp that is automatically wired into
the Pylons testing framework when you run "nosetests cows". See
cows/test/README.

Line 
1"""Pylons application test package
2
3When the test runner finds and executes tests within this directory,
4this file will be loaded to setup the test environment.
5
6It registers the root directory of the project in sys.path and
7pkg_resources, in case the project hasn't been installed with
8setuptools. It also initializes the application via websetup (paster
9setup-app) with the project's test.ini configuration file.
10"""
11import os
12import sys
13from unittest import TestCase
14
15import pkg_resources
16import paste.fixture
17import paste.script.appinstall
18from paste.deploy import loadapp
19from routes import url_for
20
21__all__ = ['url_for', 'TestController']
22
23conf_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
24
25#sys.path.insert(0, conf_dir)
26#pkg_resources.working_set.add_entry(conf_dir)
27pkg_resources.require('Paste')
28pkg_resources.require('PasteScript')
29
30test_file = os.path.join(conf_dir, 'test.ini')
31cmd = paste.script.appinstall.SetupCommand('setup-app')
32cmd.run([test_file])
33
34class TestController(TestCase):
35
36    def __init__(self, *args, **kwargs):
37        wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
38        self.app = paste.fixture.TestApp(wsgiapp)
39        TestCase.__init__(self, *args, **kwargs)
Note: See TracBrowser for help on using the repository browser.