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 StudentImportExportSetup |
---|
7 | from waeup.aaue.utils.utils import CustomKofaUtils |
---|
8 | from waeup.aaue.students.export import ( |
---|
9 | CustomStudentExporter, CustomStudentPaymentExporter, |
---|
10 | CustomStudentStudyLevelExporter, |
---|
11 | CustomCourseTicketExporter) |
---|
12 | from waeup.aaue.testing import FunctionalLayer |
---|
13 | |
---|
14 | |
---|
15 | class CustomStudentExporterTest(StudentImportExportSetup): |
---|
16 | |
---|
17 | layer = FunctionalLayer |
---|
18 | |
---|
19 | def setUp(self): |
---|
20 | super(CustomStudentExporterTest, self).setUp() |
---|
21 | self.setup_for_export() |
---|
22 | result_entry = ResultEntry( |
---|
23 | CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0], |
---|
24 | CustomKofaUtils.EXAM_GRADES[0][0] |
---|
25 | ) |
---|
26 | self.student.alr_results = [ |
---|
27 | result_entry] |
---|
28 | self.student.fst_sit_results = [ |
---|
29 | result_entry] |
---|
30 | self.student.scd_sit_results = [ |
---|
31 | result_entry] |
---|
32 | return |
---|
33 | |
---|
34 | def test_ifaces(self): |
---|
35 | # make sure we fullfill interface contracts |
---|
36 | obj = CustomStudentExporter() |
---|
37 | verifyObject(ICSVExporter, obj) |
---|
38 | verifyClass(ICSVExporter, CustomStudentExporter) |
---|
39 | return |
---|
40 | |
---|
41 | |
---|
42 | def test_export_all(self): |
---|
43 | # we can really export students |
---|
44 | # set values we can expect in export file |
---|
45 | self.setup_student(self.student) |
---|
46 | exporter = CustomStudentExporter() |
---|
47 | exporter.export_all(self.app, self.outfile) |
---|
48 | result = open(self.outfile, 'rb').read() |
---|
49 | self.assertMatches( |
---|
50 | 'adm_code,alr_date,alr_fname,alr_no,alr_results,clr_code,' |
---|
51 | 'date_of_birth,def_adm,disabled,email,emp2_end,emp2_position,' |
---|
52 | 'emp2_reason,emp2_start,emp_end,emp_position,emp_reason,' |
---|
53 | 'emp_start,employer,employer2,father_address,father_name,' |
---|
54 | 'father_phone,father_work,firstname,former_matric,fst_sit_date,' |
---|
55 | 'fst_sit_fname,fst_sit_no,fst_sit_results,fst_sit_type,hq2_degree,' |
---|
56 | 'hq2_disc,hq2_matric_no,hq2_school,hq2_session,hq2_type,' |
---|
57 | 'hq_degree,hq_disc,hq_fname,hq_matric_no,hq_school,hq_session,' |
---|
58 | 'hq_type,is_staff,lastname,lga,marit_stat,matric_number,' |
---|
59 | 'middlename,mother_address,mother_name,mother_phone,' |
---|
60 | 'mother_work,nationality,next_kin_address,next_kin_name,' |
---|
61 | 'next_kin_phone,next_kin_relation,nysc_lga,nysc_location,' |
---|
62 | 'nysc_year,officer_comment,perm_address,personal_updated,' |
---|
63 | 'phone,phone_personal,physical_clearance_date,reg_number,' |
---|
64 | 'religion,scd_sit_date,scd_sit_fname,scd_sit_no,scd_sit_results,' |
---|
65 | 'scd_sit_type,sex,student_id,suspended,suspended_comment,password,' |
---|
66 | 'state,history,certcode,is_postgrad,current_level,current_session' |
---|
67 | '\r\n' |
---|
68 | 'my adm code,,,,"[(\'printing_craft_practice\', \'A1\')]",' |
---|
69 | 'my clr code,1981-02-04#,,,anna@sample.com,,,,,,,,,,,,,,,Anna,,,,,' |
---|
70 | '"[(\'printing_craft_practice\', \'A1\')]",,,,,,,,,,,,,,,,Tester,,,' |
---|
71 | '234,M.,,,,,NG,,,,,,,,,"Studentroad 21\nLagos 123456\n",,' |
---|
72 | '+234-123-12345#,,,123,,,,,' |
---|
73 | '"[(\'printing_craft_practice\', \'A1\')]",,f,A111111,0,,,' |
---|
74 | 'created,[u\'2015-10-26 17:45:56 WAT - Record created by system\'],' |
---|
75 | 'CERT1,0,200,2012\r\n', |
---|
76 | result |
---|
77 | ) |
---|
78 | return |
---|
79 | |
---|
80 | class CustomStudentPaymentExporterTest(StudentImportExportSetup): |
---|
81 | |
---|
82 | layer = FunctionalLayer |
---|
83 | |
---|
84 | def setUp(self): |
---|
85 | super(CustomStudentPaymentExporterTest, self).setUp() |
---|
86 | self.setup_for_export() |
---|
87 | return |
---|
88 | |
---|
89 | def test_ifaces(self): |
---|
90 | # make sure we fullfill interface contracts |
---|
91 | obj = CustomStudentPaymentExporter() |
---|
92 | verifyObject(ICSVExporter, obj) |
---|
93 | verifyClass(ICSVExporter, CustomStudentPaymentExporter) |
---|
94 | return |
---|
95 | |
---|
96 | def test_export_all(self): |
---|
97 | # we can really export students |
---|
98 | # set values we can expect in export file |
---|
99 | self.setup_student(self.student) |
---|
100 | self.student['payments']['my-payment'].r_company = 'interswatch' |
---|
101 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
102 | exporter = CustomStudentPaymentExporter() |
---|
103 | exporter.export_all(self.app, self.outfile) |
---|
104 | result = open(self.outfile, 'rb').read() |
---|
105 | self.assertMatches( |
---|
106 | 'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,' |
---|
107 | 'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,' |
---|
108 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
---|
109 | 'r_pay_reference,thirdparty_amt,student_id,state,' |
---|
110 | 'current_session\r\n' |
---|
111 | '666,12.12,2012-04-01 13:12:01#,,schoolfee,1,my-id,p-item,' |
---|
112 | '100,2012,paid,2012-04-01 14:12:01#,,12.12,' |
---|
113 | '789,r-code,interswatch,,,,A111111,created,2012\r\n', |
---|
114 | result |
---|
115 | ) |
---|
116 | return |
---|
117 | |
---|
118 | class CustomStudentStudyLevelExporterTest(StudentImportExportSetup): |
---|
119 | |
---|
120 | layer = FunctionalLayer |
---|
121 | |
---|
122 | def setUp(self): |
---|
123 | super(CustomStudentStudyLevelExporterTest, self).setUp() |
---|
124 | self.setup_for_export() |
---|
125 | return |
---|
126 | |
---|
127 | def test_export_all(self): |
---|
128 | # we can really export study levels |
---|
129 | # set values we can expect in export file |
---|
130 | self.setup_student(self.student) |
---|
131 | exporter = CustomStudentStudyLevelExporter() |
---|
132 | exporter.export_all(self.app, self.outfile) |
---|
133 | result = open(self.outfile, 'rb').read() |
---|
134 | self.assertEqual( |
---|
135 | result, |
---|
136 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
137 | 'total_credits_s1,total_credits_s2,' |
---|
138 | 'validated_by,validation_date,' |
---|
139 | 'student_id,number_of_tickets,certcode\r\n' |
---|
140 | '0.0,100,2012,A,100,,,,,A111111,1,CERT1\r\n' |
---|
141 | ) |
---|
142 | return |
---|
143 | |
---|
144 | class CustomCourseTicketExporterTest(StudentImportExportSetup): |
---|
145 | |
---|
146 | layer = FunctionalLayer |
---|
147 | |
---|
148 | def setUp(self): |
---|
149 | super(CustomCourseTicketExporterTest, self).setUp() |
---|
150 | self.setup_for_export() |
---|
151 | return |
---|
152 | |
---|
153 | def test_export_all(self): |
---|
154 | # we can really export all course tickets |
---|
155 | # set values we can expect in export file |
---|
156 | self.setup_student(self.student) |
---|
157 | exporter = CustomCourseTicketExporter() |
---|
158 | exporter.export_all(self.app, self.outfile) |
---|
159 | result = open(self.outfile, 'rb').read() |
---|
160 | self.assertEqual( |
---|
161 | result, |
---|
162 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
163 | 'mandatory,passmark,score,semester,title,student_id,certcode,' |
---|
164 | 'display_fullname,matric_number\r\n' |
---|
165 | '1,1,CRS1,100,DEP1,FAC1,100,2012,0,100,,2,Course 1,A111111,CERT1,' |
---|
166 | 'Anna M. Tester,234\r\n' |
---|
167 | ) |
---|
168 | return |
---|
169 | |
---|