568
568
== Registering menus in ZCML ==
570
570
First, we define a couple of interfaces, and put them in the
571
canonical.launchpad.ftests module.
573
573
>>> class IThingHavingFacets(Interface):
575
>>> import canonical.launchpad.ftests
576
>>> getattr(canonical.launchpad.ftests, 'IThingHavingFacets', None) is None
575
>>> import lp.testing
576
>>> getattr(lp.testing, 'IThingHavingFacets', None) is None
579
>>> canonical.launchpad.ftests.IThingHavingFacets = IThingHavingFacets
580
>>> IThingHavingFacets.__module__ = 'canonical.launchpad.ftests'
579
>>> lp.testing.IThingHavingFacets = IThingHavingFacets
580
>>> IThingHavingFacets.__module__ = 'lp.testing'
582
582
>>> class IThingHavingMenus(Interface):
584
>>> import canonical.launchpad.ftests
585
>>> getattr(canonical.launchpad.ftests, 'IThingHavingMenus', None) is None
584
>>> import lp.testing
585
>>> getattr(lp.testing, 'IThingHavingMenus', None) is None
588
>>> canonical.launchpad.ftests.IThingHavingMenus = IThingHavingMenus
589
>>> IThingHavingMenus.__module__ = 'canonical.launchpad.ftests'
588
>>> lp.testing.IThingHavingMenus = IThingHavingMenus
589
>>> IThingHavingMenus.__module__ = 'lp.testing'
591
591
Next, we define a FacetMenu subclass to be used for IThingHavingFacets,
592
592
using a usedfor class attribute to say what interface it is to be
593
registered for, and put it too in the canonical.launchpad.ftests module.
593
registered for, and put it too in the lp.testing module.
595
595
>>> class FacetsForThing(Facets):
596
596
... usedfor = IThingHavingFacets
606
606
... summary = self.request.method
607
607
... return Link(target, text, summary=summary)
609
>>> getattr(canonical.launchpad.ftests, 'FacetsForThing', None) is None
609
>>> getattr(lp.testing, 'FacetsForThing', None) is None
612
>>> canonical.launchpad.ftests.FacetsForThing = FacetsForThing
612
>>> lp.testing.FacetsForThing = FacetsForThing
614
614
And likewise for an application menu registered for IThingHavingMenus.
617
617
... usedfor = IThingHavingMenus
618
618
... facet = 'foo'
620
>>> getattr(canonical.launchpad.ftests, 'FooMenuForThing', None) is None
620
>>> getattr(lp.testing, 'FooMenuForThing', None) is None
623
>>> canonical.launchpad.ftests.FooMenuForThing = FooMenuForThing
623
>>> lp.testing.FooMenuForThing = FooMenuForThing
625
625
We do the same for a context menu.
627
627
>>> class ContextMenuForThing(MyContextMenu):
628
628
... usedfor = IThingHavingMenus
630
>>> print getattr(canonical.launchpad.ftests, 'ContextMenuForThing', None)
630
>>> print getattr(lp.testing, 'ContextMenuForThing', None)
633
>>> canonical.launchpad.ftests.ContextMenuForThing = ContextMenuForThing
633
>>> lp.testing.ContextMenuForThing = ContextMenuForThing
635
635
Now, check that we have no IFacetMenu adapter for an IThingHavingFacets
660
660
... <configure xmlns:browser="http://namespaces.zope.org/browser">
661
661
... <include file="lib/canonical/launchpad/webapp/meta.zcml" />
662
662
... <browser:menus
663
... module="canonical.launchpad.ftests"
663
... module="lp.testing"
664
664
... classes="FacetsForThing FooMenuForThing ContextMenuForThing"
897
897
== Cleaning up ==
899
899
We're done testing the zcml, so we can clean up the
900
canonical.launchpad.ftests module.
902
>>> del canonical.launchpad.ftests.FacetsForThing
903
>>> del canonical.launchpad.ftests.FooMenuForThing
904
>>> del canonical.launchpad.ftests.ContextMenuForThing
905
>>> del canonical.launchpad.ftests.IThingHavingFacets
906
>>> del canonical.launchpad.ftests.IThingHavingMenus
902
>>> del lp.testing.FacetsForThing
903
>>> del lp.testing.FooMenuForThing
904
>>> del lp.testing.ContextMenuForThing
905
>>> del lp.testing.IThingHavingFacets
906
>>> del lp.testing.IThingHavingMenus
909
909
== The enabled_with_permission function decorator ==