source: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_utils.py @ 16901

Last change on this file since 16901 was 15697, checked in by Henrik Bettermann, 5 years ago

Add missing test.

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1# -*- coding: utf-8 -*-
2import unittest
3import grok
4from zope.component import getUtility, queryUtility, createObject
5from zope.catalog.interfaces import ICatalog
6from waeup.kofa.students.interfaces import IStudentsUtils
7from waeup.kofa.students.utils import formatted_text
8from waeup.kofa.students.tests.test_browser import StudentsFullSetup
9
10class FormatterTests(unittest.TestCase):
11
12    def test_formatted_text(self):
13        # we can format strings, unicode and things convertable to unicode.
14        result1 = formatted_text('sample')
15        result2 = formatted_text('ümlaut')
16        result3 = formatted_text(3)
17        result4 = formatted_text(u'unicöde')
18        result5 = formatted_text(u'sample', color='red')
19        self.assertTrue(isinstance(result1, unicode))
20        self.assertEqual(
21            result1, u'<font color="black">sample</font>')
22        self.assertEqual(
23            result2, u'<font color="black">ümlaut</font>')
24        self.assertEqual(
25            result3, u'<font color="black">3</font>')
26        self.assertEqual(
27            result4, u'<font color="black">unicöde</font>')
28        self.assertEqual(
29            result5, u'<font color="red">sample</font>')
30        return
31
32class StudentsUtilsTests(StudentsFullSetup):
33
34    def test_setReturningData(self):
35        utils = getUtility(IStudentsUtils)
36        self.student['studycourse'].current_level = 600
37        utils.setReturningData(self.student)
38        # The new level exceeds the certificates end_level.
39        # In this case current_level remains unchanged and no error is raised.
40        self.assertEqual(self.student['studycourse'].current_level, 600)
41
42    def test_setMatricNumber(self):
43        site = grok.getSite()
44        utils = getUtility(IStudentsUtils)
45        # Matric number can't be set twice.
46        msg, mnumber = utils.setMatricNumber(self.student)
47        self.assertEqual(msg, 'Matriculation number already set.')
48        self.assertEqual(mnumber, None)
49        self.assertEqual(self.student.matric_number, '234')
50        self.student.matric_number = None
51        # Matric number can't be set if next_matric_integer is 0.
52        msg, mnumber = utils.setMatricNumber(self.student)
53        self.assertEqual(msg, 'Matriculation number cannot be set.')
54        self.assertEqual(mnumber, None)
55        site['configuration'].next_matric_integer = 1
56        # Now all requirements are met and matric number can be set.
57        msg, mnumber = utils.setMatricNumber(self.student)
58        self.assertEqual(msg, None)
59        self.assertEqual(mnumber, '1')
60        self.assertEqual(self.student.matric_number, '1')
61        self.assertEqual(site['configuration'].next_matric_integer, 2)
62        # Student can be found in catalog with new matric number.
63        cat = queryUtility(ICatalog, name='students_catalog')
64        results = list(cat.searchResults(matric_number=('1', '1')))
65        self.assertEqual(self.student,results[0])
66        # Add another student.
67        another_student = createObject('waeup.Student')
68        another_student.matric_number = u'2'
69        self.app['students'].addStudent(another_student)
70        # Matric number can't be assigned twice.
71        self.student.matric_number = None
72        msg, mnumber = utils.setMatricNumber(self.student)
73        self.assertEqual(msg, 'Matriculation number 2 exists.')
74        self.assertEqual(mnumber, None)
75        self.assertEqual(self.student.matric_number, None)
76        # Certificate must be set.
77        self.student.matric_number = None
78        another_student.matric_number = u'999'
79        self.student['studycourse'].certificate = None
80        msg, mnumber = utils.setMatricNumber(self.student)
81        self.assertEqual(msg, 'No certificate assigned.')
82        return
83
84    def test_set_payment_details(self):
85        self.app['configuration']['2004'].gown_fee = 150.0
86        self.app['configuration']['2004'].transcript_fee = 90.0
87        self.app['configuration']['2004'].late_registration_fee = 180.0
88        utils = getUtility(IStudentsUtils)
89        error, payment = utils.setPaymentDetails(
90            'combi',self.student, None, None,
91            ['gown', 'transcript', 'late_registration'])
92        self.assertEqual(payment.p_level, 100)
93        self.assertEqual(payment.p_session, 2004)
94        self.assertEqual(payment.amount_auth, 420.0)
95        self.assertEqual(payment.p_item,
96            u'Gown Hire Fee + Transcript Fee + Late Course Registration Fee')
97        self.assertEqual(payment.p_combi,
98            ['gown', 'transcript', 'late_registration'])
99        return
Note: See TracBrowser for help on using the repository browser.