~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Curtis Hovey
  • Date: 2011-12-18 15:13:07 UTC
  • mto: This revision was merged to the branch mainline in revision 14547.
  • Revision ID: curtis.hovey@canonical.com-20111218151307-sdm2gzobt5tplbe0
Moved badges to lp.app.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Useful helper functions used for testing menus."""
 
5
 
 
6
__metaclass__ = type
 
7
 
 
8
from canonical.launchpad.webapp.publisher import canonical_url
 
9
 
 
10
 
 
11
def check_menu_links(menu):
 
12
    context = menu.context
 
13
    for link in menu.iterlinks():
 
14
        if link.target.startswith(('/', 'http://')):
 
15
            # The context is not the context of this target.
 
16
            continue
 
17
        if '?' in link.target:
 
18
            view_name, _args = link.target.split('?')
 
19
        else:
 
20
            view_name = link.target
 
21
        if view_name == '':
 
22
            view_name = None
 
23
        try:
 
24
            canonical_url(context, view_name=view_name, rootsite=link.site)
 
25
        except Exception:
 
26
            return 'Bad link %s: %s' % (link.name, canonical_url(context))
 
27
    return True