source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/tests/test_export.py @ 11156

Last change on this file since 11156 was 10757, checked in by Henrik Bettermann, 11 years ago

Use the customized interface when exporting Nigerian payment tickets.

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1import datetime
2from zope.component import queryUtility
3from zope.interface.verify import verifyObject, verifyClass
4from waeup.kofa.interfaces import ICSVExporter
5from waeup.kofa.schoolgrades import ResultEntry
6from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
7
8from kofacustom.nigeria.utils.utils import NigeriaKofaUtils
9from kofacustom.nigeria.students.export import (
10    NigeriaStudentsExporter, NigeriaStudentPaymentsExporter)
11from kofacustom.nigeria.testing import FunctionalLayer
12
13
14class NigeriaStudentsExporterTest(StudentImportExportSetup):
15
16    layer = FunctionalLayer
17
18    def setUp(self):
19        super(NigeriaStudentsExporterTest, self).setUp()
20        self.setup_for_export()
21        result_entry = ResultEntry(
22            NigeriaKofaUtils.EXAM_SUBJECTS_DICT.keys()[0],
23            NigeriaKofaUtils.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 = NigeriaStudentsExporter()
36        verifyObject(ICSVExporter, obj)
37        verifyClass(ICSVExporter, NigeriaStudentsExporter)
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 = NigeriaStudentsExporter()
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,clearance_locked,'
50            'clr_code,date_of_birth,def_adm,disabled,email,emp2_end,'
51            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,'
52            'emp_reason,emp_start,employer,employer2,firstname,former_matric,'
53            'fst_sit_date,fst_sit_fname,fst_sit_no,fst_sit_results,'
54            'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,'
55            'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,'
56            'hq_school,hq_session,hq_type,is_staff,lastname,lga,'
57            'marit_stat,matric_number,middlename,nationality,'
58            'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,'
59            'nysc_lga,nysc_location,nysc_year,officer_comment,'
60            'perm_address,personal_updated,phone,reg_number,'
61            'religion,scd_sit_date,scd_sit_fname,scd_sit_no,'
62            'scd_sit_results,scd_sit_type,sex,student_id,'
63            'suspended,suspended_comment,password,state,history,certcode,is_postgrad,'
64            'current_level,current_session\r\nmy adm code,,,,'
65            '"[(\'visual_art\', \'A1\')]",0,my clr code,1981-02-04#,,,'
66            'anna@sample.com,,,,,,,,,,,Anna,,,,,"[(\'visual_art\', \'A1\')]"'
67            ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,'
68            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,123,,,,,'
69            '"[(\'visual_art\', \'A1\')]",,f,A111111,0,,,created,'
70            '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],'
71            'CERT1,0,200,2012\r\n',
72            result
73            )
74        return
75
76class NigeriaStudentPaymentsExporterTest(StudentImportExportSetup):
77
78    layer = FunctionalLayer
79
80    def setUp(self):
81        super(NigeriaStudentPaymentsExporterTest, self).setUp()
82        self.setup_for_export()
83        return
84
85    def test_ifaces(self):
86        # make sure we fullfill interface contracts
87        obj = NigeriaStudentPaymentsExporter()
88        verifyObject(ICSVExporter, obj)
89        verifyClass(ICSVExporter, NigeriaStudentPaymentsExporter)
90        return
91
92    def test_export_all(self):
93        # we can really export students
94        # set values we can expect in export file
95        self.setup_student(self.student)
96        self.student['payments']['my-payment'].r_company = 'interswatch'
97        self.student['payments']['my-payment'].r_card_num = '789'
98        exporter = NigeriaStudentPaymentsExporter()
99        exporter.export_all(self.app, self.outfile)
100        result = open(self.outfile, 'rb').read()
101        self.assertMatches(
102            'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,'
103            'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,'
104            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
105            'r_pay_reference,thirdparty_amt,student_id,state,'
106            'current_session\r\n'
107            '666,12.12,2012-04-01 13:12:01,,schoolfee,1,my-id,p-item,'
108            '100,2012,paid,2012-04-01 14:12:01,,12.12,'
109            '789,r-code,interswatch,,,,A111111,created,2012\r\n',
110            result
111            )
112        return
Note: See TracBrowser for help on using the repository browser.