source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/tests/test_export.py @ 17929

Last change on this file since 17929 was 17921, checked in by Henrik Bettermann, 2 months ago

Add email2 field.

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