source: main/kofacustom.sampleuni/trunk/src/kofacustom/sampleuni/students/tests/test_export.py @ 17943

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

Pin waeup.kofa 1.5

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