[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 |
---|
| 6 | from waeup.kofa.students.tests.test_batching import StudentImportExportSetup |
---|
[11940] | 7 | from kofacustom.wdu.utils.utils import CustomKofaUtils |
---|
| 8 | from kofacustom.wdu.students.export import ( |
---|
[12880] | 9 | CustomStudentExporter, CustomStudentPaymentExporter) |
---|
[11940] | 10 | from kofacustom.wdu.testing import FunctionalLayer |
---|
[11543] | 11 | |
---|
| 12 | |
---|
[12086] | 13 | class CustomStudentExporterTest(StudentImportExportSetup): |
---|
[11543] | 14 | |
---|
| 15 | layer = FunctionalLayer |
---|
| 16 | |
---|
| 17 | def setUp(self): |
---|
[12086] | 18 | super(CustomStudentExporterTest, self).setUp() |
---|
[11543] | 19 | self.setup_for_export() |
---|
| 20 | result_entry = ResultEntry( |
---|
| 21 | CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0], |
---|
| 22 | CustomKofaUtils.EXAM_GRADES[0][0] |
---|
| 23 | ) |
---|
| 24 | self.student.alr_results = [ |
---|
| 25 | result_entry] |
---|
| 26 | self.student.fst_sit_results = [ |
---|
| 27 | result_entry] |
---|
| 28 | self.student.scd_sit_results = [ |
---|
| 29 | result_entry] |
---|
| 30 | return |
---|
| 31 | |
---|
| 32 | def test_ifaces(self): |
---|
| 33 | # make sure we fullfill interface contracts |
---|
[12086] | 34 | obj = CustomStudentExporter() |
---|
[11543] | 35 | verifyObject(ICSVExporter, obj) |
---|
[12086] | 36 | verifyClass(ICSVExporter, CustomStudentExporter) |
---|
[11543] | 37 | return |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | def test_export_all(self): |
---|
| 41 | # we can really export students |
---|
| 42 | # set values we can expect in export file |
---|
| 43 | self.setup_student(self.student) |
---|
[12086] | 44 | exporter = CustomStudentExporter() |
---|
[11543] | 45 | exporter.export_all(self.app, self.outfile) |
---|
| 46 | result = open(self.outfile, 'rb').read() |
---|
| 47 | self.assertMatches( |
---|
[13116] | 48 | 'adm_code,alr_date,alr_fname,alr_no,alr_results,' |
---|
[11543] | 49 | 'clr_code,date_of_birth,def_adm,disabled,email,emp2_end,' |
---|
| 50 | 'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,' |
---|
[13630] | 51 | 'emp_reason,emp_start,employer,employer2,' |
---|
| 52 | 'financial_clearance_date,financially_cleared_by,' |
---|
[13718] | 53 | 'firstname,flash_notice,former_matric,' |
---|
[11543] | 54 | 'fst_sit_date,fst_sit_fname,fst_sit_no,fst_sit_results,' |
---|
| 55 | 'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,' |
---|
| 56 | 'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,' |
---|
| 57 | 'hq_school,hq_session,hq_type,is_staff,lastname,lga,' |
---|
| 58 | 'marit_stat,matric_number,middlename,nationality,' |
---|
| 59 | 'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,' |
---|
| 60 | 'nysc_lga,nysc_location,nysc_year,officer_comment,' |
---|
[14278] | 61 | 'perm_address,personal_updated,phone,' |
---|
| 62 | 'physical_clearance_date,provisionally_cleared,reg_number,' |
---|
[11543] | 63 | 'religion,scd_sit_date,scd_sit_fname,scd_sit_no,' |
---|
| 64 | 'scd_sit_results,scd_sit_type,sex,student_id,' |
---|
| 65 | 'suspended,suspended_comment,password,state,history,certcode,is_postgrad,' |
---|
| 66 | 'current_level,current_session\r\nmy adm code,,,,' |
---|
[13116] | 67 | '"[(\'printing_craft_practice\', \'A1\')]",my clr code,1981-02-04#,,,' |
---|
[13718] | 68 | 'anna@sample.com,,,,,,,,,,,,,Anna,,,,,,"[(\'printing_craft_practice\', \'A1\')]"' |
---|
[11543] | 69 | ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,' |
---|
[14278] | 70 | '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,' |
---|
[11813] | 71 | '"[(\'printing_craft_practice\', \'A1\')]",,f,A111111,0,,,created,' |
---|
[11543] | 72 | '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],' |
---|
| 73 | 'CERT1,0,200,2012\r\n', |
---|
| 74 | result |
---|
| 75 | ) |
---|
| 76 | return |
---|
| 77 | |
---|
[12880] | 78 | class CustomStudentPaymentExporterTest(StudentImportExportSetup): |
---|
[11543] | 79 | |
---|
| 80 | layer = FunctionalLayer |
---|
| 81 | |
---|
| 82 | def setUp(self): |
---|
[12880] | 83 | super(CustomStudentPaymentExporterTest, self).setUp() |
---|
[11543] | 84 | self.setup_for_export() |
---|
| 85 | return |
---|
| 86 | |
---|
| 87 | def test_ifaces(self): |
---|
| 88 | # make sure we fullfill interface contracts |
---|
[12880] | 89 | obj = CustomStudentPaymentExporter() |
---|
[11543] | 90 | verifyObject(ICSVExporter, obj) |
---|
[12880] | 91 | verifyClass(ICSVExporter, CustomStudentPaymentExporter) |
---|
[11543] | 92 | return |
---|
| 93 | |
---|
| 94 | def test_export_all(self): |
---|
| 95 | # we can really export students |
---|
| 96 | # set values we can expect in export file |
---|
| 97 | self.setup_student(self.student) |
---|
| 98 | self.student['payments']['my-payment'].r_company = 'interswatch' |
---|
| 99 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
[12880] | 100 | exporter = CustomStudentPaymentExporter() |
---|
[11543] | 101 | exporter.export_all(self.app, self.outfile) |
---|
| 102 | result = open(self.outfile, 'rb').read() |
---|
| 103 | self.assertMatches( |
---|
| 104 | 'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,' |
---|
| 105 | 'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,' |
---|
| 106 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
---|
| 107 | 'r_pay_reference,thirdparty_amt,student_id,state,' |
---|
| 108 | 'current_session\r\n' |
---|
[11813] | 109 | '666,12.12,2012-04-01 13:12:01#,,schoolfee,1,my-id,p-item,' |
---|
| 110 | '100,2012,paid,2012-04-01 14:12:01#,,12.12,' |
---|
[11543] | 111 | '789,r-code,interswatch,,,,A111111,created,2012\r\n', |
---|
| 112 | result |
---|
| 113 | ) |
---|
| 114 | return |
---|