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

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

Customize SPECIAL_HANDLING_DICT and getAccommodationDetails.

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1## $Id: test_browser.py 9402 2012-10-24 05:58:57Z 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.university.faculty import Faculty
28from waeup.kofa.university.department import Department
29from waeup.kofa.students.tests.test_browser import StudentsFullSetup
30from waeup.kofa.testing import FunctionalTestCase
31from waeup.kofa.interfaces import (
32    IExtFileStore, IFileStoreNameChooser)
33from waeup.kofa.students.interfaces import IStudentsUtils
34from waeup.futminna.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        # Create SSE faculty with certificate
78        self.app['faculties']['SSE'] = Faculty(code='SSE')
79        self.app['faculties']['SSE']['dep1'] = Department(code='dep1')
80        self.certificate2 = createObject('waeup.Certificate')
81        self.certificate2.code = u'CERT2'
82        self.certificate2.application_category = 'basic'
83        self.certificate2.study_mode = 'ug_ft'
84        self.certificate2.start_level = 100
85        self.certificate2.end_level = 300
86        self.app['faculties']['SSE']['dep1'].certificates.addCertificate(
87            self.certificate2)
88        # Set study course attributes of test student
89        self.student['studycourse'].certificate = self.certificate2
90        self.student['studycourse'].current_session = 2004
91        self.student['studycourse'].entry_session = 2004
92        self.student['studycourse'].current_verdict = 'A'
93        self.student['studycourse'].current_level = 100
94
95    def test_get_returning_data(self):
96        # Student is in level 100, session 2004 with verdict A
97        utils = getUtility(IStudentsUtils)
98        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
99        self.student['studycourse'].current_verdict = 'C'
100        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
101        self.student['studycourse'].current_verdict = 'D'
102        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
103        return
104
105    def test_set_payment_details(self):
106        self.app['configuration']['2004'].gown_fee = 150.0
107        self.app['configuration']['2004'].transfer_fee = 90.0
108        self.app['configuration']['2004'].booking_fee = 150.0
109        self.app['configuration']['2004'].maint_fee = 180.0
110        self.app['configuration']['2004'].clearance_fee = 120.0
111        utils = getUtility(IStudentsUtils)
112
113        error, payment = utils.setPaymentDetails('schoolfee',self.student)
114        self.assertEqual(payment, None)
115        self.assertEqual(error, u'Amount could not be determined.')
116
117        self.student.nationality = u'NG'
118
119        IWorkflowState(self.student).setState('cleared')
120        error, payment = utils.setPaymentDetails('schoolfee',self.student)
121        self.assertEqual(payment.p_level, 100)
122        self.assertEqual(payment.p_session, 2004)
123        self.assertEqual(payment.amount_auth, 37000.0)
124        self.assertEqual(payment.p_item, u'CERT2')
125        self.assertEqual(error, None)
126
127        self.certificate2.study_mode = 'jm_ft'
128        error, payment = utils.setPaymentDetails('schoolfee',self.student)
129        self.assertEqual(payment.amount_auth, 72700.0)
130
131        IWorkflowState(self.student).setState('returning')
132        error, payment = utils.setPaymentDetails('schoolfee',self.student)
133        self.assertEqual(payment.p_level, 200)
134        self.assertEqual(payment.p_session, 2005)
135        self.assertEqual(payment.amount_auth, 37000.0)
136        self.assertEqual(payment.p_item, u'CERT2')
137        self.assertEqual(error, None)
138
139        self.certificate2.study_mode = 'ug_ft'
140        error, payment = utils.setPaymentDetails('schoolfee',self.student)
141        self.assertEqual(payment.amount_auth, 20000.0)
142
143        error, payment = utils.setPaymentDetails('clearance',self.student)
144        self.assertEqual(payment.p_level, 100)
145        self.assertEqual(payment.p_session, 2004)
146        self.assertEqual(payment.amount_auth, 20000.0)
147        self.assertEqual(payment.p_item, u'CERT2')
148        self.assertEqual(error, None)
149
150        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
151        self.assertEqual(error, u'Previous session payment not yet implemented.')
152        return
153
154    def test_get_accommodation_details(self):
155        self.app['configuration']['2004'].gown_fee = 150.0
156        self.app['configuration']['2004'].transfer_fee = 90.0
157        self.app['configuration']['2004'].booking_fee = 150.0
158        self.app['configuration']['2004'].maint_fee = 180.0
159        self.app['configuration']['2004'].clearance_fee = 120.0
160        utils = getUtility(IStudentsUtils)
161
162        details = utils.getAccommodationDetails(self.student)
163        self.assertEqual(details['bt'], u'sse_male_fr')
Note: See TracBrowser for help on using the repository browser.