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

« back to all changes in this revision

Viewing changes to src/schooltool/intervention/generations/tests/test_evolve4.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
# coding=UTF8
 
2
#
 
3
# SchoolTool - common information systems platform for school administration
 
4
# Copyright (c) 2009 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.intervention.generations.evolve4
 
22
"""
 
23
 
 
24
import unittest
 
25
import doctest
 
26
 
 
27
from zope.app.testing import setup
 
28
from zope.component.hooks import setSite
 
29
from zope.interface import implements
 
30
from zope.site.folder import Folder
 
31
 
 
32
from schooltool.app.interfaces import ISchoolToolApplication
 
33
from schooltool.generations.tests import ContextStub
 
34
from schooltool.intervention.generations.evolve4 import evolve
 
35
from schooltool.intervention.interfaces import IInterventionGoal
 
36
 
 
37
 
 
38
class AppStub(Folder):
 
39
    implements(ISchoolToolApplication)
 
40
 
 
41
 
 
42
class GoalStub(object):
 
43
    implements(IInterventionGoal)
 
44
    _persons_responsible = []
 
45
    __dict__ = {'persons_responsible': ['jdoe']}
 
46
    at_one_time_responsible = []
 
47
 
 
48
 
 
49
def doctest_evolve4():
 
50
    """Evolution to generation 4.
 
51
 
 
52
    First, we'll set up the app object:
 
53
 
 
54
        >>> context = ContextStub()
 
55
        >>> context.root_folder['app'] = app = AppStub()
 
56
        >>> app[u'schooltool.interventions'] = {}
 
57
        >>> manager = setup.createSiteManager(app)
 
58
 
 
59
    We'll set up our test with data that will be effected by running the
 
60
    evolve script:
 
61
 
 
62
        >>> root = app[u'schooltool.interventions']
 
63
        >>> year = root['2009'] = {}
 
64
        >>> student = year['jdoe'] = {}
 
65
 
 
66
        >>> goals = student['goals'] = {}
 
67
        >>> goal1 = goals['1'] = GoalStub()
 
68
 
 
69
    Finally, we'll run the evolve script, testing the effected values before and
 
70
    after:
 
71
 
 
72
        >>> goal1.__dict__['persons_responsible']
 
73
        ['jdoe']
 
74
        >>> goal1._persons_responsible
 
75
        []
 
76
        >>> goal1.at_one_time_responsible
 
77
        []
 
78
 
 
79
        >>> evolve(context)
 
80
 
 
81
        >>> 'persons_responsible' in goal1.__dict__
 
82
        False
 
83
        >>> goal1._persons_responsible
 
84
        ['jdoe']
 
85
        >>> goal1.at_one_time_responsible
 
86
        ['jdoe']
 
87
 
 
88
    What if the intervention container doesn't exist yet in the
 
89
    application:
 
90
 
 
91
        >>> context = ContextStub()
 
92
        >>> context.root_folder['app'] = app = AppStub()
 
93
        >>> manager = setup.createSiteManager(app)
 
94
        >>> evolve(context)
 
95
 
 
96
    """
 
97
 
 
98
 
 
99
def setUp(test):
 
100
    setup.placefulSetUp()
 
101
    setSite()
 
102
 
 
103
def tearDown(test):
 
104
    setup.placefulTearDown()
 
105
    setSite()
 
106
 
 
107
 
 
108
def test_suite():
 
109
    return unittest.TestSuite([
 
110
        doctest.DocTestSuite(setUp=setUp, tearDown=tearDown,
 
111
                             optionflags=doctest.ELLIPSIS
 
112
                             | doctest.NORMALIZE_WHITESPACE
 
113
                             | doctest.REPORT_NDIFF
 
114
                             | doctest.REPORT_ONLY_FIRST_FAILURE),
 
115
        ])
 
116
 
 
117
if __name__ == '__main__':
 
118
    unittest.main(defaultTest='test_suite')
 
119