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

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

Move test to a more appropriate place.

  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1## $Id: test_move.py 12614 2015-02-13 12:11:52Z 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.department import Department
25from waeup.kofa.students.tests.test_browser import StudentsFullSetup
26
27class MoveObjectsInFaculties(StudentsFullSetup):
28
29    def test_move_department(self):
30        self.assertEqual(
31            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
32            self.certificate)
33        department = self.app['faculties']['fac1']['dep1']
34        faculty = self.app['faculties']['fac1']
35
36        # We move the depart using the UtilityView
37        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
38        self.browser.open('http://localhost/app/faculties/fac1/dep1/move_department?fac=fac1&dep=newdep')
39
40        # New department is created and old department is removed
41        self.assertEqual(
42            [key for key in self.app['faculties']['fac1']], ['newdep'])
43
44        # All subobjects have been moved too
45        self.assertEqual(
46            self.app['faculties']['fac1']['newdep'].courses['COURSE1'],
47            self.course)
48        self.assertEqual(
49            self.app['faculties']['fac1']['newdep'].certificates['CERT1'],
50            self.certificate)
51        self.assertEqual(
52            [key for key in self.app['faculties']['fac1'][
53                'newdep'].certificates['CERT1'].keys()],
54            [u'COURSE1_100'])
55
56        # We can still find the certificate in the catalog
57        cat = queryUtility(ICatalog, name='certificates_catalog')
58        results = cat.searchResults(code=('CERT1','CERT1'))
59        results = [x for x in results]
60        assert len(results) == 1
61        assert results[0] is self.certificate
62
63        # We can still find the course in the catalog
64        cat = queryUtility(ICatalog, name='courses_catalog')
65        results = cat.searchResults(code=('COURSE1','COURSE1'))
66        results = [x for x in results] #
67        assert len(results) == 1
68        assert results[0] is self.course
69        # We can still find the certificatecourse in the catalog
70        cat = queryUtility(ICatalog, name='certcourses_catalog')
71        results = cat.searchResults(course_code=('COURSE1','COURSE1'))
72        results = [x for x in results]
73        assert len(results) == 1
74        assert results[0] is self.app['faculties']['fac1'][
75            'newdep'].certificates['CERT1']['COURSE1_100']
76
77        # We can find the student studying in the new department
78        cat = queryUtility(ICatalog, name='students_catalog')
79        results = cat.searchResults(depcode=('newdep','newdep'))
80        results = [x for x in results] # Turn results generator into list
81        assert len(results) == 1
82        assert results[0] is self.app['students'][self.student_id]
83
84        # Messages are found in two log files
85        logfile = os.path.join(
86            self.app['datacenter'].storage, 'logs', 'students.log')
87        logcontent = open(logfile).read()
88        self.assertTrue('INFO - zope.mgr - K1000000 - Department moved'
89            in logcontent)
90        logfile = os.path.join(
91            self.app['datacenter'].storage, 'logs', 'main.log')
92        logcontent = open(logfile).read()
93        self.assertTrue('INFO - zope.mgr - Department dep1 moved to fac1/newdep'
94            in logcontent)
95
96
97    def test_move_certificate(self):
98        self.assertEqual(
99            self.app['faculties']['fac1']['dep1'].certificates['CERT1'],
100            self.certificate)
101        self.app['faculties']['fac1']['dep2'] = Department(code=u'dep2')
102        self.certificate.moveCertificate('fac1', 'dep2')
103        self.assertEqual(
104            self.app['faculties']['fac1']['dep2'].certificates['CERT1'],
105            self.certificate)
106        self.assertEqual(
107            [key for key in self.app['faculties']['fac1'][
108                'dep2'].certificates['CERT1'].keys()],
109            [u'COURSE1_100'])
110        self.assertEqual(
111            self.student['studycourse'].certificate,
112            self.certificate)
113
114        # We can still find the certificate in the catalog
115        cat = queryUtility(ICatalog, name='certificates_catalog')
116        results = cat.searchResults(code=('CERT1','CERT1'))
117        results = [x for x in results] # Turn results generator into list
118        assert len(results) == 1
119        assert results[0] is self.certificate
120
121        # Also certcourses_catalog has been updated
122        cat = queryUtility(ICatalog, name='certcourses_catalog')
123        results = cat.searchResults(course_code=('COURSE1','COURSE1'))
124        results = [x for x in results] # Turn results generator into list
125        assert len(results) == 1
126        assert results[0] is self.app['faculties']['fac1'][
127                'dep2'].certificates['CERT1']['COURSE1_100']
128
129        # We can find the student studying in the new department
130        cat = queryUtility(ICatalog, name='students_catalog')
131        results = cat.searchResults(depcode=('dep2','dep2'))
132        results = [x for x in results] # Turn results generator into list
133        assert len(results) == 1
134        assert results[0] is self.app['students'][self.student_id]
135        logfile = os.path.join(
136            self.app['datacenter'].storage, 'logs', 'students.log')
137        logcontent = open(logfile).read()
138        self.assertTrue('INFO - system - K1000000 - Certificate moved'
139            in logcontent)
Note: See TracBrowser for help on using the repository browser.