source: cows/trunk/cows/pylons/project_templates/cows_server/+package+/tests/__init__.py @ 6576

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/pylons/project_templates/cows_server/+package+/tests/__init__.py@6576
Revision 6576, 1.4 KB checked in by spascoe, 10 years ago (diff)

Added licence to all source files

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