source: main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_move.py @ 13975

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

Improve department and certificate movers. Add utility view for moving certificates.

  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1## $Id: test_move.py 12620 2015-02-16 11:27:24Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Tests for moving objects in faculties.
20"""
21import os
22from zope.catalog.interfaces import ICatalog
23from zope.component import queryUtility
24from waeup.kofa.university.faculty import Faculty
25from waeup.kofa.university.department import Department
26from waeup.kofa.students.tests.test_browser import StudentsFullSetup
27
28class MoveObjectsInFaculties(StudentsFullSetup):
29
30    def test_move_department(self):
31        self.app['faculties']['fac2'] = Faculty(code=u'fac2')
32        self.assertEqual(
33            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
34            self.certificate)
35        department = self.app['faculties']['fac1']['dep1']
36        faculty = self.app['faculties']['fac1']
37
38        # We move the depart using the UtilityView
39        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
40        self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac2&dep=newdep')
41
42        # New department is created and old department is removed
43        self.assertEqual(
44            [key for key in self.app['faculties']['fac2']], ['newdep'])
45
46        # All subobjects have been moved too
47        self.assertEqual(
48            self.app['faculties']['fac2']['newdep'].courses['COURSE1'],
49            self.course)
50        self.assertEqual(
51            self.app['faculties']['fac2']['newdep'].certificates['CERT1'],
52            self.certificate)
53        self.assertEqual(
54            [key for key in self.app['faculties']['fac2'][
55                'newdep'].certificates['CERT1'].keys()],
56            [u'COURSE1_100'])
57
58        # We can still find the certificate in the catalog
59        cat = queryUtility(ICatalog, name='certificates_catalog')
60        results = cat.searchResults(code=('CERT1','CERT1'))
61        results = [x for x in results]
62        assert len(results) == 1
63        assert results[0] is self.certificate
64
65        # We can still find the course in the catalog
66        cat = queryUtility(ICatalog, name='courses_catalog')
67        results = cat.searchResults(code=('COURSE1','COURSE1'))
68        results = [x for x in results] #
69        assert len(results) == 1
70        assert results[0] is self.course
71
72        # We can still find the certificatecourse in the catalog
73        cat = queryUtility(ICatalog, name='certcourses_catalog')
74        results = cat.searchResults(course_code=('COURSE1','COURSE1'))
75        results = [x for x in results]
76        assert len(results) == 1
77        assert results[0] is self.app['faculties']['fac2'][
78            'newdep'].certificates['CERT1']['COURSE1_100']
79
80        # We can find the student studying in the new department
81        cat = queryUtility(ICatalog, name='students_catalog')
82        results = cat.searchResults(depcode=('newdep','newdep'))
83        results = [x for x in results] # Turn results generator into list
84        assert len(results) == 1
85        assert results[0] is self.app['students'][self.student_id]
86
87        # Messages are found in two log files
88        logfile = os.path.join(
89            self.app['datacenter'].storage, 'logs', 'students.log')
90        logcontent = open(logfile).read()
91        self.assertTrue('INFO - zope.mgr - K1000000 - Department moved'
92            in logcontent)
93        logfile = os.path.join(
94            self.app['datacenter'].storage, 'logs', 'main.log')
95        logcontent = open(logfile).read()
96        self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac2/newdep'
97            in logcontent)
98
99
100    def test_move_certificate(self):
101        self.app['faculties']['fac2'] = Faculty(code=u'fac2')
102        self.app['faculties']['fac2']['dep2'] = Department(code=u'dep2')
103        self.assertEqual(
104            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
105            self.certificate)
106
107        #self.certificate.moveCertificate('fac2', 'dep2', 'NEWCODE')
108
109        # We move the depart using the UtilityView
110        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
111        self.browser.open('http://localhost/app/faculties/fac1/dep1/certificates/CERT1/move_certificate?fac=fac2&dep=dep2&cert=NEWCODE')
112
113        self.assertEqual(
114            self.app['faculties']['fac2']['dep2'].certificates['NEWCODE'],
115            self.certificate)
116        self.assertEqual(
117            [key for key in self.app['faculties']['fac2'][
118                'dep2'].certificates['NEWCODE'].keys()], [u'COURSE1_100'])
119        self.assertEqual(
120            self.student['studycourse'].certificate,
121            self.certificate)
122
123        # We can find the moved certificate in the catalog
124        cat = queryUtility(ICatalog, name='certificates_catalog')
125        results = cat.searchResults(code=('NEWCODE','NEWCODE'))
126        results = [x for x in results] # Turn results generator into list
127        assert len(results) == 1
128        assert results[0] is self.certificate
129
130        # Also certcourses_catalog has been updated
131        cat = queryUtility(ICatalog, name='certcourses_catalog')
132        results = cat.searchResults(course_code=('COURSE1','COURSE1'))
133        results = [x for x in results] # Turn results generator into list
134        assert len(results) == 1
135        assert results[0] is self.app['faculties']['fac2'][
136                'dep2'].certificates['NEWCODE']['COURSE1_100']
137
138        # We can find the student studying in the new department
139        cat = queryUtility(ICatalog, name='students_catalog')
140        results = cat.searchResults(depcode=('dep2','dep2'))
141        results = [x for x in results] # Turn results generator into list
142        assert len(results) == 1
143        assert results[0] is self.app['students'][self.student_id]
144
145        # We can find the student studying the new course ...
146        cat = queryUtility(ICatalog, name='students_catalog')
147        results = cat.searchResults(certcode=('NEWCODE','NEWCODE'))
148        results = [x for x in results] # Turn results generator into list
149        assert len(results) == 1
150        assert results[0] is self.app['students'][self.student_id]
151        # ... but not the old course
152        results = cat.searchResults(certcode=('CERT1','CERT1'))
153        assert len(results) == 0
154
155        logfile = os.path.join(
156            self.app['datacenter'].storage, 'logs', 'students.log')
157        logcontent = open(logfile).read()
158        self.assertTrue('INFO - zope.mgr - K1000000 - Certificate moved'
159            in logcontent)
160        logfile = os.path.join(
161            self.app['datacenter'].storage, 'logs', 'main.log')
162        logcontent = open(logfile).read()
163        self.assertTrue('INFO - zope.mgr - Certificate CERT1 moved to fac2/dep2/NEWCODE'
164            in logcontent)
Note: See TracBrowser for help on using the repository browser.