-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 27 Mar 2010, at 10:40, grassoalvaro wrote:
Hi,
i have problem with some automatic tests. Simple example:
[code]
from test.tests import *
from pylons import tmpl_context as c
class TestBlaController(TestController):
def test_index(self):
response = self.app.get(url(controller='bla', action='index'))
c.test = 'dupa'
How to register tmpl_context? (I'm testing of course other module
where i can't change code using templates, below it's only simple
example).
There's probably a more elegant way of doing this but it's a
workaround of sorts (you don't say what else you want to do with c). I
took my lead from the Pylons distro test suite, specifically tests/
test_units/__init__.py
from {{package}}.tests import *
import pylons
from pylons.util import ContextObj, PylonsContext
class TestAppServer(TestController):
def setUp(self):
c = ContextObj()
py_obj = PylonsContext()
py_obj.tmpl_context = c
pylons.tmpl_context._push_object(c)
def tearDown(self):
pylons.tmpl_context._pop_object()
def test_index(self):
c = pylons.tmpl_context
response = self.app.get('/')
c.testkey = 'foo'
assert c.testkey == 'foo'
# Test response...
tgt = '''A result to match'''
assert tgt in response
HTH
- --
Cheers,
Graham
http://www.linkedin.com/in/ghiggins
-----BEGIN PGP SIGNATURE-----
iEYEARECAAYFAkuufZQACgkQOsmLt1NhivzQQgCggL1mCN2V2v79224pi79ZZaad
XKwAoMtJoWl8C3TpNRCvVcClMV8Dq0Y9iQCVAgUBS659lFnrWVZ7aXD1AQKCGgQA
hNi+OOOHydmnT31KFxn3VnjmN9RXykVNEnEE0TQV0LqQWGjJtKE00e5eVcrLAeqQ
X/VuxgeZCAwsCsL4aiWmOOjjs6BjO/67RPT+nq1ergiW8110BIJu7JszlEqmb7A1
FrtGPyCVVes4YI6rQQZRUm0qvtkylwNhC1wYPSEFc10=
=xqqg
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.