← Back to team overview

launchpad-dev team mailing list archive

HELP NEEDED: test traversal function

 

Hi All,

In a desire to make breadcrumbs easier to test, and to provide a useful test 
function, I've been attempting to write a function that takes a canonical_url 
of an object, and returns the object that was traversed to and a request 
object.

def test_traverse(url):
    url_parts = urlsplit(url)
    server_url = '://'.join(url_parts[0:2])
    path_info = url_parts[2]
    request, publication = get_request_and_publication(
        host=url_parts[1], extra_environment={
            'SERVER_URL': server_url,
            'PATH_INFO': path_info})
    getUtility(IOpenLaunchBag).clear()
    request.setPublication(publication)
    obj = publication.getApplication(request)
    obj = request.traverse(obj)
    return obj, request

branch = factory.makeBranch()
from canonical.launchpad.webapp import canonical_url
branch_url = canonical_url(branch)
obj, request = test_traverse(branch_url)


However, it doesn't work.  It fails to find the '~person' on the root object. I 
know I'm missing something vital.  It seems very close.  If I use:

    nav = LaunchpadRootNavigation(obj, request)

and then obj = request.traverse(nav), then it finds the person, but fails on 
the next segment.

I feel there must be something else that at each traversal step gets the 
navigation object for the object being traversed, and then calls 
publishTraverse on that navigation object.  However I can't seem to find it.  
Can some zope guru please point me in the right place?

Thanks
Tim




Follow ups