1 | FacultyContainer |
---|
2 | **************** |
---|
3 | |
---|
4 | Containers for faculties. |
---|
5 | |
---|
6 | :Test-Layer: unit |
---|
7 | |
---|
8 | Getting a faculty container |
---|
9 | =========================== |
---|
10 | |
---|
11 | We can easily create `FacultyContainers`:: |
---|
12 | |
---|
13 | >>> from waeup.sirp.university.facultycontainer import FacultyContainer |
---|
14 | >>> mycontainer = FacultyContainer() |
---|
15 | |
---|
16 | Faculty containers provide `IFacultyContainer`: |
---|
17 | |
---|
18 | >>> from waeup.sirp.interfaces import IFacultyContainer |
---|
19 | >>> IFacultyContainer.providedBy(mycontainer) |
---|
20 | True |
---|
21 | |
---|
22 | Another way to get a faculty container -- without importing the class |
---|
23 | -- is via factories. We registered a factory for faculty containers |
---|
24 | under the name ``waeup.facultycontainer``:: |
---|
25 | |
---|
26 | >>> import grok |
---|
27 | >>> grok.testing.grok('waeup') |
---|
28 | |
---|
29 | Now we can ask for an object by calling the appropriate factory: |
---|
30 | |
---|
31 | >>> from zope.component import createObject |
---|
32 | >>> createObject(u'waeup.FacultyContainer') |
---|
33 | <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...> |
---|
34 | |
---|
35 | This way we get a thing that implements IFacultyContainer without |
---|
36 | imports or similar. |
---|
37 | |
---|
38 | We can be sure, that the full interface is supported by the |
---|
39 | FacultyContainer class:: |
---|
40 | |
---|
41 | >>> from zope.interface.verify import verifyClass |
---|
42 | >>> verifyClass(IFacultyContainer, FacultyContainer) |
---|
43 | True |
---|
44 | |
---|
45 | |
---|
46 | Storing things in faculty containers |
---|
47 | ==================================== |
---|
48 | |
---|
49 | We can, of course, store things in a faculty container. But when we |
---|
50 | really store an object, then it must be a faculty:: |
---|
51 | |
---|
52 | >>> mycontainer.addFaculty(42) |
---|
53 | Traceback (most recent call last): |
---|
54 | ... |
---|
55 | TypeError: FacultyContainers contain only IFaculty instances |
---|
56 | |
---|
57 | Okay, so we have to get a faculty first:: |
---|
58 | |
---|
59 | >>> from waeup.sirp.university.faculty import Faculty |
---|
60 | >>> myfaculty = Faculty() |
---|
61 | |
---|
62 | We can add this faculty to our container:: |
---|
63 | |
---|
64 | >>> mycontainer.addFaculty(myfaculty) |
---|
65 | |
---|
66 | We get back the key, under which the faculty was stored. It will be |
---|
67 | some string, but there is no guarantee at all, how this key looks |
---|
68 | like. It might be a string of integers, a name or whatever; you cannot |
---|
69 | know before. |
---|
70 | |
---|