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

Last change on this file since 7886 was 7886, checked in by Henrik Bettermann, 13 years ago

Add browser test for InterswitchForm?.

  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1## $Id: tests.py 7886 2012-03-14 21:38:43Z 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
29from waeup.custom.configuration import SessionConfiguration
30
31STUDENT_SAMPLE_DATA = open(
32    os.path.join(os.path.dirname(__file__), 'sample_student_data.csv'),
33    'rb').read()
34
35STUDENT_HEADER_FIELDS = STUDENT_SAMPLE_DATA.split(
36    '\n')[0].split(',')
37
38class StudentImporterTest(FunctionalTestCase):
39    """Perform some batching tests.
40    """
41
42    layer = FunctionalLayer
43
44    def setUp(self):
45        super(StudentImporterTest, self).setUp()
46        # Setup a sample site for each test
47        app = University()
48        self.dc_root = tempfile.mkdtemp()
49        app['datacenter'].setStoragePath(self.dc_root)
50
51        # Prepopulate the ZODB...
52        self.getRootFolder()['app'] = app
53        # we add the site immediately after creation to the
54        # ZODB. Catalogs and other local utilities are not setup
55        # before that step.
56        self.app = self.getRootFolder()['app']
57        # Set site here. Some of the following setup code might need
58        # to access grok.getSite() and should get our new app then
59        setSite(app)
60
61        self.importer_base = StudentProcessorBase()
62        self.importer = StudentProcessor()
63        self.workdir = tempfile.mkdtemp()
64        self.csv_file = os.path.join(self.workdir, 'sample_student_data.csv')
65        open(self.csv_file, 'wb').write(STUDENT_SAMPLE_DATA)
66
67    def tearDown(self):
68        super(StudentImporterTest, self).tearDown()
69        shutil.rmtree(self.workdir)
70        shutil.rmtree(self.dc_root)
71        clearSite()
72        return
73
74    def test_import(self):
75        # We added empty columns 'nationality' and 'lga' to the import file.
76        # The original importer will fail because these fields are required
77        # in the base package.
78        num, num_warns, fin_file, fail_file = self.importer_base.doImport(
79            self.csv_file, STUDENT_HEADER_FIELDS)
80        self.assertEqual(num_warns,3)
81        assert len(self.app['students'].keys()) == 0
82        # The customized importer does not complain since both fields are
83        # not required in the custom package.
84        num, num_warns, fin_file, fail_file = self.importer.doImport(
85            self.csv_file, STUDENT_HEADER_FIELDS)
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
100        self.app['configuration']['2004'].transfer_fee = 90
101        self.app['configuration']['2004'].clearance_fee = 120
102        self.app['configuration']['2004'].maint_fee = 180
103
104        # Managers can add online payment tickets
105        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
106        self.browser.open(self.payments_student_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_student_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        payment_url = self.browser.url
122       
123        # Manager can access InterswitchForm
124        self.browser.getLink("CollegePAY", index=0).click()
125        self.assertMatches('...Total Amount Authorized:...',
126                           self.browser.contents)
127        self.assertMatches(
128            '...<input type="hidden" name="amount" value="4000000" />...',
129            self.browser.contents)
130
131        # Manager receives valid callback
132        self.browser.open(payment_url)
133        self.browser.getLink("Request CollegePAY callback").click()
134        self.assertMatches('...Valid callback received...',
135                          self.browser.contents)
136
137        self.browser.open(self.manage_student_path)
138        self.browser.getControl(
139            name="transition").value = ['pay_first_school_fee']
140        self.browser.getControl("Save").click()
141        # Reset to returning
142        self.browser.getControl(name="transition").value = ['reset6']
143        self.browser.getControl("Save").click()
144        self.browser.open(self.payments_student_path + '/addop')
145        self.browser.getControl("Create ticket").click()
146        self.assertMatches('...This type of payment has already been made...',
147                           self.browser.contents)
148        # Remove all payments so that we can add a school fee payment again
149        for payment in self.student['payments'].keys():
150            del self.student['payments'][payment]
151        self.browser.open(self.payments_student_path + '/addop')
152        self.browser.getControl("Create ticket").click()
153        self.assertMatches('...ticket created...',
154                           self.browser.contents)
155        self.browser.open(self.payments_student_path + '/addop')
156        self.browser.getControl(name="form.p_category").value = ['gown']
157        self.browser.getControl("Create ticket").click()
158        self.browser.open(self.payments_student_path + '/addop')
159        self.browser.getControl(name="form.p_category").value = ['transfer']
160        self.browser.getControl("Create ticket").click()
161        self.browser.open(self.payments_student_path + '/addop')
162        self.browser.getControl(
163            name="form.p_category").value = ['bed_allocation']
164        self.browser.getControl("Create ticket").click()
165        self.browser.open(self.payments_student_path + '/addop')
166        self.browser.getControl(
167            name="form.p_category").value = ['hostel_maintenance']
168        self.browser.getControl("Create ticket").click()
169        self.browser.open(self.payments_student_path + '/addop')
170        self.browser.getControl(name="form.p_category").value = ['clearance']
171        self.browser.getControl("Create ticket").click()
172        self.certificate.study_mode = 'ug_pt'
173        self.browser.open(self.payments_student_path + '/addop')
174        self.browser.getControl(name="form.p_category").value = ['schoolfee']
175        self.browser.getControl("Create ticket").click()
176        self.assertMatches('...Amount could not be determined...',
177                           self.browser.contents)
178
179        # If the session configuration doesn't exist and error message will
180        # be shown
181        del self.app['configuration']['2004']
182        self.browser.open(self.payments_student_path)
183        self.browser.getControl("Add online payment ticket").click()
184        self.browser.getControl("Create ticket").click()
185        self.assertMatches('...Session configuration object is not...',
186                           self.browser.contents)
187
188
Note: See TracBrowser for help on using the repository browser.