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

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

All fees must be float not int.

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1## $Id: test_browser.py 7928 2012-03-20 14:37:35Z 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 StudentImporterTest(FunctionalTestCase):
38    """Perform some batching tests.
39    """
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        super(StudentImporterTest, 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.importer_base = StudentProcessorBase()
61        self.importer = 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(StudentImporterTest, 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 added empty columns 'nationality' and 'lga' to the import file.
75        # The original importer will fail because these fields are required
76        # in the base package.
77        num, num_warns, fin_file, fail_file = self.importer_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 importer does not complain since both fields are
82        # not required in the custom package.
83        num, num_warns, fin_file, fail_file = self.importer.doImport(
84            self.csv_file, STUDENT_HEADER_FIELDS)
85        self.assertEqual(num_warns,0)
86        assert len(self.app['students'].keys()) == 3
87        shutil.rmtree(os.path.dirname(fin_file))
88
89
90class StudentUITests(StudentsFullSetup):
91    """Tests for customized student class views and pages
92    """
93
94    layer = FunctionalLayer
95
96    def test_manage_payments(self):
97        # Add missing configuration data
98        self.app['configuration']['2004'].gown_fee = 150.0
99        self.app['configuration']['2004'].transfer_fee = 90.0
100        self.app['configuration']['2004'].clearance_fee = 120.0
101        self.app['configuration']['2004'].maint_fee = 180.0
102
103        # Managers can add online payment tickets
104        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
105        self.browser.open(self.payments_student_path)
106        self.browser.getControl("Add online payment ticket").click()
107        self.browser.getControl("Create ticket").click()
108        self.assertMatches('...Amount could not be determined...',
109                           self.browser.contents)
110        IWorkflowState(self.student).setState('cleared')
111        self.browser.open(self.payments_student_path + '/addop')
112        self.browser.getControl("Create ticket").click()
113        self.assertMatches('...ticket created...',
114                           self.browser.contents)
115        ctrl = self.browser.getControl(name='val_id')
116        value = ctrl.options[0]
117        self.browser.getLink(value).click()
118        self.assertMatches('...Amount Authorized...',
119                           self.browser.contents)
120        # Set ticket paid
121        ticket = self.student['payments'].items()[0][1]
122        ticket.p_state = 'paid'
123        IWorkflowState(self.student).setState('returning')
124        self.browser.open(self.payments_student_path + '/addop')
125        self.browser.getControl("Create ticket").click()
126        self.assertMatches('...This type of payment has already been made...',
127                           self.browser.contents)
128        # Remove all payments so that we can add a school fee payment again
129        keys = [i for i in self.student['payments'].keys()]
130        for payment in keys:
131            del self.student['payments'][payment]
132        self.browser.open(self.payments_student_path + '/addop')
133        self.browser.getControl("Create ticket").click()
134        self.assertMatches('...ticket created...',
135                           self.browser.contents)
136        self.browser.open(self.payments_student_path + '/addop')
137        self.browser.getControl(name="form.p_category").value = ['gown']
138        self.browser.getControl("Create ticket").click()
139        self.browser.open(self.payments_student_path + '/addop')
140        self.browser.getControl(name="form.p_category").value = ['transfer']
141        self.browser.getControl("Create ticket").click()
142        self.browser.open(self.payments_student_path + '/addop')
143        self.browser.getControl(
144            name="form.p_category").value = ['bed_allocation']
145        self.browser.getControl("Create ticket").click()
146        self.browser.open(self.payments_student_path + '/addop')
147        self.browser.getControl(
148            name="form.p_category").value = ['hostel_maintenance']
149        self.browser.getControl("Create ticket").click()
150        self.browser.open(self.payments_student_path + '/addop')
151        self.browser.getControl(name="form.p_category").value = ['clearance']
152        self.browser.getControl("Create ticket").click()
153        self.certificate.study_mode = 'ug_pt'
154        self.browser.open(self.payments_student_path + '/addop')
155        self.browser.getControl(name="form.p_category").value = ['schoolfee']
156        self.browser.getControl("Create ticket").click()
157        self.assertMatches('...Amount could not be determined...',
158                           self.browser.contents)
159
160        # If the session configuration doesn't exist and error message will
161        # be shown
162        del self.app['configuration']['2004']
163        self.browser.open(self.payments_student_path)
164        self.browser.getControl("Add online payment ticket").click()
165        self.browser.getControl("Create ticket").click()
166        self.assertMatches('...Session configuration object is not...',
167                           self.browser.contents)
168
169
Note: See TracBrowser for help on using the repository browser.