source: main/waeup.custom/trunk/src/waeup/custom/students/tests/test_browser.py @ 7995

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

Adapt changes recently made in the base package.

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1## $Id: test_browser.py 7995 2012-03-28 06:23:25Z 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##
18import os
19import shutil
20import tempfile
21from hurry.workflow.interfaces import IWorkflowState
22from zope.component.hooks import setSite, clearSite
23from waeup.kofa.app import University
24from waeup.kofa.students.tests.test_browser import StudentsFullSetup
25from waeup.kofa.testing import FunctionalTestCase
26from waeup.kofa.students.batching import StudentProcessor as StudentProcessorBase
27from waeup.custom.students.batching import StudentProcessor
28from waeup.custom.testing import FunctionalLayer
29
30STUDENT_SAMPLE_DATA = open(
31    os.path.join(os.path.dirname(__file__), 'sample_student_data.csv'),
32    'rb').read()
33
34STUDENT_HEADER_FIELDS = STUDENT_SAMPLE_DATA.split(
35    '\n')[0].split(',')
36
37class StudentProcessorTest(FunctionalTestCase):
38    """Perform some batching tests.
39    """
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        super(StudentProcessorTest, self).setUp()
45        # Setup a sample site for each test
46        app = University()
47        self.dc_root = tempfile.mkdtemp()
48        app['datacenter'].setStoragePath(self.dc_root)
49
50        # Prepopulate the ZODB...
51        self.getRootFolder()['app'] = app
52        # we add the site immediately after creation to the
53        # ZODB. Catalogs and other local utilities are not setup
54        # before that step.
55        self.app = self.getRootFolder()['app']
56        # Set site here. Some of the following setup code might need
57        # to access grok.getSite() and should get our new app then
58        setSite(app)
59
60        self.processor_base = StudentProcessorBase()
61        self.processor = StudentProcessor()
62        self.workdir = tempfile.mkdtemp()
63        self.csv_file = os.path.join(self.workdir, 'sample_student_data.csv')
64        open(self.csv_file, 'wb').write(STUDENT_SAMPLE_DATA)
65
66    def tearDown(self):
67        super(StudentProcessorTest, self).tearDown()
68        shutil.rmtree(self.workdir)
69        shutil.rmtree(self.dc_root)
70        clearSite()
71        return
72
73    def test_import(self):
74        # We have an empty column 'date_of_birth' in  the import file.
75        # The original processor will fail because 'date_of_birth' is required
76        # in the base package.
77        num, num_warns, fin_file, fail_file = self.processor_base.doImport(
78            self.csv_file, STUDENT_HEADER_FIELDS)
79        self.assertEqual(num_warns,3)
80        assert len(self.app['students'].keys()) == 0
81        # The customized processor does not complain since 'date_of_birth' is
82        # not required in the custom package.
83        num, num_warns, fin_file, fail_file = self.processor.doImport(
84            self.csv_file, STUDENT_HEADER_FIELDS)
85        #print open(fail_file).read()
86        self.assertEqual(num_warns,0)
87        assert len(self.app['students'].keys()) == 3
88        shutil.rmtree(os.path.dirname(fin_file))
89
90
91class StudentUITests(StudentsFullSetup):
92    """Tests for customized student class views and pages
93    """
94
95    layer = FunctionalLayer
96
97    def test_manage_payments(self):
98        # Add missing configuration data
99        self.app['configuration']['2004'].gown_fee = 150.0
100        self.app['configuration']['2004'].transfer_fee = 90.0
101        self.app['configuration']['2004'].clearance_fee = 120.0
102        self.app['configuration']['2004'].maint_fee = 180.0
103
104        # Managers can add online payment tickets
105        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
106        self.browser.open(self.payments_path)
107        self.browser.getControl("Add online payment ticket").click()
108        self.browser.getControl("Create ticket").click()
109        self.assertMatches('...Amount could not be determined...',
110                           self.browser.contents)
111        IWorkflowState(self.student).setState('cleared')
112        self.browser.open(self.payments_path + '/addop')
113        self.browser.getControl("Create ticket").click()
114        self.assertMatches('...ticket created...',
115                           self.browser.contents)
116        ctrl = self.browser.getControl(name='val_id')
117        value = ctrl.options[0]
118        self.browser.getLink(value).click()
119        self.assertMatches('...Amount Authorized...',
120                           self.browser.contents)
121        # Set ticket paid
122        ticket = self.student['payments'].items()[0][1]
123        ticket.p_state = 'paid'
124        IWorkflowState(self.student).setState('returning')
125        self.browser.open(self.payments_path + '/addop')
126        self.browser.getControl("Create ticket").click()
127        self.assertMatches('...This type of payment has already been made...',
128                           self.browser.contents)
129        # Remove all payments so that we can add a school fee payment again
130        keys = [i for i in self.student['payments'].keys()]
131        for payment in keys:
132            del self.student['payments'][payment]
133        self.browser.open(self.payments_path + '/addop')
134        self.browser.getControl("Create ticket").click()
135        self.assertMatches('...ticket created...',
136                           self.browser.contents)
137        self.browser.open(self.payments_path + '/addop')
138        self.browser.getControl(name="form.p_category").value = ['gown']
139        self.browser.getControl("Create ticket").click()
140        self.browser.open(self.payments_path + '/addop')
141        self.browser.getControl(name="form.p_category").value = ['transfer']
142        self.browser.getControl("Create ticket").click()
143        self.browser.open(self.payments_path + '/addop')
144        self.browser.getControl(
145            name="form.p_category").value = ['bed_allocation']
146        self.browser.getControl("Create ticket").click()
147        self.browser.open(self.payments_path + '/addop')
148        self.browser.getControl(
149            name="form.p_category").value = ['hostel_maintenance']
150        self.browser.getControl("Create ticket").click()
151        self.browser.open(self.payments_path + '/addop')
152        self.browser.getControl(name="form.p_category").value = ['clearance']
153        self.browser.getControl("Create ticket").click()
154        self.certificate.study_mode = 'ug_pt'
155        self.browser.open(self.payments_path + '/addop')
156        self.browser.getControl(name="form.p_category").value = ['schoolfee']
157        self.browser.getControl("Create ticket").click()
158        self.assertMatches('...Amount could not be determined...',
159                           self.browser.contents)
160
161        # If the session configuration doesn't exist and error message will
162        # be shown
163        del self.app['configuration']['2004']
164        self.browser.open(self.payments_path)
165        self.browser.getControl("Add online payment ticket").click()
166        self.browser.getControl("Create ticket").click()
167        self.assertMatches('...Session configuration object is not...',
168                           self.browser.contents)
Note: See TracBrowser for help on using the repository browser.