Today I tried to make a test for a utility function that uses
app_globals, without going through a web request. I called
``self.app.get("/_test_vars")`` as the docs recommend, assuming it
would set ``pylons.app_globals``. Instead it returns a response object
with an ``._app_globals`` attribute. That doesn't help unless I push
the value onto ``pylons.app_globals`` myself, which means I'd then
have to go into the config value for the registry, etc... which was
way to complex for my little test. (The function needs to access some
global data that's set by environment.py.)
I ended up refactoring the function to not use app_globals. It was
too much work otherwise.
Another issue is 'url'. The docs say to use:
self.app.get(url(controller="X", action="Y"))
This is a substitution of h.url_for without changing the arguments.
But 'url' is not defined globally in the test environment ("no object
has been registered for this thread"). But doing it with
'/_test_vars' doesn't work either:
rsp = self.app.get("/_test_vars")
url = rsp.url
self.app.get(url(controller="X", action="Y"))
AttributeError: 'TestResponse' object has no attribute 'url'
As if people want to put all this code into every test method. But it
doesn't work anyway.
The only way around it I can see is to use literal URLs in tests.
Where is '/_test_vars' supposed to be used? Only in test methods? Or
can it be used in TestController.setUp and TestController.__init__ ?
I'm finding myself forced to make all tests subclasses of
TestController, even non-functional tests, because that's the only way
to access 'config' and 'app_globals' without going through more hoops.
That makes me feel dirty.
Curse the SOPs! Curse the SOPs!
--
Mike Orr <[email protected]>
--
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.