~ubuntu-branches/ubuntu/natty/schooltool.gradebook/natty

« back to all changes in this revision

Viewing changes to src/schooltool/gradebook/generations/tests/test_evolve1.py

  • Committer: Bazaar Package Importer
  • Author(s): Gediminas Paulauskas
  • Date: 2011-02-24 16:53:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110224165353-hi69ckyal3b8dyns
Tags: upstream-0.9.0~a1
ImportĀ upstreamĀ versionĀ 0.9.0~a1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# coding=UTF8
 
2
#
 
3
# SchoolTool - common information systems platform for school administration
 
4
# Copyright (c) 2008 Shuttleworth Foundation
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
#
 
20
"""
 
21
Unit tests for schooltool.gradebook.generations.evolve1
 
22
"""
 
23
 
 
24
import unittest, doctest
 
25
 
 
26
from zope.app.generations.utility import getRootFolder
 
27
 
 
28
from schooltool.gradebook.generations.tests import ContextStub
 
29
from schooltool.gradebook.generations.tests import provideAdapters
 
30
from schooltool.gradebook.generations.evolve1 import evolve
 
31
 
 
32
 
 
33
def doctest_evolve1():
 
34
    """Evolution to generation 1.
 
35
 
 
36
    First, we'll set up the app object:
 
37
 
 
38
        >>> provideAdapters()
 
39
        >>> context = ContextStub()
 
40
        >>> app = getRootFolder(context)
 
41
 
 
42
        >>> from zope.site import LocalSiteManager
 
43
        >>> app.setSiteManager(LocalSiteManager(app))
 
44
 
 
45
    We'll set up our test with data that will be effected by running the
 
46
    evolve script:
 
47
 
 
48
        >>> from schooltool.person.person import PersonContainer, Person
 
49
        >>> app['persons'] = PersonContainer()
 
50
        >>> student = Person('student')
 
51
        >>> app['persons']['student'] = student
 
52
 
 
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
 
59
 
 
60
        >>> from schooltool.gradebook.gradebook_init import setUpGradebookRoot
 
61
        >>> from schooltool.gradebook.interfaces import IGradebookRoot
 
62
        >>> setUpGradebookRoot(app)
 
63
        >>> root = IGradebookRoot(app)
 
64
 
 
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)
 
73
 
 
74
        >>> from schooltool.gradebook.interfaces import IActivities
 
75
        >>> activities = IActivities(section)
 
76
 
 
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)
 
81
 
 
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)
 
87
 
 
88
        >>> from schooltool.requirement.evaluation import Evaluation
 
89
        >>> ev = Evaluation(activity, ExtendedAmericanLetterScoreSystem, 'A+', None)
 
90
        >>> evaluations.addEvaluation(ev)
 
91
 
 
92
    Finally, we'll run the evolve script, testing the effected values before and
 
93
    after:
 
94
 
 
95
        >>> from schooltool.requirement.interfaces import IScoreSystemsProxy
 
96
        >>> proxy = IScoreSystemsProxy(app)
 
97
        >>> proxy.getScoreSystems()
 
98
        []
 
99
 
 
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'>
 
106
        >>> ev.scoreSystem
 
107
        <GlobalDiscreteValuesScoreSystem u'Extended Letter Grade'>
 
108
 
 
109
        >>> evolve(context)
 
110
 
 
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'>)]
 
115
 
 
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'>
 
122
        >>> ev.scoreSystem
 
123
        <CustomScoreSystem u'Extended Letter Grade'>
 
124
    """
 
125
 
 
126
 
 
127
def test_suite():
 
128
    return unittest.TestSuite([
 
129
        doctest.DocTestSuite(optionflags=doctest.ELLIPSIS
 
130
                                         | doctest.NORMALIZE_WHITESPACE
 
131
                                         | doctest.REPORT_NDIFF
 
132
                                         | doctest.REPORT_ONLY_FIRST_FAILURE),
 
133
        ])
 
134
 
 
135
if __name__ == '__main__':
 
136
    unittest.main(defaultTest='test_suite')
 
137