[9341] | 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 | """ |
---|
| 19 | Tests for moving objects in faculties. |
---|
| 20 | """ |
---|
| 21 | import os |
---|
| 22 | from zope.catalog.interfaces import ICatalog |
---|
| 23 | from zope.component import queryUtility |
---|
[12620] | 24 | from waeup.kofa.university.faculty import Faculty |
---|
[9341] | 25 | from waeup.kofa.university.department import Department |
---|
| 26 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
| 27 | |
---|
| 28 | class MoveObjectsInFaculties(StudentsFullSetup): |
---|
| 29 | |
---|
[12609] | 30 | def test_move_department(self): |
---|
[12620] | 31 | self.app['faculties']['fac2'] = Faculty(code=u'fac2') |
---|
[12609] | 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 | |
---|
[12610] | 38 | # We move the depart using the UtilityView |
---|
| 39 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[12620] | 40 | self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac2&dep=newdep') |
---|
[12610] | 41 | |
---|
[12609] | 42 | # New department is created and old department is removed |
---|
| 43 | self.assertEqual( |
---|
[12620] | 44 | [key for key in self.app['faculties']['fac2']], ['newdep']) |
---|
[12609] | 45 | |
---|
| 46 | # All subobjects have been moved too |
---|
| 47 | self.assertEqual( |
---|
[12620] | 48 | self.app['faculties']['fac2']['newdep'].courses['COURSE1'], |
---|
[12609] | 49 | self.course) |
---|
| 50 | self.assertEqual( |
---|
[12620] | 51 | self.app['faculties']['fac2']['newdep'].certificates['CERT1'], |
---|
[12609] | 52 | self.certificate) |
---|
| 53 | self.assertEqual( |
---|
[12620] | 54 | [key for key in self.app['faculties']['fac2'][ |
---|
[12609] | 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 |
---|
[12620] | 71 | |
---|
[12609] | 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 |
---|
[12620] | 77 | assert results[0] is self.app['faculties']['fac2'][ |
---|
[12609] | 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] |
---|
[12610] | 86 | |
---|
| 87 | # Messages are found in two log files |
---|
[12609] | 88 | logfile = os.path.join( |
---|
| 89 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
| 90 | logcontent = open(logfile).read() |
---|
[12610] | 91 | self.assertTrue('INFO - zope.mgr - K1000000 - Department moved' |
---|
[12609] | 92 | in logcontent) |
---|
[12610] | 93 | logfile = os.path.join( |
---|
| 94 | self.app['datacenter'].storage, 'logs', 'main.log') |
---|
| 95 | logcontent = open(logfile).read() |
---|
[12620] | 96 | self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac2/newdep' |
---|
[12610] | 97 | in logcontent) |
---|
[12609] | 98 | |
---|
| 99 | |
---|
[9341] | 100 | def test_move_certificate(self): |
---|
[12620] | 101 | self.app['faculties']['fac2'] = Faculty(code=u'fac2') |
---|
| 102 | self.app['faculties']['fac2']['dep2'] = Department(code=u'dep2') |
---|
[9341] | 103 | self.assertEqual( |
---|
| 104 | self.app['faculties']['fac1']['dep1'].certificates['CERT1'], |
---|
| 105 | self.certificate) |
---|
[12620] | 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 | |
---|
[9341] | 113 | self.assertEqual( |
---|
[12620] | 114 | self.app['faculties']['fac2']['dep2'].certificates['NEWCODE'], |
---|
[9341] | 115 | self.certificate) |
---|
| 116 | self.assertEqual( |
---|
[12620] | 117 | [key for key in self.app['faculties']['fac2'][ |
---|
| 118 | 'dep2'].certificates['NEWCODE'].keys()], [u'COURSE1_100']) |
---|
[9341] | 119 | self.assertEqual( |
---|
| 120 | self.student['studycourse'].certificate, |
---|
| 121 | self.certificate) |
---|
| 122 | |
---|
[12620] | 123 | # We can find the moved certificate in the catalog |
---|
[9341] | 124 | cat = queryUtility(ICatalog, name='certificates_catalog') |
---|
[12620] | 125 | results = cat.searchResults(code=('NEWCODE','NEWCODE')) |
---|
[9341] | 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 | |
---|
[12590] | 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 |
---|
[12620] | 135 | assert results[0] is self.app['faculties']['fac2'][ |
---|
| 136 | 'dep2'].certificates['NEWCODE']['COURSE1_100'] |
---|
[12590] | 137 | |
---|
[9341] | 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] |
---|
[12620] | 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 | |
---|
[9341] | 155 | logfile = os.path.join( |
---|
| 156 | self.app['datacenter'].storage, 'logs', 'students.log') |
---|
| 157 | logcontent = open(logfile).read() |
---|
[12620] | 158 | self.assertTrue('INFO - zope.mgr - K1000000 - Certificate moved' |
---|
[9341] | 159 | in logcontent) |
---|
[12620] | 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) |
---|