def test_redirect_absolute(self):
resp = self.app.get('/redirect_me?target=/')
assert resp.status == 302, resp.status
assert resp.header('location') == 'http://localhost/', resp.headers
resp = resp.follow()
assert 'hello world' in resp
This checks that we get response (which is a WebOb response object)
which is a redirect, and the does resp.follow() to get the redirected
page and then verifies that 'hello world' is in the rendered template.
We also plan to make resp.namespace contain the values that are passed
into the template (basically the controller's returned dictionary).
I've looked into it and it turns out to be kind of hard to emulate the
create_request and call that are in TG 1 in CP3, since they are very
tied to the CP2 internals. Would it be out of line to provide some
deprecation warnings for create_request and call in order to encourage
people to migrate to a testing tool that will work in 1.1 and 2.0 ?
--
Mark Ramm-Christensen
email: mark at compoundthinking dot com
blog: www.compoundthinking.com/blog
We could consider this for TG 1.1. We consider TG 1.0 stable and in
maintenance mode, so no new features or deprecations of existing ones
should go into the core.
Just my 2 cents.
Chris
The problem is that migrations to TG 1.1 will require breaking all
your tests unless we do the crazy work to make create_request work
with cherrypy 3. So it would be nicer if we could tell people to
update their tests in place in TG1 -- and then move their app to TG
1.1, where they can use those tests to verify that their app continues
to work.
As I see it the problem with making create_request work is that it
does not -- return a response object, but instead it just ends up
generating a response object on cherrypy.response as a side effect --
and I don't see a way to do that without monkeying with the cherrypy
internals in some way.
--Mark Ramm
Mark,
1.0 is closed. It took time and effort, we now intend to move to 1.1
but this enhancement in testing you are talking about is interesting.
I am working on TG 1.1 / CP3 right now and I've broken quite a few
things already so I would be interesting in helping establish this new
testing framework so that I can have the internal TG test suite
guarantee that I have the same functionality in 1.1 once I finished
moving to CP3. To be honest I think that this work will go in 1.2 if I
break to much things (for the moment I did not break the config
system)
My problem is that I am quite resource stretched and will not have
much time to give on each subject so if someone can help on this
testing subject I would be grateful. What would be the level of
changes/breakage induced by this new testing method?
Florent.
I've also been playing in this space. I agree with Mark that the
webtest API is nicer than the tg1.0 method, but I'm slightly more
hopeful of being able to maintain a good degree of backwards
compatibility during the transition.
The approach I've taken is to have create_request return a response
object, whose body can be checked instead of
cherrypy.response.body[0]. The response that's returned is massaged
slightly to look more like a webtest response. When the project is
ready to make the switch, a config option can be enabled to start
using webtest directly.
Other issues that come up include the fact that webtest automatically
checks the response's status code, and different handling of cookies.
I've attached a patch to #1466 to show where I'm at. I've got a few
tweaks I want to make yet, but I've got all the tests passing. I had
hoped to be in position to start comiting changes in the next couple
of days, but I can pull back if anything thinks I'm seriously
off-track. I'd also like to see Luke's code if it's available.
Note that I have the same problem as Mark, in that this really takes
two releases to roll out fully: one to put the new method in place &
deprecate the old way, and another to drop the old stuff completely.
I had been working under the assumption that 1.1 would still be
cp2-based, and that there will be later 1.x releases which would
target cp3.
-ken
We don't need to break anything. The changes needed are centered on
a small test for the presence of a testing environment specific
variable in the wsgi environ. Other than that, everything should
just work.
Seems like we could add this as a small bugfix (it's like 10 lines of
code) in 1.1 tomorrow. We'll talk more about backporting it to 1.0.x
when you have time.... it's pretty simple, and would make migrations
easier. Perhaps we could slip it in since it doesn't break anything,
but skip the deprecation warnings...