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 |
---|
6 | from waeup.kofa.students.tests.test_batching import ( |
---|
7 | StudentImportExportSetup, curr_year) |
---|
8 | from kofacustom.iuokada.utils.utils import CustomKofaUtils |
---|
9 | from kofacustom.iuokada.students.export import ( |
---|
10 | CustomStudentExporter, CustomStudentPaymentExporter) |
---|
11 | from kofacustom.iuokada.testing import FunctionalLayer |
---|
12 | |
---|
13 | |
---|
14 | class CustomStudentExporterTest(StudentImportExportSetup): |
---|
15 | |
---|
16 | layer = FunctionalLayer |
---|
17 | |
---|
18 | def setUp(self): |
---|
19 | super(CustomStudentExporterTest, self).setUp() |
---|
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 |
---|
35 | obj = CustomStudentExporter() |
---|
36 | verifyObject(ICSVExporter, obj) |
---|
37 | verifyClass(ICSVExporter, CustomStudentExporter) |
---|
38 | return |
---|
39 | |
---|
40 | |
---|
41 | def test_export_all(self): |
---|
42 | # we can really export students |
---|
43 | # set values we can expect in export file |
---|
44 | self.setup_student(self.student) |
---|
45 | exporter = CustomStudentExporter() |
---|
46 | exporter.export_all(self.app, self.outfile) |
---|
47 | result = open(self.outfile, 'rb').read() |
---|
48 | self.assertTrue('entry_session' in result) |
---|
49 | return |
---|
50 | |
---|
51 | class CustomStudentPaymentExporterTest(StudentImportExportSetup): |
---|
52 | |
---|
53 | layer = FunctionalLayer |
---|
54 | |
---|
55 | def setUp(self): |
---|
56 | super(CustomStudentPaymentExporterTest, self).setUp() |
---|
57 | self.setup_for_export() |
---|
58 | return |
---|
59 | |
---|
60 | def test_ifaces(self): |
---|
61 | # make sure we fullfill interface contracts |
---|
62 | obj = CustomStudentPaymentExporter() |
---|
63 | verifyObject(ICSVExporter, obj) |
---|
64 | verifyClass(ICSVExporter, CustomStudentPaymentExporter) |
---|
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) |
---|
71 | self.student['payments']['my-payment'].r_company = 'interswitch' |
---|
72 | self.student['payments']['my-payment'].p_option = 'first' |
---|
73 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
74 | exporter = CustomStudentPaymentExporter() |
---|
75 | exporter.export_all(self.app, self.outfile) |
---|
76 | result = open(self.outfile, 'rb').read() |
---|
77 | self.assertMatches( |
---|
78 | 'ac,amount_auth,creation_date,gateway_amt,net_amt,p_category,p_combi,p_current,' |
---|
79 | 'p_id,p_item,p_level,p_option,p_session,p_state,payment_date,provider_amt,' |
---|
80 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
---|
81 | 'r_pay_reference,thirdparty_amt,student_id,state,' |
---|
82 | 'current_session,entry_session\r\n' |
---|
83 | '666,12.12,%s-04-01 13:12:01#,,,schoolfee,[],1,my-id,p-item,' |
---|
84 | '100,first,%s,paid,%s-04-01 14:12:01#,,12.12,' |
---|
85 | '789,r-code,interswitch,,,,A111111,created,2012,2010\r\n' |
---|
86 | % (curr_year-6, curr_year-6, curr_year-6), result |
---|
87 | ) |
---|
88 | return |
---|