source: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_reports.py @ 9670

Last change on this file since 9670 was 9670, checked in by Henrik Bettermann, 12 years ago

See email 'Re: AsyncReportJob?'.

File size: 3.6 KB
Line 
1# Tests for student related reports
2from zope.interface.verify import verifyClass, verifyObject
3from waeup.kofa.students.reports import (
4    get_students_by, StudentsReport, IStudentsReport)
5from waeup.kofa.students.tests.test_catalog import CatalogTestSetup
6from waeup.kofa.testing import FunctionalLayer
7
8class StudentsReportTests(CatalogTestSetup):
9
10    layer = FunctionalLayer
11
12    states = ('created', 'admitted', 'clearance started',
13              'clearance requested', 'cleared', 'school fee paid',
14              'returning', 'courses registered', 'courses validated', 'Total')
15
16    def test_iface(self):
17        # ensure we fullfill interface contracts
18        obj = StudentsReport(2010, 'Undergraduate Full-Time')
19        verifyClass(IStudentsReport, StudentsReport)
20        verifyObject(IStudentsReport, obj)
21        return
22
23    def test_repr(self):
24        # exec(students_report.__repr__()) <=> students_report
25        obj1 = StudentsReport(2010, 'Undergraduate Full-Time', author='Bob')
26        self.assertEqual(
27            obj1.__repr__(),
28            "StudentsReport(2010, 'Undergraduate Full-Time', author='Bob')")
29        obj_from_str = eval(obj1.__repr__())
30        self.assertEqual(obj_from_str.session, '2010/2011')
31        self.assertEqual(obj_from_str.mode, 'Undergraduate Full-Time')
32        self.assertEqual(obj_from_str.author, 'Bob')
33        return
34
35    #def test_str(self):
36    #    # StudentsReport provide a nice string representation
37    #    obj = StudentsReport(2010, 'Undergraduate Full-Time', author='Bob')
38    #    self.assertEqual(
39    #        obj.__str__()[:65],
40    #        'Students Report '
41    #        '[session=2010/2011, mode=Undergraduate Full-Time]')
42    #    return
43
44    def test_title(self):
45        obj = StudentsReport(2010, 'Undergraduate Full-Time', author='Bob')
46        self.assertTrue(
47            obj.title.startswith(
48            'StudentsReport_2010_2011_Undergraduate_Full-Time_'))
49        return
50
51    def test_get_students_by_session_simple(self):
52        # we can get a table with one student
53        result1 = get_students_by(2010, 'Undergraduate Full-Time')
54        result2 = get_students_by(2009, 'Undergraduate Full-Time')
55        self.assertEqual(
56            result1,
57            ((u'fac1', u'Total',),
58             self.states,
59             ((1, 0, 0, 0, 0, 0, 0, 0, 0, 1),
60              (1, 0, 0, 0, 0, 0, 0, 0, 0, 1),)))
61        self.assertEqual(
62            result2,
63            ((u'fac1', u'Total'),
64             self.states,
65             ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
66              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0),)))
67        return
68
69    def test_get_students_by_session_multiple(self):
70        # we can get a table with several students
71        self.create_cert('fac2', 'dept2', 'CERT2')
72        result1 = get_students_by(2010, 'Undergraduate Full-Time')
73        result2 = get_students_by(2009, 'Undergraduate Full-Time')
74        self.assertEqual(
75            result1,
76            ((u'fac1', u'fac2', u'Total'),
77             self.states,
78             ((1, 0, 0, 0, 0, 0, 0, 0, 0, 1),
79              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
80              (1, 0, 0, 0, 0, 0, 0, 0, 0, 1),)))
81        self.assertEqual(
82            result2,
83            ((u'fac1', u'fac2', u'Total'),
84             self.states,
85             ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
86              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
87              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0),)))
88        return
89
90    def test_create_pdf(self):
91        self.create_cert('FAC2', 'dept2', 'CERT2')
92        report = StudentsReport(2010, 'Undergraduate Full-Time')
93        result = report.create_pdf()
94        self.assertTrue(result.startswith('%PDF-'))
95        return
Note: See TracBrowser for help on using the repository browser.