[11543] | 1 | import datetime |
---|
| 2 | from zope.component import queryUtility |
---|
| 3 | from zope.interface.verify import verifyObject, verifyClass |
---|
| 4 | from waeup.kofa.interfaces import ICSVExporter |
---|
| 5 | from waeup.kofa.schoolgrades import ResultEntry |
---|
[14457] | 6 | from waeup.kofa.students.tests.test_batching import ( |
---|
| 7 | StudentImportExportSetup, curr_year) |
---|
[15563] | 8 | from kofacustom.iuokada.utils.utils import CustomKofaUtils |
---|
| 9 | from kofacustom.iuokada.students.export import ( |
---|
[12878] | 10 | CustomStudentExporter, CustomStudentPaymentExporter) |
---|
[15563] | 11 | from kofacustom.iuokada.testing import FunctionalLayer |
---|
[11543] | 12 | |
---|
| 13 | |
---|
[12084] | 14 | class CustomStudentExporterTest(StudentImportExportSetup): |
---|
[11543] | 15 | |
---|
| 16 | layer = FunctionalLayer |
---|
| 17 | |
---|
| 18 | def setUp(self): |
---|
[12084] | 19 | super(CustomStudentExporterTest, self).setUp() |
---|
[11543] | 20 | self.setup_for_export() |
---|
| 21 | result_entry = ResultEntry( |
---|
| 22 | CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0], |
---|
| 23 | CustomKofaUtils.EXAM_GRADES[0][0] |
---|
| 24 | ) |
---|
| 25 | self.student.alr_results = [ |
---|
| 26 | result_entry] |
---|
| 27 | self.student.fst_sit_results = [ |
---|
| 28 | result_entry] |
---|
| 29 | self.student.scd_sit_results = [ |
---|
| 30 | result_entry] |
---|
| 31 | return |
---|
| 32 | |
---|
| 33 | def test_ifaces(self): |
---|
| 34 | # make sure we fullfill interface contracts |
---|
[12084] | 35 | obj = CustomStudentExporter() |
---|
[11543] | 36 | verifyObject(ICSVExporter, obj) |
---|
[12084] | 37 | verifyClass(ICSVExporter, CustomStudentExporter) |
---|
[11543] | 38 | return |
---|
| 39 | |
---|
| 40 | |
---|
[16403] | 41 | def test_export_all(self): |
---|
[11543] | 42 | # we can really export students |
---|
| 43 | # set values we can expect in export file |
---|
| 44 | self.setup_student(self.student) |
---|
[12084] | 45 | exporter = CustomStudentExporter() |
---|
[11543] | 46 | exporter.export_all(self.app, self.outfile) |
---|
| 47 | result = open(self.outfile, 'rb').read() |
---|
[16403] | 48 | self.assertTrue('entry_session' in result) |
---|
[11543] | 49 | return |
---|
| 50 | |
---|
[12878] | 51 | class CustomStudentPaymentExporterTest(StudentImportExportSetup): |
---|
[11543] | 52 | |
---|
| 53 | layer = FunctionalLayer |
---|
| 54 | |
---|
| 55 | def setUp(self): |
---|
[12878] | 56 | super(CustomStudentPaymentExporterTest, self).setUp() |
---|
[11543] | 57 | self.setup_for_export() |
---|
| 58 | return |
---|
| 59 | |
---|
| 60 | def test_ifaces(self): |
---|
| 61 | # make sure we fullfill interface contracts |
---|
[12878] | 62 | obj = CustomStudentPaymentExporter() |
---|
[11543] | 63 | verifyObject(ICSVExporter, obj) |
---|
[12878] | 64 | verifyClass(ICSVExporter, CustomStudentPaymentExporter) |
---|
[11543] | 65 | return |
---|
| 66 | |
---|
| 67 | def test_export_all(self): |
---|
| 68 | # we can really export students |
---|
| 69 | # set values we can expect in export file |
---|
| 70 | self.setup_student(self.student) |
---|
[16434] | 71 | self.student['payments']['my-payment'].r_company = 'interswitch' |
---|
| 72 | self.student['payments']['my-payment'].p_option = 'first' |
---|
[11543] | 73 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
[12878] | 74 | exporter = CustomStudentPaymentExporter() |
---|
[11543] | 75 | exporter.export_all(self.app, self.outfile) |
---|
| 76 | result = open(self.outfile, 'rb').read() |
---|
| 77 | self.assertMatches( |
---|
[17294] | 78 | 'ac,amount_auth,creation_date,gateway_amt,net_amt,p_category,p_combi,p_currency,p_current,' |
---|
[16434] | 79 | 'p_id,p_item,p_level,p_option,p_session,p_state,payment_date,provider_amt,' |
---|
[11543] | 80 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
---|
[17294] | 81 | 'r_pay_reference,r_payment_link,thirdparty_amt,student_id,state,' |
---|
[16665] | 82 | 'current_session,entry_session,faculty,department\r\n' |
---|
[17294] | 83 | '666,12.12,%s-04-01 13:12:01#,,,schoolfee,[],,1,my-id,p-item,' |
---|
[16434] | 84 | '100,first,%s,paid,%s-04-01 14:12:01#,,12.12,' |
---|
[17294] | 85 | '789,r-code,interswitch,,,,,A111111,created,2012,2010,' |
---|
[16665] | 86 | 'Unnamed Faculty,Unnamed Department\r\n' |
---|
[14457] | 87 | % (curr_year-6, curr_year-6, curr_year-6), result |
---|
[11543] | 88 | ) |
---|
| 89 | return |
---|