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

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

Fix test.

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