source: main/waeup.sirp/branches/ulif-experimental-folders/src/waeup/sirp/university/courserefs.txt @ 11078

Last change on this file since 11078 was 4921, checked in by uli, 15 years ago

Make functional tests work again.

File size: 3.5 KB
Line 
1Course references
2*****************
3
4Courses are referenced by certificate courses.
5
6:Test-Layer: functional
7
8We can be sure, that when removing courses or references to them,
9other data will be handled in a way we expect. That is,
10
11* when we remove a course, we want all references to it be removed as
12  well
13
14* when we remove a reference to a course, nothing else should be
15  touched but only this very reference.
16
17
18As correct deletion of references needs support of catalogs (we lookup
19catalogs to find references), we need a fully blown ZODB here,
20including an instance of :class:`waeup.sirp.app.University`, as this is our
21`ISite` object where the catalogs are stored.
22
23We create a complete university tree, starting with a
24:class:`University` instance and going down to courses, certificats
25and course certificates:
26
27    >>> from waeup.sirp.app import University
28    >>> root = getRootFolder()
29    >>> root['app'] = University()
30
31We have to set the site, to enable proper working of catalogs and
32`IObjectRemoved` handlers:
33
34    >>> from zope.app.component.hooks import setSite
35    >>> setSite(root['app'])
36
37    >>> from zope.component import createObject
38    >>> faculty = createObject('waeup.Faculty')
39    >>> faculty.code = 'FAC'
40    >>> root['app']['faculties'].addFaculty(faculty)
41    >>> fac = root['app']['faculties']['FAC']
42
43    >>> dept = createObject('waeup.Department')
44    >>> dept.code = 'DEPT'
45    >>> root['app']['faculties']['FAC'].addDepartment(dept)
46
47    >>> course = createObject('waeup.Course')
48    >>> course.code = 'CRS1'
49    >>> fac['DEPT'].courses.addCourse(course)
50
51Now let's add another department, which will also hold a course:
52
53    >>> dept2 = createObject('waeup.Department')
54    >>> dept2.code = 'DEPT2'
55    >>> root['app']['faculties']['FAC'].addDepartment(dept2)
56
57    >>> course = createObject('waeup.Course')
58    >>> course.code = 'CRS2'
59    >>> fac['DEPT2'].courses.addCourse(course)
60
61Finally, we add a certificate with references (certificate courses) to
62the created courses:
63
64    >>> cert = createObject('waeup.Certificate')
65    >>> cert.code = 'CERT'
66    >>> fac['DEPT'].certificates.addCertificate(cert)
67
68    >>> fac['DEPT'].certificates['CERT'].addCourseRef(
69    ...   fac['DEPT'].courses['CRS1'])
70
71    >>> fac['DEPT'].certificates['CERT'].addCourseRef(
72    ...   fac['DEPT2'].courses['CRS2'])
73
74We add the latter course again, but this time for the second level:
75
76    >>> fac['DEPT'].certificates['CERT'].addCourseRef(
77    ...   fac['DEPT2'].courses['CRS2'], level=200)
78
79So, we have three references in our certificate to two different
80courses stored somewhere in the application:
81
82    >>> list(fac['DEPT'].certificates['CERT'])
83    [u'CRS1_100', u'CRS2_100', u'CRS2_200']
84
85Both, the courses themselves and the references to them, are the same
86(not only equal):
87
88    >>> a = root['app']['faculties']['FAC']['DEPT']
89    >>> b1 = a.courses['CRS1']
90    >>> b2 = a.certificates['CERT']['CRS1_100'].course
91    >>> b1 is b2
92    True
93
94If we remove the course, also the reference to it in the cert course
95will be gone:
96
97    >>> list(a.certificates['CERT'])
98    [u'CRS1_100', u'CRS2_100', u'CRS2_200']
99
100    >>> list(a.courses)
101    [u'CRS1']
102
103    >>> del root['app']['faculties']['FAC']['DEPT'].courses['CRS1']
104    >>> list(a.certificates['CERT'])
105    [u'CRS2_100', u'CRS2_200']
106
107    >>> list(a.courses)
108    []
109
110If we remove a reference, this will not touch the referenced course
111nor other references:
112
113    >>> del fac['DEPT'].certificates['CERT']['CRS2_200']
114    >>> list(a.certificates['CERT'])
115    [u'CRS2_100']
116
117    >>> list(fac['DEPT2'].courses)
118    [u'CRS2']
Note: See TracBrowser for help on using the repository browser.