3
# SchoolTool - common information systems platform for school administration
4
# Copyright (c) 2008 Shuttleworth Foundation
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
Unit tests for schooltool.gradebook.generations.evolve1
26
from zope.app.zopeappgenerations import getRootFolder
27
from zope.testing import doctest
29
from schooltool.app.interfaces import ISchoolToolApplication
30
from schooltool.gradebook.generations.tests import ContextStub
31
from schooltool.gradebook.generations.tests import provideAdapters
32
from schooltool.gradebook.generations.evolve1 import evolve
33
from schooltool.requirement.interfaces import IHaveEvaluations
36
def doctest_evolve1():
37
"""Evolution to generation 1.
39
First, we'll set up the app object:
42
>>> context = ContextStub()
43
>>> app = getRootFolder(context)
45
>>> from zope.app.component.site import LocalSiteManager
46
>>> app.setSiteManager(LocalSiteManager(app))
48
We'll set up our test with data that will be effected by running the
51
>>> from schooltool.person.person import PersonContainer, Person
52
>>> app['persons'] = PersonContainer()
53
>>> student = Person('student')
54
>>> app['persons']['student'] = student
56
>>> from schooltool.course.section import SectionContainerContainer
57
>>> from schooltool.course.section import SectionContainer, Section
58
>>> app['schooltool.course.section'] = SectionContainerContainer()
59
>>> app['schooltool.course.section']['1'] = SectionContainer()
60
>>> section = Section('section')
61
>>> app['schooltool.course.section']['1']['1'] = section
63
>>> from schooltool.gradebook.gradebook_init import setUpGradebookRoot
64
>>> from schooltool.gradebook.interfaces import IGradebookRoot
65
>>> setUpGradebookRoot(app)
66
>>> root = IGradebookRoot(app)
68
>>> from schooltool.requirement.scoresystem import PassFail
69
>>> from schooltool.requirement.scoresystem import AmericanLetterScoreSystem
70
>>> from schooltool.gradebook.activity import ReportWorksheet
71
>>> from schooltool.gradebook.activity import ReportActivity
72
>>> root.templates['1'] = temp_ws = ReportWorksheet('1')
73
>>> temp_ws['1'] = temp_act = ReportActivity('1', None, PassFail)
74
>>> root.deployed['1'] = dep_ws = ReportWorksheet('1')
75
>>> dep_ws['1'] = dep_act = ReportActivity('1', None, AmericanLetterScoreSystem)
77
>>> from schooltool.gradebook.interfaces import IActivities
78
>>> activities = IActivities(section)
80
>>> from schooltool.requirement.scoresystem import ExtendedAmericanLetterScoreSystem
81
>>> from schooltool.gradebook.activity import Worksheet, Activity
82
>>> activities['1'] = worksheet = Worksheet('1')
83
>>> worksheet['1'] = activity = Activity('1', None, ExtendedAmericanLetterScoreSystem)
85
>>> from schooltool.requirement.interfaces import IHaveEvaluations
86
>>> from schooltool.requirement.interfaces import IEvaluations
87
>>> from zope.interface import alsoProvides
88
>>> alsoProvides(student, IHaveEvaluations)
89
>>> evaluations = IEvaluations(student)
91
>>> from schooltool.requirement.evaluation import Evaluation
92
>>> ev = Evaluation(activity, ExtendedAmericanLetterScoreSystem, 'A+', None)
93
>>> evaluations.addEvaluation(ev)
95
Finally, we'll run the evolve script, testing the effected values before and
98
>>> from schooltool.requirement.interfaces import IScoreSystemsProxy
99
>>> proxy = IScoreSystemsProxy(app)
100
>>> proxy.getScoreSystems()
103
>>> temp_act.scoresystem
104
<GlobalDiscreteValuesScoreSystem u'Pass/Fail'>
105
>>> dep_act.scoresystem
106
<GlobalDiscreteValuesScoreSystem u'Letter Grade'>
107
>>> activity.scoresystem
108
<GlobalDiscreteValuesScoreSystem u'Extended Letter Grade'>
110
<GlobalDiscreteValuesScoreSystem u'Extended Letter Grade'>
114
>>> proxy.getScoreSystems()
115
[(u'Extended Letter Grade', <CustomScoreSystem u'Extended Letter Grade'>),
116
(u'Letter Grade', <CustomScoreSystem u'Letter Grade'>),
117
(u'Pass/Fail', <CustomScoreSystem u'Pass/Fail'>)]
119
>>> temp_act.scoresystem
120
<CustomScoreSystem u'Pass/Fail'>
121
>>> dep_act.scoresystem
122
<CustomScoreSystem u'Letter Grade'>
123
>>> activity.scoresystem
124
<CustomScoreSystem u'Extended Letter Grade'>
126
<CustomScoreSystem u'Extended Letter Grade'>
131
return unittest.TestSuite([
132
doctest.DocTestSuite(optionflags=doctest.ELLIPSIS
133
| doctest.NORMALIZE_WHITESPACE
134
| doctest.REPORT_NDIFF
135
| doctest.REPORT_ONLY_FIRST_FAILURE),
138
if __name__ == '__main__':
139
unittest.main(defaultTest='test_suite')