~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/menu.py

  • Committer: William Grant
  • Date: 2011-12-30 07:50:11 UTC
  • mto: This revision was merged to the branch mainline in revision 14611.
  • Revision ID: william.grant@canonical.com-20111230075011-y4cmg5xuoq6mu9ya
Merge canonical.lazr's menu testing stuff to lp.testing.menu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
from lp.services.webapp import urlsplit
17
17
from lp.services.webapp.interfaces import ILink
 
18
from lp.services.webapp.publisher import canonical_url
18
19
from lp.services.webapp.servers import LaunchpadTestRequest
19
20
 
20
21
 
 
22
def check_menu_links(menu):
 
23
    context = menu.context
 
24
    for link in menu.iterlinks():
 
25
        if link.target.startswith(('/', 'http://')):
 
26
            # The context is not the context of this target.
 
27
            continue
 
28
        if '?' in link.target:
 
29
            view_name, _args = link.target.split('?')
 
30
        else:
 
31
            view_name = link.target
 
32
        if view_name == '':
 
33
            view_name = None
 
34
        try:
 
35
            canonical_url(context, view_name=view_name, rootsite=link.site)
 
36
        except Exception:
 
37
            return 'Bad link %s: %s' % (link.name, canonical_url(context))
 
38
    return True
 
39
 
 
40
 
21
41
def summarise_tal_links(links):
22
42
    """List the links and their attributes in the dict or list.
23
43