[7510] | 1 | # -*- coding: utf-8 -*- |
---|
| 2 | import unittest |
---|
[11589] | 3 | import grok |
---|
| 4 | from zope.component import getUtility, queryUtility, createObject |
---|
| 5 | from zope.catalog.interfaces import ICatalog |
---|
[11588] | 6 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[7811] | 7 | from waeup.kofa.students.utils import formatted_text |
---|
[11588] | 8 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[7510] | 9 | |
---|
| 10 | class 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') |
---|
[9911] | 18 | result5 = formatted_text(u'sample', color='red') |
---|
[7510] | 19 | self.assertTrue(isinstance(result1, unicode)) |
---|
| 20 | self.assertEqual( |
---|
[9911] | 21 | result1, u'<font color="black">sample</font>') |
---|
[7510] | 22 | self.assertEqual( |
---|
[9911] | 23 | result2, u'<font color="black">ümlaut</font>') |
---|
[7510] | 24 | self.assertEqual( |
---|
[9911] | 25 | result3, u'<font color="black">3</font>') |
---|
[7510] | 26 | self.assertEqual( |
---|
[9911] | 27 | result4, u'<font color="black">unicöde</font>') |
---|
[7510] | 28 | self.assertEqual( |
---|
[9911] | 29 | result5, u'<font color="red">sample</font>') |
---|
[7510] | 30 | return |
---|
[11588] | 31 | |
---|
| 32 | class 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) |
---|
[11589] | 41 | |
---|
| 42 | def test_setMatricNumber(self): |
---|
| 43 | site = grok.getSite() |
---|
| 44 | utils = getUtility(IStudentsUtils) |
---|
[11595] | 45 | # Matric number can't be set twice. |
---|
[11589] | 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 |
---|
[11595] | 51 | # Matric number can't be set if next_matric_integer is 0. |
---|
[11589] | 52 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
[11595] | 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) |
---|
[11589] | 58 | self.assertEqual(msg, None) |
---|
[11595] | 59 | self.assertEqual(mnumber, '1') |
---|
[11589] | 60 | self.assertEqual(self.student.matric_number, '1') |
---|
| 61 | self.assertEqual(site['configuration'].next_matric_integer, 2) |
---|
[11595] | 62 | # Student can be found in catalog with new matric number. |
---|
[11589] | 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) |
---|
[13225] | 73 | self.assertEqual(msg, 'Matriculation number 2 exists.') |
---|
[11589] | 74 | self.assertEqual(mnumber, None) |
---|
| 75 | self.assertEqual(self.student.matric_number, None) |
---|
[11590] | 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.') |
---|
[11589] | 82 | return |
---|
| 83 | |
---|
[15697] | 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 |
---|