[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 |
---|
[11832] | 7 | from kofacustom.pcn.utils.utils import CustomKofaUtils |
---|
| 8 | from kofacustom.pcn.students.export import ( |
---|
[12234] | 9 | CustomStudentExporter, CustomStudentPaymentsExporter) |
---|
[11832] | 10 | from kofacustom.pcn.testing import FunctionalLayer |
---|
[11543] | 11 | |
---|
| 12 | |
---|
[12234] | 13 | class CustomStudentExporterTest(StudentImportExportSetup): |
---|
[11543] | 14 | |
---|
| 15 | layer = FunctionalLayer |
---|
| 16 | |
---|
| 17 | def setUp(self): |
---|
[12234] | 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 |
---|
[12234] | 34 | obj = CustomStudentExporter() |
---|
[11543] | 35 | verifyObject(ICSVExporter, obj) |
---|
[12234] | 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) |
---|
[12234] | 44 | exporter = CustomStudentExporter() |
---|
[11543] | 45 | exporter.export_all(self.app, self.outfile) |
---|
| 46 | result = open(self.outfile, 'rb').read() |
---|
| 47 | self.assertMatches( |
---|
[11687] | 48 | 'adm_code,clearance_locked,clr_code,date_of_birth,email,' |
---|
| 49 | 'employer,firstname,lastname,matric_number,middlename,' |
---|
| 50 | 'nationality,officer_comment,perm_address,personal_updated,' |
---|
| 51 | 'phone,reg_number,sex,student_id,suspended,suspended_comment,' |
---|
| 52 | 'password,state,history,certcode,is_postgrad,current_level,' |
---|
| 53 | 'current_session\r\nmy adm code,0,my clr code,1981-02-04#,' |
---|
| 54 | 'anna@sample.com,,Anna,Tester,234,M.,NG,,' |
---|
| 55 | '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,123,' |
---|
| 56 | 'f,A111111,0,,,created,' |
---|
| 57 | '[u\'2014-06-16 08:23:55 UTC - Record created by system\'],' |
---|
[11543] | 58 | 'CERT1,0,200,2012\r\n', |
---|
| 59 | result |
---|
| 60 | ) |
---|
| 61 | return |
---|
| 62 | |
---|
| 63 | class CustomStudentPaymentsExporterTest(StudentImportExportSetup): |
---|
| 64 | |
---|
| 65 | layer = FunctionalLayer |
---|
| 66 | |
---|
| 67 | def setUp(self): |
---|
| 68 | super(CustomStudentPaymentsExporterTest, self).setUp() |
---|
| 69 | self.setup_for_export() |
---|
| 70 | return |
---|
| 71 | |
---|
| 72 | def test_ifaces(self): |
---|
| 73 | # make sure we fullfill interface contracts |
---|
| 74 | obj = CustomStudentPaymentsExporter() |
---|
| 75 | verifyObject(ICSVExporter, obj) |
---|
| 76 | verifyClass(ICSVExporter, CustomStudentPaymentsExporter) |
---|
| 77 | return |
---|
| 78 | |
---|
| 79 | def test_export_all(self): |
---|
| 80 | # we can really export students |
---|
| 81 | # set values we can expect in export file |
---|
| 82 | self.setup_student(self.student) |
---|
| 83 | self.student['payments']['my-payment'].r_company = 'interswatch' |
---|
| 84 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
| 85 | exporter = CustomStudentPaymentsExporter() |
---|
| 86 | exporter.export_all(self.app, self.outfile) |
---|
| 87 | result = open(self.outfile, 'rb').read() |
---|
| 88 | self.assertMatches( |
---|
[11687] | 89 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
| 90 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
| 91 | 'r_code,r_desc,student_id,state,current_session\r\n666,' |
---|
[12234] | 92 | '12.12,2012-04-01 13:12:01#,schoolfee,1,my-id,p-item,' |
---|
| 93 | '100,2012,paid,2012-04-01 14:12:01#,12.12,r-code,,' |
---|
[11687] | 94 | 'A111111,created,2012\r\n', |
---|
[11543] | 95 | result |
---|
| 96 | ) |
---|
| 97 | return |
---|