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

Last change on this file since 11621 was 11546, checked in by Henrik Bettermann, 11 years ago

Adapt exporters and batch processors to customized interfaces.

  • Property svn:keywords set to Id
File size: 5.6 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    CustomStudentsExporter, CustomStudentPaymentsExporter,
10    CustomStudentStudyLevelExporter)
11from waeup.aaue.testing import FunctionalLayer
12
13
14class CustomStudentsExporterTest(StudentImportExportSetup):
15
16    layer = FunctionalLayer
17
18    def setUp(self):
19        super(CustomStudentsExporterTest, self).setUp()
20        self.setup_for_export()
21        result_entry = ResultEntry(
22            CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0],
23            CustomKofaUtils.EXAM_GRADES[0][0]
24            )
25        self.student.alr_results = [
26            result_entry]
27        self.student.fst_sit_results = [
28            result_entry]
29        self.student.scd_sit_results = [
30            result_entry]
31        return
32
33    def test_ifaces(self):
34        # make sure we fullfill interface contracts
35        obj = CustomStudentsExporter()
36        verifyObject(ICSVExporter, obj)
37        verifyClass(ICSVExporter, CustomStudentsExporter)
38        return
39
40
41    def test_export_all(self):
42        # we can really export students
43        # set values we can expect in export file
44        self.setup_student(self.student)
45        exporter = CustomStudentsExporter()
46        exporter.export_all(self.app, self.outfile)
47        result = open(self.outfile, 'rb').read()
48        self.assertMatches(
49            'adm_code,alr_date,alr_fname,alr_no,alr_results,clearance_locked,'
50            'clr_code,date_of_birth,def_adm,disabled,email,emp2_end,'
51            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,'
52            'emp_reason,emp_start,employer,employer2,firstname,former_matric,'
53            'fst_sit_date,fst_sit_fname,fst_sit_no,fst_sit_results,'
54            'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,'
55            'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,'
56            'hq_school,hq_session,hq_type,is_staff,lastname,lga,'
57            'marit_stat,matric_number,middlename,nationality,'
58            'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,'
59            'nysc_lga,nysc_location,nysc_year,officer_comment,'
60            'perm_address,personal_updated,phone,reg_number,'
61            'religion,scd_sit_date,scd_sit_fname,scd_sit_no,'
62            'scd_sit_results,scd_sit_type,sex,student_id,'
63            'suspended,suspended_comment,password,state,history,certcode,is_postgrad,'
64            'current_level,current_session\r\nmy adm code,,,,'
65            '"[(\'visual_art\', \'A1\')]",0,my clr code,1981-02-04#,,,'
66            'anna@sample.com,,,,,,,,,,,Anna,,,,,"[(\'visual_art\', \'A1\')]"'
67            ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,'
68            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,123,,,,,'
69            '"[(\'visual_art\', \'A1\')]",,f,A111111,0,,,created,'
70            '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],'
71            'CERT1,0,200,2012\r\n',
72            result
73            )
74        return
75
76class CustomStudentPaymentsExporterTest(StudentImportExportSetup):
77
78    layer = FunctionalLayer
79
80    def setUp(self):
81        super(CustomStudentPaymentsExporterTest, self).setUp()
82        self.setup_for_export()
83        return
84
85    def test_ifaces(self):
86        # make sure we fullfill interface contracts
87        obj = CustomStudentPaymentsExporter()
88        verifyObject(ICSVExporter, obj)
89        verifyClass(ICSVExporter, CustomStudentPaymentsExporter)
90        return
91
92    def test_export_all(self):
93        # we can really export students
94        # set values we can expect in export file
95        self.setup_student(self.student)
96        self.student['payments']['my-payment'].r_company = 'interswatch'
97        self.student['payments']['my-payment'].r_card_num = '789'
98        exporter = CustomStudentPaymentsExporter()
99        exporter.export_all(self.app, self.outfile)
100        result = open(self.outfile, 'rb').read()
101        self.assertMatches(
102            'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,'
103            'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,'
104            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
105            'r_pay_reference,thirdparty_amt,student_id,state,'
106            'current_session\r\n'
107            '666,12.12,2012-04-01 13:12:01,,schoolfee,1,my-id,p-item,'
108            '100,2012,paid,2012-04-01 14:12:01,,12.12,'
109            '789,r-code,interswatch,,,,A111111,created,2012\r\n',
110            result
111            )
112        return
113
114class CustomStudentStudyLevelExporterTest(StudentImportExportSetup):
115
116    layer = FunctionalLayer
117
118    def setUp(self):
119        super(CustomStudentStudyLevelExporterTest, self).setUp()
120        self.setup_for_export()
121        return
122
123    def test_export_all(self):
124        # we can really export study levels
125        # set values we can expect in export file
126        self.setup_student(self.student)
127        exporter = CustomStudentStudyLevelExporter()
128        exporter.export_all(self.app, self.outfile)
129        result = open(self.outfile, 'rb').read()
130        self.assertEqual(
131            result,
132            'gpa,level,level_session,level_verdict,total_credits,'
133            'total_credits_s1,total_credits_s2,'
134            'validated_by,validation_date,'
135            'student_id,number_of_tickets,certcode\r\n'
136            '0.0,100,2012,A,100,,,,,A111111,1,CERT1\r\n'
137            )
138        return
139
Note: See TracBrowser for help on using the repository browser.