1 | ## $Id: test_browser.py 9122 2012-08-29 11:53:22Z 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 | Test the student-related UI components. |
---|
20 | """ |
---|
21 | import shutil |
---|
22 | import tempfile |
---|
23 | import pytz |
---|
24 | from datetime import datetime, timedelta |
---|
25 | from StringIO import StringIO |
---|
26 | import os |
---|
27 | import grok |
---|
28 | from zope.event import notify |
---|
29 | from zope.component import createObject, queryUtility |
---|
30 | from zope.component.hooks import setSite, clearSite |
---|
31 | from zope.catalog.interfaces import ICatalog |
---|
32 | from zope.security.interfaces import Unauthorized |
---|
33 | from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase |
---|
34 | |
---|
35 | from waeup.kofa.utils.browser import replaceStudentMessages |
---|
36 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
37 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
38 | |
---|
39 | class StudentUtilsUITests(StudentsFullSetup): |
---|
40 | |
---|
41 | layer = FunctionalLayer |
---|
42 | |
---|
43 | def test_replace_student_messages(self): |
---|
44 | self.assertTrue('Record created by system' in |
---|
45 | self.student.history.messages[0]) |
---|
46 | replaceStudentMessages('system', 'me') |
---|
47 | self.assertTrue('Record created by me' in |
---|
48 | self.student.history.messages[0]) |
---|
49 | |
---|
50 | def test_modify_all_student_history(self): |
---|
51 | self.assertTrue('Record created by system' in |
---|
52 | self.student.history.messages[0]) |
---|
53 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
54 | self.browser.open('http://localhost/app/modify_student_history') |
---|
55 | self.assertTrue( |
---|
56 | 'Syntax: /modify_student_history?old=[old string]&new=[new string]' |
---|
57 | in self.browser.contents) |
---|
58 | self.browser.open( |
---|
59 | 'http://localhost/app/modify_student_history?old=by system&new=by me') |
---|
60 | self.assertTrue('Finished' in self.browser.contents) |
---|
61 | self.assertTrue('Record created by me' in |
---|
62 | self.student.history.messages[0]) |
---|
63 | |
---|
64 | def test_reindex(self): |
---|
65 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
66 | self.browser.open('http://localhost/app/reindex') |
---|
67 | self.assertTrue('No catalog name provided' in self.browser.contents) |
---|
68 | self.browser.open('http://localhost/app/reindex?ctlg=xyz') |
---|
69 | self.assertTrue('xyz_catalog does not exist' in self.browser.contents) |
---|
70 | cat = queryUtility(ICatalog, name='students_catalog') |
---|
71 | results = cat.searchResults(student_id=(None, None)) |
---|
72 | self.assertEqual(len(results),1) |
---|
73 | cat.clear() |
---|
74 | results = cat.searchResults(student_id=(None, None)) |
---|
75 | self.assertEqual(len(results),0) |
---|
76 | self.browser.open('http://localhost/app/reindex?ctlg=students') |
---|
77 | self.assertTrue('1 students re-indexed' in self.browser.contents) |
---|
78 | results = cat.searchResults(student_id=(None, None)) |
---|
79 | self.assertEqual(len(results),1) |
---|
80 | |
---|
81 | class ApplicantUtilsUITests(ApplicantsFullSetup): |
---|
82 | |
---|
83 | layer = FunctionalLayer |
---|
84 | |
---|
85 | def test_modify_all_applicant_history(self): |
---|
86 | self.assertTrue('Application initialized by system' in |
---|
87 | self.applicant.history.messages[0]) |
---|
88 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
89 | self.browser.open('http://localhost/app/modify_applicant_history') |
---|
90 | self.assertTrue( |
---|
91 | 'Syntax: /modify_applicant_history?old=[old string]&new=[new string]' |
---|
92 | in self.browser.contents) |
---|
93 | self.browser.open( |
---|
94 | 'http://localhost/app/modify_applicant_history?old=by system&new=by me') |
---|
95 | self.assertTrue('Finished' in self.browser.contents) |
---|
96 | self.assertTrue('Application initialized by me' in |
---|
97 | self.applicant.history.messages[0]) |
---|