source: main/waeup.kofa/trunk/src/waeup/kofa/doctests/certificatescontainer.txt @ 13066

Last change on this file since 13066 was 12951, checked in by Henrik Bettermann, 10 years ago

Simplify headlines in doctests. Remove some API documentation.

File size: 4.5 KB
Line 
1Certificate Containers
2**********************
3
4.. module:: waeup.kofa.university.certificatescontainer
5
6Containers for certificates.
7
8.. :doctest:
9.. :layer: waeup.kofa.testing.KofaUnitTestLayer
10
11
12Content Classes (models and containers)
13=======================================
14
15:class:`CertificatesContainer`
16------------------------------
17
18.. class:: CertificatesContainer()
19
20   Create a certificate container instance.
21
22   .. attribute:: grok.implements(ICertificatesContainer)
23
24   :class:`CertificatesContainer` instances are instances of
25   :class:`grok.Container` that hold and manage instances of
26   :class:`waeup.kofa.university.certificate.Certificate`.
27
28     >>> from waeup.kofa.university.certificatescontainer import CertificatesContainer
29     >>> mycontainer = CertificatesContainer()
30     >>> mycontainer
31     <waeup.kofa.university.certificatescontainer.CertificatesContainer object at 0x...>
32
33   Certificate containers provide `ICertificatesContainer`:
34
35     >>> from waeup.kofa.university.interfaces import ICertificatesContainer
36     >>> ICertificatesContainer.providedBy(mycontainer)
37     True
38
39   We can be sure, that the full interface is supported by the
40   CertificatesContainer class:
41
42     >>> from zope.interface.verify import verifyClass
43     >>> verifyClass(ICertificatesContainer, CertificatesContainer)
44     True
45
46   As normal ``grok.Container``, :class:`CertificatesContainer` instances
47   can be used like dicts:
48
49     >>> list(mycontainer.keys())
50     []
51
52   .. method:: addCertificate(certificate)
53
54      Add a certificate.
55
56      *certificate* must be an instance of
57      :class:`waeup.kofa.university.certificate.Certificate`:
58
59        >>> from waeup.kofa.university.certificatescontainer import (
60        ...   CertificatesContainer)
61        >>> mycontainer = CertificatesContainer()
62        >>> mycontainer.addCertificate('blah')
63        Traceback (most recent call last):
64        ...
65        TypeError: CertificatesContainers contain only ICertificate instances
66
67      The key of added items is the ``code`` attribute:
68
69        >>> from waeup.kofa.university.certificate import Certificate
70        >>> mycertificate = Certificate(code='CERTIFICATE1')
71        >>> mycontainer.addCertificate(mycertificate)
72        >>> list(mycontainer.keys())
73        [u'CERTIFICATE1']
74
75   .. method:: clear()
76
77      Remove all contained certificates:
78
79        >>> len(mycontainer.items())
80        1
81
82        >>> mycontainer.clear()
83        >>> len(mycontainer.items())
84        0
85
86Utilities
87=========
88
89:class:`CertificatesContainerFactory`
90-------------------------------------
91
92.. class:: CertificatesContainerFactory()
93
94   .. attribute:: grok.name(u'waeup.CertificatesContainer')
95
96   .. attribute:: grok.implements(IFactory)
97
98   A named utility to deliver new instances of :class:`CertificatesContainer`
99   without the need to import the implementation before:
100
101     >>> from zope.component import createObject
102     >>> mycertificatescontainer = createObject(u'waeup.CertificatesContainer')
103     >>> mycertificatescontainer
104     <waeup.kofa.university.certificatescontainer.CertificatesContainer object at 0x...>
105
106   The factory complies with the specifications from the
107   :class:`IFactory` insterface:
108
109     >>> from zope.interface.verify import verifyClass
110     >>> from zope.component.interfaces import IFactory
111     >>> from waeup.kofa.university.certificatescontainer import (
112     ...   CertificatesContainerFactory)
113     >>> verifyClass(IFactory, CertificatesContainerFactory)
114     True
115
116   This means also, that we can get the interfaces of the created
117   object from the factory:
118
119     >>> certificatescontainer_factory = CertificatesContainerFactory()
120     >>> certificatescontainer_factory.getInterfaces()
121     <implementedBy waeup.kofa.university.certificatescontainer.CertificatesContainer>
122
123
124Examples
125========
126
127Getting a certificate container
128-------------------------------
129
130We can easily create `CertificatesContainers`:
131
132    >>> from waeup.kofa.university.certificatescontainer import CertificatesContainer
133    >>> mycontainer = CertificatesContainer()
134
135
136Another way to get a certificate container -- without importing the
137class -- is via factories. We registered a factory for certificate
138containers under the name ``waeup.CertificatesContainer``. Now we can
139ask for an object by calling the appropriate factory:
140
141    >>> from zope.component import createObject
142    >>> createObject(u'waeup.CertificatesContainer')
143    <waeup.kofa.university.certificatescontainer.CertificatesContainer object at 0x...>
144
145This way we get a thing that implements ICertificatesContainer without
146imports or similar.
147
Note: See TracBrowser for help on using the repository browser.