~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/webapp/doc/zcmldirectives.txt

Merged fix-retest-colorize into redo-read-only-transactions-in-buildmaster, resolving several import conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
== Setting up some interfaces and objects to test with ==
37
37
 
38
 
We'll put an interface in canonical.launchpad.ftests.IFoo, and set the
 
38
We'll put an interface in lp.testing.IFoo, and set the
39
39
default view for the IFooLayer layer.
40
40
 
41
41
    >>> from zope.component import queryMultiAdapter
42
 
    >>> import canonical.launchpad.ftests
 
42
    >>> import lp.testing
43
43
    >>> from zope.interface import Interface, implements
44
44
    >>> class IFoo(Interface):
45
45
    ...     pass
46
46
    >>> class IFooLayer(Interface):
47
47
    ...     pass
48
 
    >>> canonical.launchpad.ftests.IFoo = IFoo
49
 
    >>> canonical.launchpad.ftests.IFooLayer = IFooLayer
 
48
    >>> lp.testing.IFoo = IFoo
 
49
    >>> lp.testing.IFooLayer = IFooLayer
50
50
 
51
51
    >>> class FooObject:
52
52
    ...     implements(IFoo)
62
62
    ...
63
63
    ...     def __call__(self):
64
64
    ...         return "FooView was called"
65
 
    >>> canonical.launchpad.ftests.FooView = FooView
 
65
    >>> lp.testing.FooView = FooView
66
66
 
67
67
 
68
68
== Overriding the browser:page directive ==
72
72
 
73
73
First, a unit test of the overridden directive.
74
74
 
75
 
    >>> from canonical.launchpad.webapp.metazcml import page
 
75
    >>> from lp.services.webapp.metazcml import page
76
76
    >>> context = Context()
77
77
    >>> context.info = "INFO"
78
78
 
136
136
    >>> from zope.configuration import xmlconfig
137
137
    >>> zcmlcontext = xmlconfig.string("""
138
138
    ... <configure xmlns:browser="http://namespaces.zope.org/browser"
139
 
    ...     package="canonical.launchpad">
 
139
    ...     package="lp.services">
140
140
    ...   <include file="webapp/meta-overrides.zcml" />
141
141
    ...   <browser:page
142
 
    ...     for="canonical.launchpad.ftests.IFoo"
 
142
    ...     for="lp.testing.IFoo"
143
143
    ...     name="+whatever"
144
144
    ...     permission="zope.Public"
145
 
    ...     class="canonical.launchpad.ftests.FooView"
 
145
    ...     class="lp.testing.FooView"
146
146
    ...     attribute="__call__"
147
147
    ...     facet="the_evil_facet"
148
 
    ...     layer="canonical.launchpad.ftests.IFooLayer"
 
148
    ...     layer="lp.testing.IFooLayer"
149
149
    ...     />
150
150
    ...   <browser:page
151
 
    ...     for="canonical.launchpad.ftests.IFoo"
 
151
    ...     for="lp.testing.IFoo"
152
152
    ...     name="+mandrill"
153
153
    ...     permission="zope.Public"
154
154
    ...     template="../../lp/app/templates/base-layout.pt"
155
155
    ...     facet="another-mister-lizard"
156
 
    ...     layer="canonical.launchpad.ftests.IFooLayer"
 
156
    ...     layer="lp.testing.IFooLayer"
157
157
    ...     />
158
158
    ... </configure>
159
159
    ... """)
181
181
 
182
182
First, a unit test of the overridden directive.
183
183
 
184
 
    >>> from canonical.launchpad.webapp.metazcml import pages
 
184
    >>> from lp.services.webapp.metazcml import pages
185
185
    >>> context = Context()
186
186
    >>> context.info = "INFO"
187
187
 
200
200
    >>> P.page(context, name, facet=facet)
201
201
    >>> P.page(context, "OTHER NAME")
202
202
 
203
 
# This is a pointless test. See pointless test comment above
204
 
# -- StuartBishop 20060411
205
 
#     >>> context
206
 
#     ((None,
207
 
#       <function provideInterface>,
208
 
#       ('', 'FOR_')),
209
 
#      (('view',
210
 
#        'FOR_',
211
 
#        'NAME',
212
 
#        <InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
213
 
#        <InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>),
214
 
#       <function handler>,
215
 
#       ('Adapters',
216
 
#        'register',
217
 
#        ('FOR_',
218
 
#         <InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>),
219
 
#        <InterfaceClass zope.interface.Interface>,
220
 
#        'NAME',
221
 
#        <class 'zope.app.publisher.browser.viewmeta.SimpleLaunchpadViewClass'>,
222
 
#        'INFO')),
223
 
#      (None,
224
 
#       <function provideInterface>,
225
 
#       ('', 'FOR_')),
226
 
#      (('view',
227
 
#        'FOR_',
228
 
#        'OTHER NAME',
229
 
#        <InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>,
230
 
#        <InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>),
231
 
#       <function handler>,
232
 
#       ('Adapters',
233
 
#        'register',
234
 
#        ('FOR_',
235
 
#         <InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>),
236
 
#        <InterfaceClass zope.interface.Interface>,
237
 
#        'OTHER NAME',
238
 
#        <class 'zope.app.publisher.browser.viewmeta.SimpleLaunchpadViewClass'>,
239
 
#        'INFO')))
240
 
 
241
 
 
242
203
Look for the SimpleLaunchpadViewClass in the data structure above, and check
243
204
its __launchpad_facetname__ attribute.
244
205
 
260
221
 
261
222
    >>> zcmlcontext = xmlconfig.string("""
262
223
    ... <configure xmlns:browser="http://namespaces.zope.org/browser"
263
 
    ...     package="canonical.launchpad">
 
224
    ...     package="lp.services">
264
225
    ...   <include file="webapp/meta-overrides.zcml" />
265
226
    ...   <browser:pages
266
 
    ...     for="canonical.launchpad.ftests.IFoo"
267
 
    ...     layer="canonical.launchpad.ftests.IFooLayer"
268
 
    ...     class="canonical.launchpad.ftests.FooView"
 
227
    ...     for="lp.testing.IFoo"
 
228
    ...     layer="lp.testing.IFooLayer"
 
229
    ...     class="lp.testing.FooView"
269
230
    ...     facet="outerspace"
270
231
    ...     permission="zope.Public">
271
232
    ...     <browser:page
303
264
 
304
265
First, a unit test of the overridden directive.
305
266
 
306
 
    >>> from canonical.launchpad.webapp.metazcml import EditFormDirective
 
267
    >>> from lp.services.webapp.metazcml import EditFormDirective
307
268
    >>> context = Context()
308
269
    >>> context.info = "INFO"
309
270
 
334
295
#        'edit.pt',
335
296
#        'edit.pt',
336
297
#        (<class 'zope.app.form.browser.editview.EditView'>,
337
 
#         <class 'canonical.launchpad.webapp.metazcml.SimpleLaunchpadViewClass'>),
 
298
#         <class 'lp.services.webapp.metazcml.SimpleLaunchpadViewClass'>),
338
299
#        'FOR_',
339
300
#        [])),)
340
301
 
354
315
 
355
316
    >>> zcmlcontext = xmlconfig.string("""
356
317
    ... <configure xmlns:browser="http://namespaces.zope.org/browser"
357
 
    ...     package="canonical.launchpad">
 
318
    ...     package="lp.services">
358
319
    ...   <include file="webapp/meta-overrides.zcml" />
359
320
    ...   <browser:editform
360
 
    ...     for="canonical.launchpad.ftests.IFoo"
 
321
    ...     for="lp.testing.IFoo"
361
322
    ...     name="+someeditform"
362
 
    ...     layer="canonical.launchpad.ftests.IFooLayer"
 
323
    ...     layer="lp.testing.IFooLayer"
363
324
    ...     schema="zope.interface.Interface"
364
325
    ...     facet="another_mister_lizard"
365
326
    ...     permission="zope.Public"/>
381
342
 
382
343
First, a unit test of the overridden directive.
383
344
 
384
 
    >>> from canonical.launchpad.webapp.metazcml import AddFormDirective
 
345
    >>> from lp.services.webapp.metazcml import AddFormDirective
385
346
    >>> context = Context()
386
347
    >>> context.info = "INFO"
387
348
 
412
373
#       'add.pt',
413
374
#       'add.pt',
414
375
#       (<class 'zope.app.form.browser.add.AddView'>,
415
 
#        <class 'canonical.launchpad.webapp.metazcml.SimpleLaunchpadViewClass'>),
 
376
#        <class 'lp.services.webapp.metazcml.SimpleLaunchpadViewClass'>),
416
377
#       'FOR_',
417
378
#       [],
418
379
#       None,
437
398
 
438
399
    >>> zcmlcontext = xmlconfig.string("""
439
400
    ... <configure xmlns:browser="http://namespaces.zope.org/browser"
440
 
    ...     package="canonical.launchpad">
 
401
    ...     package="lp.services">
441
402
    ...   <include file="webapp/meta-overrides.zcml" />
442
403
    ...   <browser:addform
443
 
    ...     for="canonical.launchpad.ftests.IFoo"
 
404
    ...     for="lp.testing.IFoo"
444
405
    ...     name="+someaddform"
445
 
    ...     layer="canonical.launchpad.ftests.IFooLayer"
 
406
    ...     layer="lp.testing.IFooLayer"
446
407
    ...     schema="zope.interface.Interface"
447
408
    ...     facet="yet_another_mister_lizard"
448
409
    ...     permission="zope.Public"/>
464
425
 
465
426
First, a unit test of the overridden directive.
466
427
 
467
 
    >>> from canonical.launchpad.webapp.metazcml import SchemaDisplayDirective
 
428
    >>> from lp.services.webapp.metazcml import SchemaDisplayDirective
468
429
    >>> context = Context()
469
430
    >>> context.info = "INFO"
470
431
 
495
456
#        'display.pt',
496
457
#        'display.pt',
497
458
#        (<class 'zope.app.form.browser.schemadisplay.DisplayView'>,
498
 
#         <class 'canonical.launchpad.webapp.metazcml.SimpleLaunchpadViewClass'>),
 
459
#         <class 'lp.services.webapp.metazcml.SimpleLaunchpadViewClass'>),
499
460
#        'FOR_',
500
461
#        [],
501
462
#        None)),)
517
478
 
518
479
    >>> zcmlcontext = xmlconfig.string("""
519
480
    ... <configure xmlns:browser="http://namespaces.zope.org/browser"
520
 
    ...     package="canonical.launchpad">
 
481
    ...     package="lp.services">
521
482
    ...   <include file="webapp/meta-overrides.zcml" />
522
483
    ...   <browser:schemadisplay
523
 
    ...     for="canonical.launchpad.ftests.IFoo"
 
484
    ...     for="lp.testing.IFoo"
524
485
    ...     name="+someschemadisplay"
525
 
    ...     layer="canonical.launchpad.ftests.IFooLayer"
 
486
    ...     layer="lp.testing.IFooLayer"
526
487
    ...     schema="zope.interface.Interface"
527
488
    ...     facet="hurrah_yet_another_mister_lizard"
528
489
    ...     permission="zope.Public"/>
542
503
We override the grouping directive zope:configure to add a 'facet' attribute
543
504
that can be inherited by all of the directives it contains.
544
505
 
545
 
    >>> from canonical.launchpad.webapp.metazcml import GroupingFacet
 
506
    >>> from lp.services.webapp.metazcml import GroupingFacet
546
507
    >>> context = Context()
547
508
 
548
509
Name some variables to mirror the names used as arguments.
561
522
    >>> zcmlcontext = xmlconfig.string("""
562
523
    ... <configure xmlns="http://namespaces.zope.org/zope"
563
524
    ...            xmlns:browser="http://namespaces.zope.org/browser"
564
 
    ...     package="canonical.launchpad">
 
525
    ...     package="lp.services">
565
526
    ...   <include file="webapp/meta.zcml" />
566
527
    ...   <include file="webapp/meta-overrides.zcml" />
567
528
    ...   <facet facet="whole-facet">
568
529
    ...     <browser:page
569
 
    ...       for="canonical.launchpad.ftests.IFoo"
 
530
    ...       for="lp.testing.IFoo"
570
531
    ...       name="+impliedfacet"
571
532
    ...       permission="zope.Public"
572
 
    ...       class="canonical.launchpad.ftests.FooView"
 
533
    ...       class="lp.testing.FooView"
573
534
    ...       attribute="__call__"
574
 
    ...       layer="canonical.launchpad.ftests.IFooLayer"
 
535
    ...       layer="lp.testing.IFooLayer"
575
536
    ...       />
576
537
    ...     <browser:addform
577
 
    ...       for="canonical.launchpad.ftests.IFoo"
 
538
    ...       for="lp.testing.IFoo"
578
539
    ...       name="+impliedfacet-add"
579
 
    ...       layer="canonical.launchpad.ftests.IFooLayer"
 
540
    ...       layer="lp.testing.IFooLayer"
580
541
    ...       schema="zope.interface.Interface"
581
542
    ...       permission="zope.Public"/>
582
543
    ...     <browser:editform
583
 
    ...       for="canonical.launchpad.ftests.IFoo"
 
544
    ...       for="lp.testing.IFoo"
584
545
    ...       name="+impliedfacet-edit"
585
 
    ...       layer="canonical.launchpad.ftests.IFooLayer"
 
546
    ...       layer="lp.testing.IFooLayer"
586
547
    ...       schema="zope.interface.Interface"
587
548
    ...       permission="zope.Public"/>
588
549
    ...     <browser:schemadisplay
589
 
    ...       for="canonical.launchpad.ftests.IFoo"
 
550
    ...       for="lp.testing.IFoo"
590
551
    ...       name="+impliedfacet-schemadisplay"
591
 
    ...       layer="canonical.launchpad.ftests.IFooLayer"
 
552
    ...       layer="lp.testing.IFooLayer"
592
553
    ...       schema="zope.interface.Interface"
593
554
    ...       permission="zope.Public"/>
594
555
    ...   </facet>
634
595
    >>> zcmlcontext = xmlconfig.string("""
635
596
    ... <configure xmlns="http://namespaces.zope.org/zope"
636
597
    ...     i18n_domain="canonical">
637
 
    ...   <include file="lib/canonical/launchpad/webapp/meta-overrides.zcml" />
 
598
    ...   <include file="lib/lp/services/webapp/meta-overrides.zcml" />
638
599
    ...   <permission id="foo.bar" title="Foo Bar" access_level="read" />
639
600
    ... </configure>
640
601
    ... """)
641
 
    >>> from canonical.launchpad.webapp.metazcml import ILaunchpadPermission
642
 
    >>> from canonical.launchpad.webapp.testing import verifyObject
 
602
    >>> from lp.services.webapp.metazcml import ILaunchpadPermission
 
603
    >>> from lp.services.webapp.testing import verifyObject
643
604
    >>> permission = getUtility(ILaunchpadPermission, 'foo.bar')
644
605
    >>> verifyObject(ILaunchpadPermission, permission)
645
606
    True
651
612
 
652
613
Clean up the interfaces we created for testing with.
653
614
 
654
 
    >>> del canonical.launchpad.ftests.IFoo
655
 
    >>> del canonical.launchpad.ftests.IFooLayer
656
 
    >>> del canonical.launchpad.ftests.FooView
 
615
    >>> del lp.testing.IFoo
 
616
    >>> del lp.testing.IFooLayer
 
617
    >>> del lp.testing.FooView