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

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

Uups, that was the wrong name.

  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1## $Id: test_browser.py 7893 2012-03-16 07:20:30Z 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 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
108    def test_manage_payments(self):
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
114
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()
120        self.assertMatches('...Amount could not be determined...',
121                           self.browser.contents)
122        IWorkflowState(self.student).setState('cleared')
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)
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)
132        # Set ticket paid
133        ticket = self.student['payments'].items()[0][1]
134        ticket.p_state = 'paid'
135        IWorkflowState(self.student).setState('returning')
136        self.browser.open(self.payments_student_path + '/addop')
137        self.browser.getControl("Create ticket").click()
138        self.assertMatches('...This type of payment has already been made...',
139                           self.browser.contents)
140        # Remove all payments so that we can add a school fee payment again
141        keys = [i for i in self.student['payments'].keys()]
142        for payment in keys:
143            del self.student['payments'][payment]
144        self.browser.open(self.payments_student_path + '/addop')
145        self.browser.getControl("Create ticket").click()
146        self.assertMatches('...ticket created...',
147                           self.browser.contents)
148        self.browser.open(self.payments_student_path + '/addop')
149        self.browser.getControl(name="form.p_category").value = ['gown']
150        self.browser.getControl("Create ticket").click()
151        self.browser.open(self.payments_student_path + '/addop')
152        self.browser.getControl(name="form.p_category").value = ['transfer']
153        self.browser.getControl("Create ticket").click()
154        self.browser.open(self.payments_student_path + '/addop')
155        self.browser.getControl(
156            name="form.p_category").value = ['bed_allocation']
157        self.browser.getControl("Create ticket").click()
158        self.browser.open(self.payments_student_path + '/addop')
159        self.browser.getControl(
160            name="form.p_category").value = ['hostel_maintenance']
161        self.browser.getControl("Create ticket").click()
162        self.browser.open(self.payments_student_path + '/addop')
163        self.browser.getControl(name="form.p_category").value = ['clearance']
164        self.browser.getControl("Create ticket").click()
165        self.certificate.study_mode = 'ug_pt'
166        self.browser.open(self.payments_student_path + '/addop')
167        self.browser.getControl(name="form.p_category").value = ['schoolfee']
168        self.browser.getControl("Create ticket").click()
169        self.assertMatches('...Amount could not be determined...',
170                           self.browser.contents)
171
172        # If the session configuration doesn't exist and error message will
173        # be shown
174        del self.app['configuration']['2004']
175        self.browser.open(self.payments_student_path)
176        self.browser.getControl("Add online payment ticket").click()
177        self.browser.getControl("Create ticket").click()
178        self.assertMatches('...Session configuration object is not...',
179                           self.browser.contents)
180
181
Note: See TracBrowser for help on using the repository browser.