Skip to content
Newer
Older
100644 163 lines (130 sloc) 4.98 KB
83beee9 forgot to add base.py in
percious authored
1 # -*- coding: utf-8 -*-
2
3 import os, shutil
4 from unittest import TestCase
5 from xmlrpclib import loads, dumps
54f4e47 pylons 0.10 support started
percious authored
6 import warnings
83beee9 forgot to add base.py in
percious authored
7
8 import webob
9 import beaker
10 import pylons
11 from paste.registry import Registry
12 from paste.registry import RegistryManager
a6654b3 Updated the rest of the tests to use webtest now
mramm authored
13 from webtest import TestApp
83beee9 forgot to add base.py in
percious authored
14 from paste.wsgiwrappers import WSGIRequest, WSGIResponse
15 from paste import httpexceptions
16
4aeb6bb Content-Type bug is finally, after all these months squashed.
percious authored
17
d10739a beginings of rendering tests
mramm authored
18 import tg
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
19 import pylons
901942b Moved decorators to TG2.
mramm authored
20 from tg import tmpl_context
b32198c @deets moved tests to separate directory.
deets authored
21 from tests.test_stack import app_from_config, TestConfig
0971197 --HG--
mramm authored
22 from pylons import url
23 from routes import URLGenerator, Mapper
84d307d Fix config bug, clean up config, and add some basic full-stack tests.
mramm authored
24 from tg.util import Bunch
83beee9 forgot to add base.py in
percious authored
25 from pylons.util import ContextObj, PylonsContext
26 from pylons.controllers.util import Request, Response
f933b09 Fixing some tests that were still working against pylons.
mramm authored
27 from tg.controllers import TGController
4aeb6bb Content-Type bug is finally, after all these months squashed.
percious authored
28
29 from pylons.configuration import response_defaults
30 response_defaults['headers']['Content-Type'] = None
31
83beee9 forgot to add base.py in
percious authored
32 from pylons.testutil import ControllerWrap, SetupCacheGlobal
33
34 from beaker.middleware import CacheMiddleware
35
36 data_dir = os.path.dirname(os.path.abspath(__file__))
37 session_dir = os.path.join(data_dir, 'session')
38
39 def setup_session_dir():
40 if not os.path.exists(session_dir):
41 os.makedirs(session_dir)
453adde pylons 0.10 support started
percious authored
42
83beee9 forgot to add base.py in
percious authored
43 def teardown_session_dir():
44 shutil.rmtree(session_dir, ignore_errors=True)
45
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
46 default_config = {
47 'debug': False,
48 'pylons.package': None,
49 'pylons.paths': {'root': None,
50 'controllers': None,
51 'templates': [],
52 'static_files': None},
53 'pylons.db_engines': {},
453adde pylons 0.10 support started
percious authored
54 'pylons.environ_config': dict(session='beaker.session',
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
55 cache='beaker.cache'),
56 'pylons.g': None,
57 'pylons.h': None,
58 'pylons.request_options': pylons.configuration.request_defaults.copy(),
59 'pylons.response_options': pylons.configuration.response_defaults.copy(),
60 'pylons.strict_c': False,
be63f9b @amol- change random text to what it should have been
amol- authored
61 'pylons.strict_tmpl_context':False,
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
62 'pylons.c_attach_args': True,
453adde pylons 0.10 support started
percious authored
63 'pylons.tmpl_context_attach_args': True,
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
64 'default_renderer':'genshi',
982e97b @Cito Set up render_genshi function on demand only. Proper render_chameleon…
Cito authored
65 'renderers':['json'],
66 'render_functions':{'json':tg.render.render_json},
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
67 'use_legacy_renderers':False,
68 'use_sqlalchemy': False
69 }
83beee9 forgot to add base.py in
percious authored
70
71 default_environ = {
669596b Switched tests to use webob.
mramm authored
72 'pylons.use_webob' : True,
83beee9 forgot to add base.py in
percious authored
73 'pylons.routes_dict': dict(action='index'),
74 'paste.config': dict(global_conf=dict(debug=True))
75 }
76
0971197 --HG--
mramm authored
77 default_map = Mapper()
78
79 # Setup a default route for the error controller:
80 default_map.connect('error/:action/:id', controller='error')
81 # Setup a default route for the root of object dispatch
82 default_map.connect('*url', controller='root', action='routes_placeholder')
83
83beee9 forgot to add base.py in
percious authored
84 def make_app(controller_klass=None, environ=None):
85 """Creates a `TestApp` instance."""
86 if environ is None:
87 environ = {}
88 environ['pylons.routes_dict'] = {}
7d7ecda changing the name of the placholder route method to make it more obvi…
mramm authored
89 environ['pylons.routes_dict']['action'] = "routes_placeholder"
83beee9 forgot to add base.py in
percious authored
90
453adde pylons 0.10 support started
percious authored
91
83beee9 forgot to add base.py in
percious authored
92 if controller_klass is None:
93 controller_klass = TGController
94
95 app = ControllerWrap(controller_klass)
453adde pylons 0.10 support started
percious authored
96 app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True)
83beee9 forgot to add base.py in
percious authored
97 app = RegistryManager(app)
98 app = beaker.middleware.SessionMiddleware(app, {}, data_dir=session_dir)
99 app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache'))
100 app = httpexceptions.make_middleware(app)
101 return TestApp(app)
102
103 def create_request(path, environ=None):
104 """Helper used in test cases to quickly setup a request obj.
105
106 ``path``
107 The path will become PATH_INFO
108 ``environ``
109 Additional environment
110
111 Returns an instance of the `webob.Request` object.
112 """
113 # setup the environ
114 if environ is None:
115 environ = {}
116 environ.update(default_environ)
117 # create a "blank" WebOb Request object
118 # using Pylon's Request which is a webob Request plus
119 # some compatibility methods
120 req = Request.blank(path, environ)
121 # setup a Registry
122 reg = environ.setdefault('paste.registry', Registry())
123 reg.prepare()
4aeb6bb Content-Type bug is finally, after all these months squashed.
percious authored
124
83beee9 forgot to add base.py in
percious authored
125 # setup pylons.request to point to our Registry
126 reg.register(pylons.request, req)
453adde pylons 0.10 support started
percious authored
127
128
83beee9 forgot to add base.py in
percious authored
129 # setup tmpl context
9f109dd Fixed context renaming in base.py
mramm authored
130 tmpl_context._push_object(ContextObj())
0971197 --HG--
mramm authored
131 url._push_object(URLGenerator(default_map, environ))
83beee9 forgot to add base.py in
percious authored
132 return req
133
134 class TestWSGIController(TestCase):
135 def setUp(self):
40a6c17 Some optmization at _render_response regarding SOP access (which unco…
alberto authored
136 tmpl_options = {}
137 tmpl_options['genshi.search_path'] = ['tests']
138 self._ctx = ContextObj()
139 tmpl_context._push_object(self._ctx)
54f4e47 pylons 0.10 support started
percious authored
140
141 warnings.simplefilter("ignore")
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
142 pylons.config.push_process_config(default_config)
54f4e47 pylons 0.10 support started
percious authored
143 warnings.resetwarnings()
27351b4 We use webtest now
mramm authored
144 setup_session_dir()
40a6c17 Some optmization at _render_response regarding SOP access (which unco…
alberto authored
145
83beee9 forgot to add base.py in
percious authored
146 def tearDown(self):
40a6c17 Some optmization at _render_response regarding SOP access (which unco…
alberto authored
147 tmpl_context._pop_object(self._ctx)
612f493 pylons 0.10 support started
percious authored
148 # pylons.config.pop_thread_config()
1f3f1b3 @markramm Fix the non full stack tests to have consistant and predictable confi…
markramm authored
149 pylons.config.pop_process_config()
27351b4 We use webtest now
mramm authored
150 teardown_session_dir()
453adde pylons 0.10 support started
percious authored
151
83beee9 forgot to add base.py in
percious authored
152 def get_response(self, **kargs):
153 url = kargs.pop('_url', '/')
154 self.environ['pylons.routes_dict'].update(kargs)
0971197 --HG--
mramm authored
155
83beee9 forgot to add base.py in
percious authored
156 return self.app.get(url, extra_environ=self.environ)
157
158 def post_response(self, **kargs):
159 url = kargs.pop('_url', '/')
0971197 --HG--
mramm authored
160
83beee9 forgot to add base.py in
percious authored
161 return self.app.post(url, extra_environ=self.environ, params=kargs)
d10739a beginings of rendering tests
mramm authored
162
Something went wrong with that request. Please try again.