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