source: main/waeup.sirp/branches/ulif-paster/src/waeup/sirp/hostel/hostelcontainer.txt @ 10009

Last change on this file since 10009 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
Line 
1waeup.sirp.hostel.HostelContainer
2*********************************
3
4Containers for hostels.
5
6.. :doctest:
7.. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer
8
9Getting a hostel container
10==========================
11
12We can easily create `HostelContainers`::
13
14    >>> from waeup.sirp.hostel.hostelcontainer import HostelContainer
15    >>> mycontainer = HostelContainer()
16
17Hostel containers provide ``IHostelContainer``:
18
19    >>> from waeup.sirp.interfaces import IHostelContainer
20    >>> IHostelContainer.providedBy(mycontainer)
21    True
22
23Another way to get a hostel container -- without importing the class
24-- is via factories. We registered a factory for hostel containers
25under the name ``waeup.HostelContainer``. So we can ask for an object
26by calling the appropriate factory:
27
28    >>> from zope.component import createObject
29    >>> createObject(u'waeup.HostelContainer')
30    <waeup.sirp.hostel.hostelcontainer.HostelContainer object at 0x...>
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
56    >>> from waeup.sirp.hostel.hostel import Hostel
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.