~ubuntu-branches/ubuntu/raring/schooltool.intervention/raring

« back to all changes in this revision

Viewing changes to src/schooltool/intervention/tests/test_intervention.py

  • Committer: Bazaar Package Importer
  • Author(s): Gediminas Paulauskas
  • Date: 2011-02-24 17:10:33 UTC
  • Revision ID: james.westby@ubuntu.com-20110224171033-8wflfqxxe3zld6bf
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# SchoolTool - common information systems platform for school administration
 
3
# Copyright (c) 2005 Shuttleworth Foundation
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
#
 
19
"""
 
20
Unit tests for the schooltool.intervention.intervention.
 
21
"""
 
22
import unittest
 
23
import doctest
 
24
 
 
25
from zope.app.testing.placelesssetup import setUp, tearDown
 
26
from zope.component import provideAdapter
 
27
from zope.interface import implements
 
28
 
 
29
from schooltool.app.interfaces import ISchoolToolApplication
 
30
from schooltool.intervention import intervention
 
31
 
 
32
 
 
33
def doctest_PersonRemovedSubsciber():
 
34
    """
 
35
    First we need some stubs.
 
36
 
 
37
        >>> class PersonStub:
 
38
        ...     def __init__(self, username):
 
39
        ...         self.username = username
 
40
 
 
41
        >>> class AppStub(dict):
 
42
        ...    implements(ISchoolToolApplication)
 
43
 
 
44
    We need to create an application, intervention root, intervention school
 
45
    year and a couple intervention students.
 
46
 
 
47
        >>> app = AppStub()
 
48
        >>> app['schooltool.interventions'] = root = {}
 
49
        >>> root['2009'] = year = {}
 
50
        >>> year['student1'] = 'Student One'
 
51
        >>> year['student2'] = 'Student Two'
 
52
 
 
53
    We need an adapter to get the app.
 
54
 
 
55
        >>> provideAdapter(lambda x: app, (None,), ISchoolToolApplication)
 
56
 
 
57
    We'll load the subscriber with student1 and see how the intervention
 
58
    student object will disappear.
 
59
 
 
60
        >>> student1 = PersonStub('student1')
 
61
        >>> subscriver = intervention.PersonRemovedSubsciber(None, student1)
 
62
        >>> subscriver()
 
63
        >>> sorted(year.keys())
 
64
        ['student2']
 
65
    """
 
66
 
 
67
 
 
68
def doctest_SchoolYearRemovedSubsciber():
 
69
    """
 
70
    First we need some stubs.
 
71
 
 
72
        >>> class SchoolYearStub:
 
73
        ...     def __init__(self, name):
 
74
        ...         self.__name__ = name
 
75
 
 
76
        >>> class AppStub(dict):
 
77
        ...    implements(ISchoolToolApplication)
 
78
 
 
79
    We need to create an application, an intervention root and a couple
 
80
    intervention schoolyears.
 
81
 
 
82
        >>> app = AppStub()
 
83
        >>> app['schooltool.interventions'] = root = {}
 
84
        >>> root['2008'] = {}
 
85
        >>> root['2009'] = {}
 
86
 
 
87
    We need an adapter to get the app.
 
88
 
 
89
        >>> provideAdapter(lambda x: app, (None,), ISchoolToolApplication)
 
90
 
 
91
    We'll load the subscriber with student1 and see how the intervention
 
92
    student object will disappear.
 
93
 
 
94
        >>> year = SchoolYearStub('2009')
 
95
        >>> subscriver = intervention.SchoolYearRemovedSubsciber(None, year)
 
96
        >>> subscriver()
 
97
        >>> sorted(root.keys())
 
98
        ['2008']
 
99
    """
 
100
 
 
101
 
 
102
def test_suite():
 
103
    optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
 
104
    suite = doctest.DocTestSuite(optionflags=optionflags,
 
105
                                 setUp=setUp, tearDown=tearDown)
 
106
    return unittest.TestSuite([suite])
 
107
 
 
108
 
 
109
if __name__ == '__main__':
 
110
    unittest.main(defaultTest='test_suite')
 
111