source: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_export.py @ 14595

Last change on this file since 14595 was 14595, checked in by Henrik Bettermann, 8 years ago

Export level and level_session too.

  • Property svn:keywords set to Id
File size: 8.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 waeup.aaue.utils.utils import CustomKofaUtils
9from waeup.aaue.students.export import (
10    CustomStudentExporter, CustomStudentPaymentExporter,
11    CustomStudentStudyLevelExporter,
12    CustomCourseTicketExporter,
13    LevelReportDataExporter)
14from waeup.aaue.testing import FunctionalLayer
15
16
17class CustomStudentExporterTest(StudentImportExportSetup):
18
19    layer = FunctionalLayer
20
21    def setUp(self):
22        super(CustomStudentExporterTest, self).setUp()
23        self.setup_for_export()
24        result_entry = ResultEntry(
25            CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0],
26            CustomKofaUtils.EXAM_GRADES[0][0]
27            )
28        self.student.alr_results = [
29            result_entry]
30        self.student.fst_sit_results = [
31            result_entry]
32        self.student.scd_sit_results = [
33            result_entry]
34        return
35
36    def test_ifaces(self):
37        # make sure we fullfill interface contracts
38        obj = CustomStudentExporter()
39        verifyObject(ICSVExporter, obj)
40        verifyClass(ICSVExporter, CustomStudentExporter)
41        return
42
43
44    def disabled_test_export_all(self):
45        # we can really export students
46        # set values we can expect in export file
47        self.setup_student(self.student)
48        exporter = CustomStudentExporter()
49        exporter.export_all(self.app, self.outfile)
50        result = open(self.outfile, 'rb').read()
51        self.assertMatches(
52            'adm_code,alr_date,alr_fname,alr_no,alr_results,'
53            'application_number,clr_code,'
54            'date_of_birth,def_adm,disabled,email,emp2_end,emp2_position,'
55            'emp2_reason,emp2_start,emp_end,emp_position,emp_reason,'
56            'emp_start,employer,employer2,father_address,father_name,'
57            'father_phone,father_work,'
58            'financial_clearance_date,financially_cleared_by,'
59            'firstname,flash_notice,former_matric,fst_sit_date,'
60            'fst_sit_fname,fst_sit_no,fst_sit_results,fst_sit_type,hq2_degree,'
61            'hq2_disc,hq2_matric_no,hq2_school,hq2_session,hq2_type,'
62            'hq_degree,hq_disc,hq_fname,hq_matric_no,hq_school,hq_session,'
63            'hq_type,is_staff,lastname,lga,marit_stat,matric_number,'
64            'middlename,mother_address,mother_name,mother_phone,'
65            'mother_work,nationality,next_kin_address,next_kin_name,'
66            'next_kin_phone,next_kin_relation,nysc_lga,nysc_location,'
67            'nysc_year,officer_comment,perm_address,personal_updated,'
68            'phone,phone_personal,physical_clearance_date,reg_number,'
69            'religion,sc_pin,sc_serial_number,scd_sit_date,'
70            'scd_sit_fname,scd_sit_no,scd_sit_results,'
71            'scd_sit_type,sex,student_id,suspended,suspended_comment,password,'
72            'state,history,certcode,is_postgrad,current_level,current_session'
73            '\r\n'
74            'my adm code,,,,"[(\'printing_craft_practice\', \'A1\')]",,'
75            'my clr code,1981-02-04#,,,anna@sample.com,,,,,,,,,,,,,,,,,Anna,,,,,,'
76            '"[(\'printing_craft_practice\', \'A1\')]",,,,,,,,,,,,,,,,Tester,,,'
77            '234,M.,,,,,NG,,,,,,,,,"Studentroad 21\nLagos 123456\n",,'
78            '+234-123-12345#,,,123,,,,,,,'
79            '"[(\'printing_craft_practice\', \'A1\')]",,f,A111111,0,,,'
80            'created,[u\'2015-10-26 17:45:56 WAT - Record created by system\'],'
81            'CERT1,0,200,2012\r\n',
82            result
83            )
84        return
85
86class CustomStudentPaymentExporterTest(StudentImportExportSetup):
87
88    layer = FunctionalLayer
89
90    def setUp(self):
91        super(CustomStudentPaymentExporterTest, self).setUp()
92        self.setup_for_export()
93        return
94
95    def test_ifaces(self):
96        # make sure we fullfill interface contracts
97        obj = CustomStudentPaymentExporter()
98        verifyObject(ICSVExporter, obj)
99        verifyClass(ICSVExporter, CustomStudentPaymentExporter)
100        return
101
102    def test_export_all(self):
103        # we can really export students
104        # set values we can expect in export file
105        self.setup_student(self.student)
106        self.student['payments']['my-payment'].r_company = 'interswatch'
107        self.student['payments']['my-payment'].r_card_num = '789'
108        exporter = CustomStudentPaymentExporter()
109        exporter.export_all(self.app, self.outfile)
110        result = open(self.outfile, 'rb').read()
111        self.assertMatches(
112            'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,'
113            'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,'
114            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
115            'r_pay_reference,thirdparty_amt,student_id,state,'
116            'current_session\r\n'
117            '666,12.12,%s-04-01 13:12:01#,,schoolfee,1,my-id,p-item,'
118            '100,%s,paid,%s-04-01 14:12:01#,,12.12,'
119            '789,r-code,interswatch,,,,A111111,created,2012\r\n'
120            % (curr_year-6, curr_year-6, curr_year-6), result
121            )
122        return
123
124class CustomStudentStudyLevelExporterTest(StudentImportExportSetup):
125
126    layer = FunctionalLayer
127
128    def setUp(self):
129        super(CustomStudentStudyLevelExporterTest, self).setUp()
130        self.setup_for_export()
131        return
132
133    def test_export_all(self):
134        # we can really export study levels
135        # set values we can expect in export file
136        self.setup_student(self.student)
137        exporter = CustomStudentStudyLevelExporter()
138        exporter.export_all(self.app, self.outfile)
139        result = open(self.outfile, 'rb').read()
140        self.assertEqual(
141            result,
142            'gpa,imported_cgpa,imported_gpa,'
143            'level,level_session,level_verdict,total_credits,'
144            'total_credits_s1,total_credits_s2,'
145            'validated_by,validation_date,'
146            'student_id,matric_number,number_of_tickets,certcode,cgpa\r\n'
147            '0.00,,,100,2012,A,100,,,,,A111111,234,1,CERT1,0.0\r\n'
148            )
149        return
150
151class CustomCourseTicketExporterTest(StudentImportExportSetup):
152
153    layer = FunctionalLayer
154
155    def setUp(self):
156        super(CustomCourseTicketExporterTest, self).setUp()
157        self.setup_for_export()
158        return
159
160    def test_export_all(self):
161        # we can really export all course tickets
162        # set values we can expect in export file
163        self.setup_student(self.student)
164        exporter = CustomCourseTicketExporter()
165        exporter.export_all(self.app, self.outfile)
166        result = open(self.outfile, 'rb').read()
167        self.assertEqual(
168            result,
169            'automatic,ca,carry_over,code,credits,dcode,fcode,level,level_session,'
170            'mandatory,outstanding,passmark,score,semester,title,student_id,certcode,'
171            'display_fullname,matric_number\r\n'
172            '1,,1,CRS1,100,DEP1,FAC1,100,2012,0,0,100,,2,Course 1,A111111,CERT1,'
173            '"TESTER, Anna M.",234\r\n'
174            )
175        return
176
177class LevelReportDataExporterTest(StudentImportExportSetup):
178
179    layer = FunctionalLayer
180
181    def setUp(self):
182        super(LevelReportDataExporterTest, self).setUp()
183        self.setup_for_export()
184        return
185
186    def test_export_all(self):
187        # we can really export study levels
188        # set values we can expect in export file
189        self.setup_student(self.student)
190        exporter = LevelReportDataExporter()
191        exporter.export_all(self.app, self.outfile)
192        result = open(self.outfile, 'rb').read()
193        self.assertEqual(
194            result,
195            'matric_number,display_fullname,level,level_session,'
196            'credits_counted,credits_passed,'
197            'level_gpa,failed_courses,not_taken_courses,cum_credits_taken,'
198            'cum_credits_passed,cgpa,remark\r\n'
199            '234,"TESTER, Anna M.",100,2012,0,0,0.000,,CRS1 ,0,0,0.000,\r\n'
200            )
201        return
202
203
Note: See TracBrowser for help on using the repository browser.