source: main/waeup.futminna/trunk/src/waeup/futminna/students/tests/test_browser.py @ 9298

Last change on this file since 9298 was 9298, checked in by Henrik Bettermann, 12 years ago

Set payment ticket attributes properly.

  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1## $Id: test_browser.py 9298 2012-10-05 11:26:26Z 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
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 StudentsFullSetup
28from waeup.kofa.testing import FunctionalTestCase
29from waeup.kofa.interfaces import (
30    IExtFileStore, IFileStoreNameChooser)
31from waeup.kofa.students.interfaces import IStudentsUtils
32from waeup.futminna.testing import FunctionalLayer
33
34
35class StudentProcessorTest(FunctionalTestCase):
36    """Perform some batching tests.
37    """
38
39    layer = FunctionalLayer
40
41    def setUp(self):
42        super(StudentProcessorTest, self).setUp()
43        # Setup a sample site for each test
44        app = University()
45        self.dc_root = tempfile.mkdtemp()
46        app['datacenter'].setStoragePath(self.dc_root)
47
48        # Prepopulate the ZODB...
49        self.getRootFolder()['app'] = app
50        # we add the site immediately after creation to the
51        # ZODB. Catalogs and other local utilities are not setup
52        # before that step.
53        self.app = self.getRootFolder()['app']
54        # Set site here. Some of the following setup code might need
55        # to access grok.getSite() and should get our new app then
56        setSite(app)
57
58
59    def tearDown(self):
60        super(StudentProcessorTest, self).tearDown()
61        shutil.rmtree(self.workdir)
62        shutil.rmtree(self.dc_root)
63        clearSite()
64        return
65
66class StudentUITests(StudentsFullSetup):
67    """Tests for customized student class views and pages
68    """
69
70    layer = FunctionalLayer
71
72    def test_get_returning_data(self):
73        # Student is in level 100, session 2004 with verdict A
74        utils = getUtility(IStudentsUtils)
75        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
76        self.student['studycourse'].current_verdict = 'C'
77        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
78        self.student['studycourse'].current_verdict = 'D'
79        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
80        return
81
82    def test_set_payment_details(self):
83        self.app['configuration']['2004'].gown_fee = 150.0
84        self.app['configuration']['2004'].transfer_fee = 90.0
85        self.app['configuration']['2004'].booking_fee = 150.0
86        self.app['configuration']['2004'].maint_fee = 180.0
87        self.app['configuration']['2004'].clearance_fee = 120.0
88        utils = getUtility(IStudentsUtils)
89
90        error, payment = utils.setPaymentDetails('schoolfee',self.student)
91        self.assertEqual(payment, None)
92        self.assertEqual(error, u'Amount could not be determined.')
93
94        self.student.nationality = u'NG'
95
96        IWorkflowState(self.student).setState('cleared')
97        error, payment = utils.setPaymentDetails('schoolfee',self.student)
98        self.assertEqual(payment.p_level, 100)
99        self.assertEqual(payment.p_session, 2004)
100        self.assertEqual(payment.amount_auth, 37000.0)
101        self.assertEqual(payment.p_item, u'CERT1')
102        self.assertEqual(error, None)
103
104        self.certificate.study_mode = 'jm_ft'
105        error, payment = utils.setPaymentDetails('schoolfee',self.student)
106        self.assertEqual(payment.amount_auth, 72700.0)
107
108        IWorkflowState(self.student).setState('returning')
109        error, payment = utils.setPaymentDetails('schoolfee',self.student)
110        self.assertEqual(payment.p_level, 200)
111        self.assertEqual(payment.p_session, 2005)
112        self.assertEqual(payment.amount_auth, 37000.0)
113        self.assertEqual(payment.p_item, u'CERT1')
114        self.assertEqual(error, None)
115
116        self.certificate.study_mode = 'ug_ft'
117        error, payment = utils.setPaymentDetails('schoolfee',self.student)
118        self.assertEqual(payment.amount_auth, 20000.0)
119
120
121        error, payment = utils.setPaymentDetails('clearance',self.student)
122        self.assertEqual(payment.p_level, 100)
123        self.assertEqual(payment.p_session, 2004)
124        self.assertEqual(payment.amount_auth, 20000.0)
125        self.assertEqual(payment.p_item, u'CERT1')
126        self.assertEqual(error, None)
127
128        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
129        self.assertEqual(error, u'Previous session payment not yet implemented.')
130        return
Note: See TracBrowser for help on using the repository browser.