| 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 | from waeup.aaue.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.assertMatches( |
|---|
| 49 | 'adm_code,alr_date,alr_fname,alr_no,alr_results,clr_code,' |
|---|
| 50 | 'date_of_birth,def_adm,disabled,email,emp2_end,emp2_position,' |
|---|
| 51 | 'emp2_reason,emp2_start,emp_end,emp_position,emp_reason,' |
|---|
| 52 | 'emp_start,employer,employer2,father_address,father_name,' |
|---|
| 53 | 'father_phone,father_work,firstname,former_matric,fst_sit_date,' |
|---|
| 54 | 'fst_sit_fname,fst_sit_no,fst_sit_results,fst_sit_type,hq2_degree,' |
|---|
| 55 | 'hq2_disc,hq2_matric_no,hq2_school,hq2_session,hq2_type,' |
|---|
| 56 | 'hq_degree,hq_disc,hq_fname,hq_matric_no,hq_school,hq_session,' |
|---|
| 57 | 'hq_type,is_staff,lastname,lga,marit_stat,matric_number,' |
|---|
| 58 | 'middlename,mother_address,mother_name,mother_phone,' |
|---|
| 59 | 'mother_work,nationality,next_kin_address,next_kin_name,' |
|---|
| 60 | 'next_kin_phone,next_kin_relation,nysc_lga,nysc_location,' |
|---|
| 61 | 'nysc_year,officer_comment,perm_address,personal_updated,' |
|---|
| 62 | 'phone,phone_personal,physical_clearance_date,reg_number,' |
|---|
| 63 | 'religion,scd_sit_date,scd_sit_fname,scd_sit_no,scd_sit_results,' |
|---|
| 64 | 'scd_sit_type,sex,student_id,suspended,suspended_comment,password,' |
|---|
| 65 | 'state,history,certcode,is_postgrad,current_level,current_session' |
|---|
| 66 | '\r\n' |
|---|
| 67 | 'my adm code,,,,"[(\'printing_craft_practice\', \'A1\')]",' |
|---|
| 68 | 'my clr code,1981-02-04#,,,anna@sample.com,,,,,,,,,,,,,,,Anna,,,,,' |
|---|
| 69 | '"[(\'printing_craft_practice\', \'A1\')]",,,,,,,,,,,,,,,,Tester,,,' |
|---|
| 70 | '234,M.,,,,,NG,,,,,,,,,"Studentroad 21\nLagos 123456\n",,' |
|---|
| 71 | '+234-123-12345#,,,123,,,,,' |
|---|
| 72 | '"[(\'printing_craft_practice\', \'A1\')]",,f,A111111,0,,,' |
|---|
| 73 | 'created,[u\'2015-10-26 17:45:56 WAT - Record created by system\'],' |
|---|
| 74 | 'CERT1,0,200,2012\r\n', |
|---|
| 75 | result |
|---|
| 76 | ) |
|---|
| 77 | return |
|---|
| 78 | |
|---|
| 79 | class CustomStudentPaymentExporterTest(StudentImportExportSetup): |
|---|
| 80 | |
|---|
| 81 | layer = FunctionalLayer |
|---|
| 82 | |
|---|
| 83 | def setUp(self): |
|---|
| 84 | super(CustomStudentPaymentExporterTest, self).setUp() |
|---|
| 85 | self.setup_for_export() |
|---|
| 86 | return |
|---|
| 87 | |
|---|
| 88 | def test_ifaces(self): |
|---|
| 89 | # make sure we fullfill interface contracts |
|---|
| 90 | obj = CustomStudentPaymentExporter() |
|---|
| 91 | verifyObject(ICSVExporter, obj) |
|---|
| 92 | verifyClass(ICSVExporter, CustomStudentPaymentExporter) |
|---|
| 93 | return |
|---|
| 94 | |
|---|
| 95 | def test_export_all(self): |
|---|
| 96 | # we can really export students |
|---|
| 97 | # set values we can expect in export file |
|---|
| 98 | self.setup_student(self.student) |
|---|
| 99 | self.student['payments']['my-payment'].r_company = 'interswatch' |
|---|
| 100 | self.student['payments']['my-payment'].r_card_num = '789' |
|---|
| 101 | exporter = CustomStudentPaymentExporter() |
|---|
| 102 | exporter.export_all(self.app, self.outfile) |
|---|
| 103 | result = open(self.outfile, 'rb').read() |
|---|
| 104 | self.assertMatches( |
|---|
| 105 | 'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,' |
|---|
| 106 | 'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,' |
|---|
| 107 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
|---|
| 108 | 'r_pay_reference,thirdparty_amt,student_id,state,' |
|---|
| 109 | 'current_session\r\n' |
|---|
| 110 | '666,12.12,2012-04-01 13:12:01#,,schoolfee,1,my-id,p-item,' |
|---|
| 111 | '100,2012,paid,2012-04-01 14:12:01#,,12.12,' |
|---|
| 112 | '789,r-code,interswatch,,,,A111111,created,2012\r\n', |
|---|
| 113 | result |
|---|
| 114 | ) |
|---|
| 115 | return |
|---|
| 116 | |
|---|
| 117 | class CustomStudentStudyLevelExporterTest(StudentImportExportSetup): |
|---|
| 118 | |
|---|
| 119 | layer = FunctionalLayer |
|---|
| 120 | |
|---|
| 121 | def setUp(self): |
|---|
| 122 | super(CustomStudentStudyLevelExporterTest, self).setUp() |
|---|
| 123 | self.setup_for_export() |
|---|
| 124 | return |
|---|
| 125 | |
|---|
| 126 | def test_export_all(self): |
|---|
| 127 | # we can really export study levels |
|---|
| 128 | # set values we can expect in export file |
|---|
| 129 | self.setup_student(self.student) |
|---|
| 130 | exporter = CustomStudentStudyLevelExporter() |
|---|
| 131 | exporter.export_all(self.app, self.outfile) |
|---|
| 132 | result = open(self.outfile, 'rb').read() |
|---|
| 133 | self.assertEqual( |
|---|
| 134 | result, |
|---|
| 135 | 'gpa,level,level_session,level_verdict,total_credits,' |
|---|
| 136 | 'total_credits_s1,total_credits_s2,' |
|---|
| 137 | 'validated_by,validation_date,' |
|---|
| 138 | 'student_id,number_of_tickets,certcode\r\n' |
|---|
| 139 | '0.0,100,2012,A,100,,,,,A111111,1,CERT1\r\n' |
|---|
| 140 | ) |
|---|
| 141 | return |
|---|
| 142 | |
|---|