On 5/19/06, Joost Moesker <[EMAIL PROTECTED]> wrote:

Hi, I'm having some trouble writing unit tests for a secured object.
The controller code is as follows:

yes this is a known issue, it also happens went you run tg-admin shell and try to do identity.

foo= Foo()
foo = identity.SecureObject(foo,
identity.from_any_host(cherrypy.config.get ("identity.allowed_hosts",["127.0.0.1"])))

Next i'm trying to test this controller as described in the docs:

def test_index():
    cherrypy.root = Root()
    d = testutil.call(cherrypy.root.index)
    assert d['title'] == 'A greate title'

Yet this raises IdentityFailure.

Digging into identity and testutil it appears that the allowed_hosts
predicate uses cherrypy.request.remoteHost which isn't set in the
DummyRequest used by testutils.call(). I have attached a patch which
sets this attribute to '127.0.0.1'. Yet i'm not sure if this is the
best way to go about.

Your patch seems to fix your issue but I believe a more general one could be better.

Reply via email to