source: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py @ 7973

Last change on this file since 7973 was 7973, checked in by Henrik Bettermann, 13 years ago

Add the hash symbol at the end of date_of_birth.

This is to avoid annoying automatic date transformation by Excel or Calc.

File size: 3.6 KB
Line 
1import datetime
2import os
3from zope.catalog.interfaces import ICatalog
4from zope.component import queryUtility, getUtility
5from zope.interface.verify import verifyObject, verifyClass
6from zope.intid.interfaces import IIntIds
7from waeup.kofa.interfaces import ICSVExporter
8from waeup.kofa.students.export import StudentsExporter
9from waeup.kofa.students.student import Student
10from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
11from waeup.kofa.testing import FunctionalLayer
12
13class StudentsExporterTest(StudentImportExportSetup):
14
15    layer = FunctionalLayer
16
17    def setUp(self):
18        super(StudentsExporterTest, self).setUp()
19        student = Student()
20        student.student_id = u'A111111'
21        self.app['students'][student.student_id] = self.student = student
22        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
23        self.cat = getUtility(ICatalog, name='students_catalog')
24        self.intids = getUtility(IIntIds)
25        return
26
27    def test_ifaces(self):
28        # make sure we fullfill interface contracts
29        obj = StudentsExporter()
30        verifyObject(ICSVExporter, obj)
31        verifyClass(ICSVExporter, StudentsExporter)
32        return
33
34    def test_get_as_utility(self):
35        # we can get an student exporter as utility
36        result = queryUtility(ICSVExporter, name="students")
37        self.assertTrue(result is not None)
38        return
39
40    def setup_student(self, student):
41        # set predictable values for `student`
42        student.matric_number = u'M123456'
43        student.adm_code = u'my adm code'
44        student.clearance_locked = False
45        student.clr_code = u'my clr code'
46        student.perm_address = u'Studentroad 21\nLagos 123456\n'
47        student.reg_number = u'123456'
48        student.student_id = u'A111111'
49        student.firstname = u'Anna'
50        student.lastname = u'Tester'
51        student.middlename = u'M.'
52        student.date_of_birth = datetime.date(1981, 2, 4)
53        student.sex = 'f'
54        student.email = 'anna@sample.com'
55        student.phone = u'+234-123-12345'
56        student.notice = u'Some notice\nin lines.'
57        return student
58
59    def test_export(self):
60        # we can really export students
61        # set values we can expect in export file
62        self.setup_student(self.student)
63        exporter = StudentsExporter()
64        exporter.export([self.student], self.outfile)
65        result = open(self.outfile, 'rb').read()
66        self.assertEqual(
67            result,
68            'adm_code,clearance_locked,clr_code,date_of_birth,email,'
69            'firstname,lastname,matric_number,middlename,nationality,'
70            'perm_address,phone,reg_number,sex,student_id\r\n'
71
72            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,Anna,'
73            'Tester,M123456,M.,nigeria,"Studentroad 21\nLagos 123456\n",'
74            '+234-123-12345,123456,f,A111111\r\n'
75            )
76        return
77
78    def test_export_all(self):
79        # we can really export students
80        # set values we can expect in export file
81        self.setup_student(self.student)
82        exporter = StudentsExporter()
83        exporter.export_all(self.app, self.outfile)
84        result = open(self.outfile, 'rb').read()
85        self.assertEqual(
86            result,
87            'adm_code,clearance_locked,clr_code,date_of_birth,email,'
88            'firstname,lastname,matric_number,middlename,nationality,'
89            'perm_address,phone,reg_number,sex,student_id\r\n'
90
91            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,Anna,'
92            'Tester,M123456,M.,nigeria,"Studentroad 21\nLagos 123456\n",'
93            '+234-123-12345,123456,f,A111111\r\n'
94            )
95        return
96
Note: See TracBrowser for help on using the repository browser.