I'm having a lot of trouble writing tests for controller methods. In
particular methods that have identity requirements and methods that
raise redirects are giving me problems.
For example, this is one method I want to test:
@identity.require(identity.not_anonymous())
@expose()
def addcity3(self, cityname):
"This is another method written so that Matt can learn to
write tests."
c = model.City(cityname=cityname)
return dict(city=c)
And here is the test:
def test_addcity3(self):
"Toy -- figure out how to work around identity decorator."
cherrypy.root = Root()
testutil.set_identity_user(model.User.by_user_name("matt"))
d = testutil.call(cherrypy.root.addcity3, "Pittsburgh")
pittsburgh = model.City.by_cityname("Pittsburgh")
assert d['city'].cityname == "Pittsburgh"
And here is what happens:
$ nosetests -x test_controllers.py
E
======================================================================
ERROR: Toy -- figure out how to work around identity decorator.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/matt/svn-checkouts/bz/branches/staffknex/bazman/bazman/
tests/test_controllers.py", line 108, in test_addcity3
d = testutil.call(cherrypy.root.addcity3, "Pittsburgh")
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.4b2-py2.5.egg/
turbogears/testutil.py", line 138, in call
output, response = call_with_request(method, DummyRequest(),
*args, **kw)
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.4b2-py2.5.egg/
turbogears/testutil.py", line 151, in call_with_request
output = method(*args, **kw)
File "<string>", line 3, in addcity3
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.4b2-py2.5.egg/
turbogears/identity/conditions.py", line 239, in require
raise IdentityFailure(errors)
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.4b2-py2.5.egg/
turbogears/identity/exceptions.py", line 64, in __init__
raise IdentityConfigurationException( msg )
IdentityConfigurationException: Missing URL for identity failure
----------------------------------------------------------------------
Ran 1 test in 0.060s
FAILED (errors=1)
Does anyone have some successful test_controllers they can share?
Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---