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

Last change on this file since 7890 was 7890, checked in by Henrik Bettermann, 15 years ago

Setup module for Interswitch components.

Do not display the base package callback button in custom pages.

  • Property svn:keywords set to Id
File size: 9.5 KB
RevLine 
[7419]1## $Id: tests.py 7890 2012-03-16 06:26:17Z 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##
[7604]18import os
19import shutil
20import tempfile
[7886]21from hurry.workflow.interfaces import IWorkflowState
[7604]22from zope.component.hooks import setSite, clearSite
[7822]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
[7604]27from waeup.custom.students.batching import StudentProcessor
[6903]28from waeup.custom.testing import FunctionalLayer
[6925]29from waeup.custom.configuration import SessionConfiguration
[6902]30
[7604]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
[6902]91class StudentUITests(StudentsFullSetup):
[7604]92    """Tests for customized student class views and pages
93    """
[6902]94
95    layer = FunctionalLayer
96
[7889]97    def callback_url(self, payment_url, resp, apprAmt):
98        return payment_url + (
99            '/callback?echo=' +
100            '&resp=%s' +
101            '&desc=Something went wrong' +
102            '&txnRef=p1331792385335' +
103            '&payRef=' + '&retRef=' +
104            '&cardNum=0' +
105            '&apprAmt=%s' +
106            '&url=http://xyz') % (resp, apprAmt)
107
[6902]108    def test_manage_payments(self):
[7021]109        # Add missing configuration data
110        self.app['configuration']['2004'].gown_fee = 150
111        self.app['configuration']['2004'].transfer_fee = 90
112        self.app['configuration']['2004'].clearance_fee = 120
113        self.app['configuration']['2004'].maint_fee = 180
[6925]114
[6926]115        # Managers can add online payment tickets
116        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
117        self.browser.open(self.payments_student_path)
118        self.browser.getControl("Add online payment ticket").click()
119        self.browser.getControl("Create ticket").click()
[6925]120        self.assertMatches('...Amount could not be determined...',
[6902]121                           self.browser.contents)
[7886]122        IWorkflowState(self.student).setState('cleared')
[6902]123        self.browser.open(self.payments_student_path + '/addop')
124        self.browser.getControl("Create ticket").click()
125        self.assertMatches('...ticket created...',
126                           self.browser.contents)
[7419]127        ctrl = self.browser.getControl(name='val_id')
128        value = ctrl.options[0]
129        self.browser.getLink(value).click()
130        self.assertMatches('...Amount Authorized...',
131                           self.browser.contents)
[7886]132        payment_url = self.browser.url
133       
134        # Manager can access InterswitchForm
135        self.browser.getLink("CollegePAY", index=0).click()
136        self.assertMatches('...Total Amount Authorized:...',
137                           self.browser.contents)
138        self.assertMatches(
139            '...<input type="hidden" name="amount" value="4000000" />...',
140            self.browser.contents)
141
142        # Manager receives valid callback
[7889]143        #self.browser.open(payment_url)
144        #self.browser.getLink("Request CollegePAY callback").click()
145
146        self.browser.open(self.callback_url(payment_url, 'XX', '300'))
147        self.assertMatches('...Unsuccessful callback: Something went wrong...',
148                          self.browser.contents)
149        self.assertMatches('...Failed...',
150                           self.browser.contents)
151        self.browser.open(self.payments_student_path + '/addop')
152        self.browser.getControl("Create ticket").click()
153        ctrl = self.browser.getControl(name='val_id')
154        self.browser.open(payment_url + '/callback')
[7890]155        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
[7889]156                          self.browser.contents)
157        self.assertMatches('...Failed...',
158                           self.browser.contents)
159        self.browser.open(self.callback_url(payment_url, '00', '300'))
[7419]160        self.assertMatches('...Valid callback received...',
161                          self.browser.contents)
[6925]162        self.browser.open(self.manage_student_path)
[7021]163        self.browser.getControl(
164            name="transition").value = ['pay_first_school_fee']
[6925]165        self.browser.getControl("Save").click()
[7419]166        # Reset to returning
[6925]167        self.browser.getControl(name="transition").value = ['reset6']
168        self.browser.getControl("Save").click()
169        self.browser.open(self.payments_student_path + '/addop')
170        self.browser.getControl("Create ticket").click()
[7419]171        self.assertMatches('...This type of payment has already been made...',
[7146]172                           self.browser.contents)
173        # Remove all payments so that we can add a school fee payment again
[7889]174        keys = [i for i in self.student['payments'].keys()]
175        for payment in keys:
[7146]176            del self.student['payments'][payment]
177        self.browser.open(self.payments_student_path + '/addop')
178        self.browser.getControl("Create ticket").click()
[6925]179        self.assertMatches('...ticket created...',
180                           self.browser.contents)
[6926]181        self.browser.open(self.payments_student_path + '/addop')
182        self.browser.getControl(name="form.p_category").value = ['gown']
183        self.browser.getControl("Create ticket").click()
184        self.browser.open(self.payments_student_path + '/addop')
185        self.browser.getControl(name="form.p_category").value = ['transfer']
186        self.browser.getControl("Create ticket").click()
187        self.browser.open(self.payments_student_path + '/addop')
[7021]188        self.browser.getControl(
189            name="form.p_category").value = ['bed_allocation']
[6926]190        self.browser.getControl("Create ticket").click()
[6950]191        self.browser.open(self.payments_student_path + '/addop')
[7021]192        self.browser.getControl(
193            name="form.p_category").value = ['hostel_maintenance']
194        self.browser.getControl("Create ticket").click()
195        self.browser.open(self.payments_student_path + '/addop')
[6950]196        self.browser.getControl(name="form.p_category").value = ['clearance']
197        self.browser.getControl("Create ticket").click()
[6926]198        self.certificate.study_mode = 'ug_pt'
199        self.browser.open(self.payments_student_path + '/addop')
200        self.browser.getControl(name="form.p_category").value = ['schoolfee']
201        self.browser.getControl("Create ticket").click()
202        self.assertMatches('...Amount could not be determined...',
203                           self.browser.contents)
204
[7021]205        # If the session configuration doesn't exist and error message will
206        # be shown
207        del self.app['configuration']['2004']
208        self.browser.open(self.payments_student_path)
209        self.browser.getControl("Add online payment ticket").click()
210        self.browser.getControl("Create ticket").click()
211        self.assertMatches('...Session configuration object is not...',
212                           self.browser.contents)
[6926]213
[7021]214
Note: See TracBrowser for help on using the repository browser.