source: main/waeup.kofa/branches/uli-fix-zc-async/src/waeup/kofa/utils/tests/test_browser.py @ 17341

Last change on this file since 17341 was 16037, checked in by Henrik Bettermann, 5 years ago

Fix test.

  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1## $Id: test_browser.py 16037 2020-03-13 10:55:28Z 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"""
19Test the student-related UI components.
20"""
21import shutil
22import tempfile
23import pytz
24from datetime import datetime, timedelta
25from StringIO import StringIO
26import os
27import grok
28from zope.event import notify
29from zope.component import createObject, queryUtility
30from zope.component.hooks import setSite, clearSite
31from zope.catalog.interfaces import ICatalog
32from zope.security.interfaces import Unauthorized
33from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
34
35from waeup.kofa.utils.browser import replaceStudentMessages
36from waeup.kofa.students.tests.test_browser import StudentsFullSetup
37from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
38
39class 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_remove_student_history_message(self):
65        self.assertTrue('Record created by system' in
66            self.student.history.messages[0])
67        self.assertEqual(len(self.student.history.messages),1)
68        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
69        self.browser.open('http://localhost/app/remove_student_history_message')
70        self.assertTrue(
71            'Syntax: /remove_student_history_message?student_id=[id]&number=[line number, starting with 0]'
72            in self.browser.contents)
73        self.browser.open(
74            'http://localhost/app/remove_student_history_message?student_id=%s&number=0' % self.student.student_id)
75        self.assertTrue('Finished' in self.browser.contents)
76        self.assertEqual(len(self.student.history.messages),0)
77        logfile = os.path.join(
78            self.app['datacenter'].storage, 'logs', 'main.log')
79        logcontent = open(logfile).read()
80        self.assertMatches(
81            "...zope.mgr - line '<YYYY-MM-DD hh:mm:ss> UTC - "
82            "Record created by system' removed in K1000000 history",
83            logcontent)
84
85    def test_reindex(self):
86        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
87        self.browser.open('http://localhost/app/reindex')
88        self.assertTrue('No catalog name provided' in self.browser.contents)
89        self.browser.open('http://localhost/app/reindex?ctlg=xyz')
90        self.assertTrue('xyz_catalog does not exist' in self.browser.contents)
91        cat = queryUtility(ICatalog, name='students_catalog')
92        results = cat.searchResults(student_id=(None, None))
93        self.assertEqual(len(results),1)
94        self.browser.open('http://localhost/app/reindex?ctlg=students')
95        self.assertTrue('1 students re-indexed' in self.browser.contents)
96        cat.clear()
97        results = cat.searchResults(student_id=(None, None))
98        self.assertEqual(len(results),0)
99        self.browser.open('http://localhost/app/reindex?ctlg=students')
100        # No docids found, the new reindex method does only reindex existing
101        # catalog entries.
102        self.assertTrue('0 students re-indexed' in self.browser.contents)
103        results = cat.searchResults(student_id=(None, None))
104        self.assertEqual(len(results),0)
105
106class ApplicantUtilsUITests(ApplicantsFullSetup):
107
108    layer = FunctionalLayer
109
110    def test_modify_all_applicant_history(self):
111        self.assertTrue('Application initialized by system' in
112            self.applicant.history.messages[0])
113        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
114        self.browser.open('http://localhost/app/modify_applicant_history')
115        self.assertTrue(
116            'Syntax: /modify_applicant_history?old=[old string]&new=[new string]'
117            in self.browser.contents)
118        self.browser.open(
119            'http://localhost/app/modify_applicant_history?old=by system&new=by me')
120        self.assertTrue('Finished' in self.browser.contents)
121        self.assertTrue('Application initialized by me' in
122            self.applicant.history.messages[0])
123
124    def test_remove_applicant_history_message(self):
125        self.assertTrue('Application initialized by system' in
126            self.applicant.history.messages[0])
127        self.assertEqual(len(self.applicant.history.messages),1)
128        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
129        self.browser.open('http://localhost/app/remove_applicant_history_message')
130        self.assertTrue(
131            'Syntax: /remove_applicant_history_message?applicant_id=[id]&number=[line number, starting with 0]'
132            in self.browser.contents)
133        self.browser.open(
134            'http://localhost/app/remove_applicant_history_message?applicant_id=%s&number=0' % self.applicant.applicant_id)
135        self.assertTrue('Finished' in self.browser.contents)
136        self.assertEqual(len(self.applicant.history.messages),0)
137        logfile = os.path.join(
138            self.app['datacenter'].storage, 'logs', 'main.log')
139        logcontent = open(logfile).read()
140        self.assertMatches(
141            "...zope.mgr - line '<YYYY-MM-DD hh:mm:ss> UTC - "
142            "Application initialized by system' removed in %s history"
143            % self.applicant.applicant_id, logcontent)
Note: See TracBrowser for help on using the repository browser.