2
# SchoolTool - common information systems platform for school administration
3
# Copyright (c) 2005 Shuttleworth Foundation
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.
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.
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
20
Unit tests for the schooltool.intervention.intervention.
25
from zope.app.testing.placelesssetup import setUp, tearDown
26
from zope.component import provideAdapter
27
from zope.interface import implements
29
from schooltool.app.interfaces import ISchoolToolApplication
30
from schooltool.intervention import intervention
33
def doctest_PersonRemovedSubsciber():
35
First we need some stubs.
38
... def __init__(self, username):
39
... self.username = username
41
>>> class AppStub(dict):
42
... implements(ISchoolToolApplication)
44
We need to create an application, intervention root, intervention school
45
year and a couple intervention students.
48
>>> app['schooltool.interventions'] = root = {}
49
>>> root['2009'] = year = {}
50
>>> year['student1'] = 'Student One'
51
>>> year['student2'] = 'Student Two'
53
We need an adapter to get the app.
55
>>> provideAdapter(lambda x: app, (None,), ISchoolToolApplication)
57
We'll load the subscriber with student1 and see how the intervention
58
student object will disappear.
60
>>> student1 = PersonStub('student1')
61
>>> subscriver = intervention.PersonRemovedSubsciber(None, student1)
63
>>> sorted(year.keys())
68
def doctest_SchoolYearRemovedSubsciber():
70
First we need some stubs.
72
>>> class SchoolYearStub:
73
... def __init__(self, name):
74
... self.__name__ = name
76
>>> class AppStub(dict):
77
... implements(ISchoolToolApplication)
79
We need to create an application, an intervention root and a couple
80
intervention schoolyears.
83
>>> app['schooltool.interventions'] = root = {}
87
We need an adapter to get the app.
89
>>> provideAdapter(lambda x: app, (None,), ISchoolToolApplication)
91
We'll load the subscriber with student1 and see how the intervention
92
student object will disappear.
94
>>> year = SchoolYearStub('2009')
95
>>> subscriver = intervention.SchoolYearRemovedSubsciber(None, year)
97
>>> sorted(root.keys())
103
optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
104
suite = doctest.DocTestSuite(optionflags=optionflags,
105
setUp=setUp, tearDown=tearDown)
106
return unittest.TestSuite([suite])
109
if __name__ == '__main__':
110
unittest.main(defaultTest='test_suite')