source: main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_browser.py @ 15501

Last change on this file since 15501 was 9127, checked in by Henrik Bettermann, 12 years ago

Quick shot: Remove single history messages through URL. All views in the utils.browser module should be replaced by proper form pages.

  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1## $Id: test_browser.py 9127 2012-08-30 08:55:31Z 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        cat.clear()
95        results = cat.searchResults(student_id=(None, None))
96        self.assertEqual(len(results),0)
97        self.browser.open('http://localhost/app/reindex?ctlg=students')
98        self.assertTrue('1 students re-indexed' in self.browser.contents)
99        results = cat.searchResults(student_id=(None, None))
100        self.assertEqual(len(results),1)
101
102class ApplicantUtilsUITests(ApplicantsFullSetup):
103
104    layer = FunctionalLayer
105
106    def test_modify_all_applicant_history(self):
107        self.assertTrue('Application initialized by system' in
108            self.applicant.history.messages[0])
109        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
110        self.browser.open('http://localhost/app/modify_applicant_history')
111        self.assertTrue(
112            'Syntax: /modify_applicant_history?old=[old string]&new=[new string]'
113            in self.browser.contents)
114        self.browser.open(
115            'http://localhost/app/modify_applicant_history?old=by system&new=by me')
116        self.assertTrue('Finished' in self.browser.contents)
117        self.assertTrue('Application initialized by me' in
118            self.applicant.history.messages[0])
119
120    def test_remove_applicant_history_message(self):
121        self.assertTrue('Application initialized by system' in
122            self.applicant.history.messages[0])
123        self.assertEqual(len(self.applicant.history.messages),1)
124        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
125        self.browser.open('http://localhost/app/remove_applicant_history_message')
126        self.assertTrue(
127            'Syntax: /remove_applicant_history_message?applicant_id=[id]&number=[line number, starting with 0]'
128            in self.browser.contents)
129        self.browser.open(
130            'http://localhost/app/remove_applicant_history_message?applicant_id=%s&number=0' % self.applicant.applicant_id)
131        self.assertTrue('Finished' in self.browser.contents)
132        self.assertEqual(len(self.applicant.history.messages),0)
133        logfile = os.path.join(
134            self.app['datacenter'].storage, 'logs', 'main.log')
135        logcontent = open(logfile).read()
136        self.assertMatches(
137            "...zope.mgr - line '<YYYY-MM-DD hh:mm:ss> UTC - "
138            "Application initialized by system' removed in %s history"
139            % self.applicant.applicant_id, logcontent)
Note: See TracBrowser for help on using the repository browser.