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

Last change on this file was 17897, checked in by Henrik Bettermann, 3 months ago

Add fields.

File size: 8.2 KB
RevLine 
[17257]1import datetime
[12856]2from zope.component import queryUtility
3from zope.interface.verify import verifyObject, verifyClass
4from waeup.kofa.interfaces import ICSVExporter
5from waeup.kofa.schoolgrades import ResultEntry
[14421]6from waeup.kofa.students.tests.test_batching import (
7    StudentImportExportSetup, curr_year)
[12856]8from waeup.uniben.utils.utils import CustomKofaUtils
9from waeup.uniben.students.export import (
[16390]10    CustomStudentExporter, CustomStudentPaymentExporter,
[17396]11    MedicalHistoryExporter, NYSCExporter)
[12856]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
[16382]42    def disabled_test_export_all(self):
[12856]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(
[13110]50            'adm_code,alr_date,alr_fname,alr_no,alr_results,'
[16088]51            'clr_code,date_of_birth,def_adm,disabled,email,email2,emp2_end,'
[12856]52            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,'
[13624]53            'emp_reason,emp_start,employer,employer2,'
54            'financial_clearance_date,financially_cleared_by,'
[13717]55            'firstname,flash_notice,former_matric,'
[12856]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,'
[15371]59            'hq_school,hq_session,hq_type,is_staff,lastname,lga,library,'
[12856]60            'marit_stat,matric_number,middlename,nationality,'
61            'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,'
[15666]62            'nysc_lga,nysc_location,nysc_year,officer_comment,parent_email,parents_email,'
[14275]63            'perm_address,personal_updated,phone,'
64            'physical_clearance_date,provisionally_cleared,reg_number,'
[12856]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,,,,'
[13110]69            '"[(\'printing_craft_practice\', \'A1\')]",my clr code,1981-02-04#,,,'
[16088]70            'anna@sample.com,,,,,,,,,,,,,,Anna,,,,,,"[(\'printing_craft_practice\', \'A1\')]"'
[15666]71            ',,,,,,,,,,,,,,,,Tester,,,,234,M.,NG,,,,,,,,,,,'
[14275]72            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,'
[12856]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
[12879]80class CustomStudentPaymentExporterTest(StudentImportExportSetup):
[12856]81
82    layer = FunctionalLayer
83
84    def setUp(self):
[12879]85        super(CustomStudentPaymentExporterTest, self).setUp()
[12856]86        self.setup_for_export()
87        return
88
89    def test_ifaces(self):
90        # make sure we fullfill interface contracts
[12879]91        obj = CustomStudentPaymentExporter()
[12856]92        verifyObject(ICSVExporter, obj)
[12879]93        verifyClass(ICSVExporter, CustomStudentPaymentExporter)
[12856]94        return
95
96    def test_export_all(self):
[17257]97        # we can really export student payments
[12856]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'
[12879]102        exporter = CustomStudentPaymentExporter()
[12856]103        exporter.export_all(self.app, self.outfile)
104        result = open(self.outfile, 'rb').read()
105        self.assertMatches(
[17257]106            'ac,amount_auth,creation_date,gateway_amt,net_amt,p_category,p_combi,p_currency,p_current,'
[16437]107            'p_id,p_item,p_level,p_option,p_session,p_state,payment_date,provider_amt,'
[12856]108            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
[17257]109            'r_pay_reference,r_payment_link,rebate_amount,staff_rebate,thirdparty_amt,student_id,state,'
[12856]110            'current_session\r\n'
[17257]111            '666,12.12,%s-04-01 13:12:01#,,,schoolfee,[],,1,my-id,p-item,'
[16437]112            '100,,%s,paid,%s-04-01 14:12:01#,,12.12,'
[17257]113            '789,r-code,interswatch,,,,,,,A111111,created,2012\r\n'
[14421]114            % (curr_year-6, curr_year-6, curr_year-6), result
[12856]115            )
116        return
[16390]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(
[17395]143            'asthma,body_pains,breathing,catarrh,company_confirmed,'
144            'company_suspected,cough,diabetes,fever,headaches,hypertension,'
[16390]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,'
[17395]149            'current_level,genotype,bloodgroup\r\n'
150            ',,,,,,,,,,,,,,,,,,,,,1,,,,A111111,Anna M. Tester,234,'
151            'NA,NA,created,2012,200,,\r\n' , result
[16390]152            )
153        return
[17396]154
155curr_year = datetime.datetime.now().year
156year_range = range(curr_year - 11, curr_year + 1)
157year_range_str = ','.join([str(i) for i in year_range])
158
159class NYSCExporterTest(StudentImportExportSetup):
160
161    layer = FunctionalLayer
162
163    def setUp(self):
164        super(NYSCExporterTest, self).setUp()
165        self.setup_for_export()
166        return
167
168    def test_ifaces(self):
169        # make sure we fullfill interface contracts
170        obj = NYSCExporter()
171        verifyObject(ICSVExporter, obj)
172        verifyClass(ICSVExporter, NYSCExporter)
173        return
174
175    def test_export_all(self):
176        # we can really export students
177        # set values we can expect in export file
178        self.setup_student(self.student)
179        self.student.nysc = True
[17862]180        self.student.nysc_verdict = 'B'
[17835]181        self.student.nysc_processed = False
[17849]182        self.student.lga = u'cross_river_abc'
[17396]183        exporter = NYSCExporter()
184        exporter.export_all(self.app, self.outfile)
185        result = open(self.outfile, 'rb').read()
186        self.assertMatches(
187            'student_id,matric_number,reg_number,firstname,middlename,lastname,'
[17897]188            'sex,email,email2,phone,nationality,date_of_birth,state,lg_state,lg_area,current_mode,'
[17862]189            'certificate,faccode,depcode,current_level,current_session,'
190            'current_verdict,entry_session,nysc_verdict,nysc_senate_info,'
191            'nysc_date_of_graduation,nysc_updated,nysc_processed,%s\r\n'
[17897]192            'A111111,234,123,Anna,M.,Tester,f,anna@sample.com,,+234-123-12345,NG,1981-02-04#,created,'
[17862]193            'cross-river,abc,ug_ft,Unnamed Certificate,NA,NA,200,2012,0,2010,'
194            'Student with carryover courses,,,,0,,,,,,'
195            '12.12,,,,,,\r\n' % year_range_str,
[17396]196            result
197            )
198        return
Note: See TracBrowser for help on using the repository browser.