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

Last change on this file since 13625 was 13625, checked in by Henrik Bettermann, 9 years ago

Adjust to changes in base package.

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