source: main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_export.py @ 16437

Last change on this file since 16437 was 16437, checked in by Henrik Bettermann, 4 years ago

Adjust test.

File size: 6.4 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 waeup.uniben.utils.utils import CustomKofaUtils
9from waeup.uniben.students.export import (
10    CustomStudentExporter, CustomStudentPaymentExporter,
11    MedicalHistoryExporter)
12from waeup.uniben.testing import FunctionalLayer
13
14
15class CustomStudentExporterTest(StudentImportExportSetup):
16
17    layer = FunctionalLayer
18
19    def setUp(self):
20        super(CustomStudentExporterTest, self).setUp()
21        self.setup_for_export()
22        result_entry = ResultEntry(
23            CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0],
24            CustomKofaUtils.EXAM_GRADES[0][0]
25            )
26        self.student.alr_results = [
27            result_entry]
28        self.student.fst_sit_results = [
29            result_entry]
30        self.student.scd_sit_results = [
31            result_entry]
32        return
33
34    def test_ifaces(self):
35        # make sure we fullfill interface contracts
36        obj = CustomStudentExporter()
37        verifyObject(ICSVExporter, obj)
38        verifyClass(ICSVExporter, CustomStudentExporter)
39        return
40
41
42    def disabled_test_export_all(self):
43        # we can really export students
44        # set values we can expect in export file
45        self.setup_student(self.student)
46        exporter = CustomStudentExporter()
47        exporter.export_all(self.app, self.outfile)
48        result = open(self.outfile, 'rb').read()
49        self.assertMatches(
50            'adm_code,alr_date,alr_fname,alr_no,alr_results,'
51            'clr_code,date_of_birth,def_adm,disabled,email,email2,emp2_end,'
52            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,'
53            'emp_reason,emp_start,employer,employer2,'
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,library,'
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,parent_email,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,p_category,p_combi,p_current,'
107            'p_id,p_item,p_level,p_option,p_session,p_state,payment_date,provider_amt,'
108            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
109            'r_pay_reference,rebate_amount,staff_rebate,thirdparty_amt,student_id,state,'
110            'current_session\r\n'
111            '666,12.12,%s-04-01 13:12:01#,,,schoolfee,[],1,my-id,p-item,'
112            '100,,%s,paid,%s-04-01 14:12:01#,,12.12,'
113            '789,r-code,interswatch,,,,,,A111111,created,2012\r\n'
114            % (curr_year-6, curr_year-6, curr_year-6), result
115            )
116        return
117
118class MedicalHistoryExporterTest(StudentImportExportSetup):
119
120    layer = FunctionalLayer
121
122    def setUp(self):
123        super(MedicalHistoryExporterTest, self).setUp()
124        self.setup_for_export()
125        return
126
127    def test_ifaces(self):
128        # make sure we fullfill interface contracts
129        obj = MedicalHistoryExporter()
130        verifyObject(ICSVExporter, obj)
131        verifyClass(ICSVExporter, MedicalHistoryExporter)
132        return
133
134    def test_export_all(self):
135        # we can really export students
136        # set values we can expect in export file
137        self.setup_student(self.student)
138        self.student.sore_throat = True
139        exporter = MedicalHistoryExporter()
140        exporter.export_all(self.app, self.outfile)
141        result = open(self.outfile, 'rb').read()
142        self.assertMatches(
143            'asthma,body_pains,breathing,catarrh,company_confirmed,'
144            'company_suspected,cough,diabetes,fever,headaches,hypertension,'
145            'lagos_abuja,medical_updated,medicines,negative,obesity,'
146            'others,outside,positive,smell,sneezing,sore_throat,taste,'
147            'vaccination,weakness,student_id,display_fullname,'
148            'matric_number,faccode,depcode,state,current_session,'
149            'current_level\r\n'
150            ',,,,,,,,,,,,,,,,,,,,,1,,,,A111111,Anna M. Tester,234,'
151            'NA,NA,created,2012,200\r\n' , result
152            )
153        return
Note: See TracBrowser for help on using the repository browser.