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
24
import unittest, doctest
26
from zope.app.generations.utility import getRootFolder
28
from schooltool.gradebook.generations.tests import ContextStub
29
from schooltool.gradebook.generations.tests import provideAdapters
30
from schooltool.gradebook.generations.evolve1 import evolve
33
def doctest_evolve1():
34
"""Evolution to generation 1.
36
First, we'll set up the app object:
39
>>> context = ContextStub()
40
>>> app = getRootFolder(context)
42
>>> from zope.site import LocalSiteManager
43
>>> app.setSiteManager(LocalSiteManager(app))
45
We'll set up our test with data that will be effected by running the
48
>>> from schooltool.person.person import PersonContainer, Person
49
>>> app['persons'] = PersonContainer()
50
>>> student = Person('student')
51
>>> app['persons']['student'] = student
53
>>> from schooltool.course.section import SectionContainerContainer
54
>>> from schooltool.course.section import SectionContainer, Section
55
>>> app['schooltool.course.section'] = SectionContainerContainer()
56
>>> app['schooltool.course.section']['1'] = SectionContainer()
57
>>> section = Section('section')
58
>>> app['schooltool.course.section']['1']['1'] = section
60
>>> from schooltool.gradebook.gradebook_init import setUpGradebookRoot
61
>>> from schooltool.gradebook.interfaces import IGradebookRoot
62
>>> setUpGradebookRoot(app)
63
>>> root = IGradebookRoot(app)
65
>>> from schooltool.requirement.scoresystem import PassFail
66
>>> from schooltool.requirement.scoresystem import AmericanLetterScoreSystem
67
>>> from schooltool.gradebook.activity import ReportWorksheet
68
>>> from schooltool.gradebook.activity import ReportActivity
69
>>> root.templates['1'] = temp_ws = ReportWorksheet('1')
70
>>> temp_ws['1'] = temp_act = ReportActivity('1', None, PassFail)
71
>>> root.deployed['1'] = dep_ws = ReportWorksheet('1')
72
>>> dep_ws['1'] = dep_act = ReportActivity('1', None, AmericanLetterScoreSystem)
74
>>> from schooltool.gradebook.interfaces import IActivities
75
>>> activities = IActivities(section)
77
>>> from schooltool.requirement.scoresystem import ExtendedAmericanLetterScoreSystem
78
>>> from schooltool.gradebook.activity import Worksheet, Activity
79
>>> activities['1'] = worksheet = Worksheet('1')
80
>>> worksheet['1'] = activity = Activity('1', None, ExtendedAmericanLetterScoreSystem)
82
>>> from schooltool.requirement.interfaces import IHaveEvaluations
83
>>> from schooltool.requirement.interfaces import IEvaluations
84
>>> from zope.interface import alsoProvides
85
>>> alsoProvides(student, IHaveEvaluations)
86
>>> evaluations = IEvaluations(student)
88
>>> from schooltool.requirement.evaluation import Evaluation
89
>>> ev = Evaluation(activity, ExtendedAmericanLetterScoreSystem, 'A+', None)
90
>>> evaluations.addEvaluation(ev)
92
Finally, we'll run the evolve script, testing the effected values before and
95
>>> from schooltool.requirement.interfaces import IScoreSystemsProxy
96
>>> proxy = IScoreSystemsProxy(app)
97
>>> proxy.getScoreSystems()
100
>>> temp_act.scoresystem
101
<GlobalDiscreteValuesScoreSystem u'Pass/Fail'>
102
>>> dep_act.scoresystem
103
<GlobalDiscreteValuesScoreSystem u'Letter Grade'>
104
>>> activity.scoresystem
105
<GlobalDiscreteValuesScoreSystem u'Extended Letter Grade'>
107
<GlobalDiscreteValuesScoreSystem u'Extended Letter Grade'>
111
>>> proxy.getScoreSystems()
112
[(u'Extended Letter Grade', <CustomScoreSystem u'Extended Letter Grade'>),
113
(u'Letter Grade', <CustomScoreSystem u'Letter Grade'>),
114
(u'Pass/Fail', <CustomScoreSystem u'Pass/Fail'>)]
116
>>> temp_act.scoresystem
117
<CustomScoreSystem u'Pass/Fail'>
118
>>> dep_act.scoresystem
119
<CustomScoreSystem u'Letter Grade'>
120
>>> activity.scoresystem
121
<CustomScoreSystem u'Extended Letter Grade'>
123
<CustomScoreSystem u'Extended Letter Grade'>
128
return unittest.TestSuite([
129
doctest.DocTestSuite(optionflags=doctest.ELLIPSIS
130
| doctest.NORMALIZE_WHITESPACE
131
| doctest.REPORT_NDIFF
132
| doctest.REPORT_ONLY_FIRST_FAILURE),
135
if __name__ == '__main__':
136
unittest.main(defaultTest='test_suite')