| 1 | # |
|---|
| 2 | # Copyright (c) 2008-2011 Camptocamp. |
|---|
| 3 | # All rights reserved. |
|---|
| 4 | # |
|---|
| 5 | # Redistribution and use in source and binary forms, with or without |
|---|
| 6 | # modification, are permitted provided that the following conditions |
|---|
| 7 | # are met: |
|---|
| 8 | # 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | # notice, this list of conditions and the following disclaimer. |
|---|
| 10 | # 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | # notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | # documentation and/or other materials provided with the distribution. |
|---|
| 13 | # 3. Neither the name of Camptocamp nor the names of its contributors may |
|---|
| 14 | # be used to endorse or promote products derived from this software |
|---|
| 15 | # without specific prior written permission. |
|---|
| 16 | # |
|---|
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|---|
| 18 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 20 | # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY |
|---|
| 21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|---|
| 22 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|---|
| 23 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|---|
| 24 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 26 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 | # |
|---|
| 28 | |
|---|
| 29 | from unittest import TestCase |
|---|
| 30 | |
|---|
| 31 | import pylons |
|---|
| 32 | from pylons.util import ContextObj, PylonsContext |
|---|
| 33 | |
|---|
| 34 | class TestWSGIController(TestCase): |
|---|
| 35 | def setUp(self): |
|---|
| 36 | c = ContextObj() |
|---|
| 37 | py_obj = PylonsContext() |
|---|
| 38 | py_obj.tmpl_context = c |
|---|
| 39 | py_obj.request = py_obj.response = None |
|---|
| 40 | self.environ = {'pylons.routes_dict': dict(action='index'), |
|---|
| 41 | 'paste.config': dict(global_conf=dict(debug=True)), |
|---|
| 42 | 'pylons.pylons': py_obj} |
|---|
| 43 | pylons.tmpl_context._push_object(c) |
|---|
| 44 | |
|---|
| 45 | def tearDown(self): |
|---|
| 46 | pylons.tmpl_context._pop_object() |
|---|
| 47 | |
|---|
| 48 | def get_response(self, **kargs): |
|---|
| 49 | test_args = kargs.pop('test_args', {}) |
|---|
| 50 | url = kargs.pop('_url', '/') |
|---|
| 51 | self.environ['pylons.routes_dict'].update(kargs) |
|---|
| 52 | return self.app.get(url, extra_environ=self.environ, **test_args) |
|---|