source: main/waeup.sirp/trunk/src/waeup/sirp/hostel/hostelcontainer.txt @ 5325

Last change on this file since 5325 was 5140, checked in by uli, 15 years ago

Update all unit tests that use the ZCA to run inside the new unit test layer.

File size: 2.0 KB
RevLine 
[4920]1waeup.sirp.hostel.HostelContainer
2*********************************
[3941]3
4Containers for hostels.
5
[5140]6.. :doctest:
7.. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer
[3941]8
9Getting a hostel container
10==========================
11
12We can easily create `HostelContainers`::
13
[4920]14    >>> from waeup.sirp.hostel.hostelcontainer import HostelContainer
[3941]15    >>> mycontainer = HostelContainer()
16
[4082]17Hostel containers provide ``IHostelContainer``:
[3941]18
[4920]19    >>> from waeup.sirp.interfaces import IHostelContainer
[3941]20    >>> IHostelContainer.providedBy(mycontainer)
21    True
22
[4082]23Another way to get a hostel container -- without importing the class
24-- is via factories. We registered a factory for hostel containers
[5140]25under the name ``waeup.HostelContainer``. So we can ask for an object
26by calling the appropriate factory:
[3941]27
[4082]28    >>> from zope.component import createObject
29    >>> createObject(u'waeup.HostelContainer')
[4920]30    <waeup.sirp.hostel.hostelcontainer.HostelContainer object at 0x...>
[3941]31
32This way we get a thing that implements IHostelContainer without
33imports or similar.
34
35We can be sure, that the full interface is supported by the
36HostelContainer class::
37
38    >>> from zope.interface.verify import verifyClass
39    >>> verifyClass(IHostelContainer, HostelContainer)
40    True
41
42
43Storing things in hostel containers
44====================================
45
46We can, of course, store things in a hostel container. But when we
47really store an object, then it must be a hostel::
48
49    >>> mycontainer.addHostel(42)
50    Traceback (most recent call last):
51    ...
52    TypeError: HostelContainers contain only IHostel instances
53
54Okay, so we have to get a hostel first::
55
[4920]56    >>> from waeup.sirp.hostel.hostel import Hostel
[3941]57    >>> myhostel = Hostel()
58
59We can add this hostel to our container::
60
61    >>> mycontainer.addHostel(myhostel)
62    '0'
63
64We get back the key, under which the hostel was stored. It will be
65some string, but there is no guarantee at all, how this key looks
66like. It might be a string of integers, a name or whatever; you cannot
67know before.
Note: See TracBrowser for help on using the repository browser.