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

« back to all changes in this revision

Viewing changes to src/schooltool/intervention/generations/tests/test_evolve6.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.evolve6
 
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.evolve6 import evolve
 
35
 
 
36
 
 
37
class AppStub(Folder):
 
38
    implements(ISchoolToolApplication)
 
39
 
 
40
 
 
41
def doctest_evolve6():
 
42
    """Evolution to generation 6.
 
43
 
 
44
    First, we'll set up the app object:
 
45
 
 
46
        >>> context = ContextStub()
 
47
        >>> context.root_folder['app'] = app = AppStub()
 
48
        >>> manager = setup.createSiteManager(app)
 
49
 
 
50
    We'll set up our test with data that will be effected by running the
 
51
    evolve script:
 
52
 
 
53
        >>> app[u'schooltool.schoolyear'] = {'2009': ''}
 
54
        >>> root = app[u'schooltool.interventions'] = {}
 
55
        >>> root['2008'] = {}
 
56
        >>> root['2009'] = {}
 
57
 
 
58
    Finally, we'll run the evolve script, testing the effected values before and
 
59
    after:
 
60
 
 
61
        >>> sorted(root.keys())
 
62
        ['2008', '2009']
 
63
 
 
64
        >>> evolve(context)
 
65
 
 
66
        >>> sorted(root.keys())
 
67
        ['2009']
 
68
 
 
69
    What if the intervention container doesn't exist yet in the
 
70
    application:
 
71
 
 
72
        >>> context = ContextStub()
 
73
        >>> context.root_folder['app'] = app = AppStub()
 
74
        >>> manager = setup.createSiteManager(app)
 
75
        >>> evolve(context)
 
76
 
 
77
    """
 
78
 
 
79
 
 
80
def setUp(test):
 
81
    setup.placefulSetUp()
 
82
    setSite()
 
83
 
 
84
def tearDown(test):
 
85
    setup.placefulTearDown()
 
86
    setSite()
 
87
 
 
88
 
 
89
def test_suite():
 
90
    return unittest.TestSuite([
 
91
        doctest.DocTestSuite(setUp=setUp, tearDown=tearDown,
 
92
                             optionflags=doctest.ELLIPSIS
 
93
                             | doctest.NORMALIZE_WHITESPACE
 
94
                             | doctest.REPORT_NDIFF
 
95
                             | doctest.REPORT_ONLY_FIRST_FAILURE),
 
96
        ])
 
97
 
 
98
if __name__ == '__main__':
 
99
    unittest.main(defaultTest='test_suite')
 
100