source: main/waeup.aaua/trunk/src/waeup/aaua/students/tests/test_browser.py

Last change on this file was 10192, checked in by Henrik Bettermann, 11 years ago

Only ug_pt students get the reduction?!

  • Property svn:keywords set to Id
File size: 7.7 KB
Line 
1## $Id: test_browser.py 10192 2013-05-22 12:48:32Z 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 StringIO import StringIO
22from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
23from zope.component.hooks import setSite, clearSite
24from zope.component import getUtility, createObject
25from zope.interface import verify
26from waeup.kofa.app import University
27from waeup.kofa.students.tests.test_browser import (
28    StudentsFullSetup, SAMPLE_IMAGE)
29from waeup.kofa.students.accommodation import BedTicket
30from waeup.kofa.testing import FunctionalTestCase
31from waeup.kofa.interfaces import (
32    IExtFileStore, IFileStoreNameChooser)
33from waeup.kofa.students.interfaces import IStudentsUtils
34from waeup.aaua.testing import FunctionalLayer
35
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
61    def tearDown(self):
62        super(StudentProcessorTest, self).tearDown()
63        shutil.rmtree(self.workdir)
64        shutil.rmtree(self.dc_root)
65        clearSite()
66        return
67
68class StudentUITests(StudentsFullSetup):
69    """Tests for customized student class views and pages
70    """
71
72    layer = FunctionalLayer
73
74    def setUp(self):
75        super(StudentUITests, self).setUp()
76
77        bedticket = BedTicket()
78        bedticket.booking_session = 2004
79        bedticket.bed_type = u'any bed type'
80        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
81        bedticket.bed_coordinates = u'My bed coordinates'
82        self.student['accommodation'].addBedTicket(bedticket)
83
84    def test_student_start_clearance(self):
85        self.browser.open(self.login_path)
86        self.browser.getControl(name="form.login").value = self.student_id
87        self.browser.getControl(name="form.password").value = 'spwd'
88        self.browser.getControl("Login").click()
89
90        IWorkflowInfo(self.student).fireTransition('admit')
91        self.browser.open(self.student_path + '/change_portrait')
92        image = open(SAMPLE_IMAGE, 'rb')
93        ctrl = self.browser.getControl(name='passportuploadedit')
94        file_ctrl = ctrl.mech_control
95        file_ctrl.add_file(image, filename='my_photo.jpg')
96        self.browser.getControl(
97            name='upload_passportuploadedit').click()
98        self.browser.open(self.student_path + '/start_clearance')
99        # In AAUA the students can just start clearance without entering
100        # an activation code.
101        self.browser.getControl("Start clearance now").click()
102        self.assertMatches('...Clearance process has been started...',
103                           self.browser.contents)
104
105    def test_next_session_allowed(self):
106        # Let's see if next_session_allowed works as expected
107        # A, ug_ft, 100
108        IWorkflowState(self.student).setState('returning')
109        self.assertTrue(self.student['studycourse'].next_session_allowed)
110        # Uniben special PG programmes have the same workflow
111        # as UG students
112        self.certificate.study_mode = 'special_pg'
113        self.assertTrue(self.student['studycourse'].next_session_allowed)
114        IWorkflowState(self.student).setState('school fee paid')
115        self.assertFalse(self.student['studycourse'].next_session_allowed)
116        # Now we convert the certificate into a 'regular
117        # postgraduate certificate ...
118        self.certificate.study_mode = 'pg_xx'
119        # ... and voila next session registration is allowed
120        self.assertTrue(self.student['studycourse'].next_session_allowed)
121
122    def test_set_payment_details(self):
123        self.certificate.school_fee_1 = 100.0
124        self.certificate.school_fee_2 = 200.0
125        utils = getUtility(IStudentsUtils)
126
127        IWorkflowState(self.student).setState('cleared')
128        self.certificate.study_mode = 'ug_ft'
129        error, payment = utils.setPaymentDetails('schoolfee',self.student)
130        self.assertEqual(payment.p_level, 100)
131        self.assertEqual(payment.p_session, 2004)
132        self.assertEqual(payment.amount_auth, 100.0)
133        self.assertEqual(payment.p_item, u'CERT1')
134        self.assertEqual(error, None)
135
136        IWorkflowState(self.student).setState('returning')
137        configuration = createObject('waeup.SessionConfiguration')
138        configuration.academic_session = 2005
139        self.app['configuration'].addSessionConfiguration(configuration)
140        error, payment = utils.setPaymentDetails('schoolfee',self.student)
141        self.assertEqual(payment.p_level, 200)
142        self.assertEqual(payment.p_session, 2005)
143        self.assertEqual(payment.amount_auth, 200.0)
144        self.assertEqual(payment.p_item, u'CERT1')
145        self.assertEqual(error, None)
146
147        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
148        self.assertEqual(error, u'Payment by instalments not allowed.')
149        self.certificate.ratio = 0.0
150        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
151        self.assertEqual(error, u'Payment by instalments not allowed.')
152        error, payment = utils.setPaymentDetails('schoolfee_2',self.student)
153        self.assertEqual(error, u'Payment by instalments not allowed.')
154        self.certificate.ratio = 0.4
155        error, payment = utils.setPaymentDetails('schoolfee',self.student)
156        self.assertEqual(error, u'Payment by instalments required.')
157        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
158        self.assertEqual(payment.amount_auth, 80.0)
159        IWorkflowState(self.student).setState('cleared')
160        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
161        self.assertEqual(payment.amount_auth, 40.0)
162
163        # schoolfee_2 payment is state-independent
164        self.student['studycourse'].entry_session = 2003
165        error, payment = utils.setPaymentDetails('schoolfee_2',self.student)
166        self.assertEqual(payment.amount_auth, 120.0)
167        self.student['studycourse'].entry_session = 2004
168        error, payment = utils.setPaymentDetails('schoolfee_2',self.student)
169        self.assertEqual(payment.amount_auth, 60.0)
170
171        # Returning students with entry session 2005-2007
172        # and study mode ug_pt get a reduction of 20000
173        self.certificate.study_mode = 'ug_pt'
174        IWorkflowState(self.student).setState('returning')
175        self.student['studycourse'].entry_session = 2005
176        error, payment = utils.setPaymentDetails('schoolfee_1',self.student)
177        self.assertEqual(payment.amount_auth, -19920.0)
Note: See TracBrowser for help on using the repository browser.