source: main/kofacustom.pcn/trunk/src/kofacustom/pcn/students/tests/test_export.py @ 11835

Last change on this file since 11835 was 11832, checked in by Henrik Bettermann, 10 years ago

Replace 'sampleuni' by 'pcn'.

  • Property svn:keywords set to Id
File size: 3.7 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 kofacustom.pcn.utils.utils import CustomKofaUtils
8from kofacustom.pcn.students.export import (
9    CustomStudentsExporter, CustomStudentPaymentsExporter)
10from kofacustom.pcn.testing import FunctionalLayer
11
12
13class CustomStudentsExporterTest(StudentImportExportSetup):
14
15    layer = FunctionalLayer
16
17    def setUp(self):
18        super(CustomStudentsExporterTest, self).setUp()
19        self.setup_for_export()
20        result_entry = ResultEntry(
21            CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0],
22            CustomKofaUtils.EXAM_GRADES[0][0]
23            )
24        self.student.alr_results = [
25            result_entry]
26        self.student.fst_sit_results = [
27            result_entry]
28        self.student.scd_sit_results = [
29            result_entry]
30        return
31
32    def test_ifaces(self):
33        # make sure we fullfill interface contracts
34        obj = CustomStudentsExporter()
35        verifyObject(ICSVExporter, obj)
36        verifyClass(ICSVExporter, CustomStudentsExporter)
37        return
38
39
40    def test_export_all(self):
41        # we can really export students
42        # set values we can expect in export file
43        self.setup_student(self.student)
44        exporter = CustomStudentsExporter()
45        exporter.export_all(self.app, self.outfile)
46        result = open(self.outfile, 'rb').read()
47        self.assertMatches(
48            'adm_code,clearance_locked,clr_code,date_of_birth,email,'
49            'employer,firstname,lastname,matric_number,middlename,'
50            'nationality,officer_comment,perm_address,personal_updated,'
51            'phone,reg_number,sex,student_id,suspended,suspended_comment,'
52            'password,state,history,certcode,is_postgrad,current_level,'
53            'current_session\r\nmy adm code,0,my clr code,1981-02-04#,'
54            'anna@sample.com,,Anna,Tester,234,M.,NG,,'
55            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,123,'
56            'f,A111111,0,,,created,'
57            '[u\'2014-06-16 08:23:55 UTC - Record created by system\'],'
58            'CERT1,0,200,2012\r\n',
59            result
60            )
61        return
62
63class CustomStudentPaymentsExporterTest(StudentImportExportSetup):
64
65    layer = FunctionalLayer
66
67    def setUp(self):
68        super(CustomStudentPaymentsExporterTest, self).setUp()
69        self.setup_for_export()
70        return
71
72    def test_ifaces(self):
73        # make sure we fullfill interface contracts
74        obj = CustomStudentPaymentsExporter()
75        verifyObject(ICSVExporter, obj)
76        verifyClass(ICSVExporter, CustomStudentPaymentsExporter)
77        return
78
79    def test_export_all(self):
80        # we can really export students
81        # set values we can expect in export file
82        self.setup_student(self.student)
83        self.student['payments']['my-payment'].r_company = 'interswatch'
84        self.student['payments']['my-payment'].r_card_num = '789'
85        exporter = CustomStudentPaymentsExporter()
86        exporter.export_all(self.app, self.outfile)
87        result = open(self.outfile, 'rb').read()
88        self.assertMatches(
89            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
90            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
91            'r_code,r_desc,student_id,state,current_session\r\n666,'
92            '12.12,2012-04-01 13:12:01,schoolfee,1,my-id,p-item,'
93            '100,2012,paid,2012-04-01 14:12:01,12.12,r-code,,'
94            'A111111,created,2012\r\n',
95            result
96            )
97        return
Note: See TracBrowser for help on using the repository browser.