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