~ubuntu-branches/ubuntu/quantal/schooltool.intervention/quantal-201209201712

« back to all changes in this revision

Viewing changes to src/schooltool/intervention/generations/tests/test_evolve2.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.evolve2
 
22
"""
 
23
 
 
24
from datetime import datetime
 
25
import unittest
 
26
import doctest
 
27
 
 
28
from zope.app.generations.utility import getRootFolder
 
29
 
 
30
from schooltool.generations.tests import ContextStub
 
31
from schooltool.intervention.generations.tests import provideAdapters
 
32
from schooltool.intervention.generations.evolve2 import evolve
 
33
from schooltool.intervention.intervention import InterventionMessage
 
34
from schooltool.intervention.intervention import InterventionGoal
 
35
 
 
36
 
 
37
def doctest_evolve2():
 
38
    """Evolution to generation 2.
 
39
 
 
40
    First, we'll set up the app object:
 
41
 
 
42
        >>> provideAdapters()
 
43
        >>> context = ContextStub()
 
44
        >>> app = getRootFolder(context)
 
45
 
 
46
    We'll set up our test with data that will be effected by running the
 
47
    evolve script:
 
48
 
 
49
        >>> root = app[u'schooltool.interventions'] = {}
 
50
        >>> year = root['2009'] = {}
 
51
        >>> student = year['jdoe'] = {}
 
52
 
 
53
        >>> messages = student['messages'] = {}
 
54
        >>> message1 = messages['1'] = InterventionMessage('', '', '')
 
55
        >>> message1.created = datetime.now()
 
56
 
 
57
        >>> goals = student['goals'] = {}
 
58
        >>> goal1 = goals['1'] = InterventionGoal('', '', '', '', '', '', '', 
 
59
        ...                                       '')
 
60
        >>> goal1.created = datetime.now()
 
61
 
 
62
    Finally, we'll run the evolve script, testing the effected values before and
 
63
    after:
 
64
 
 
65
        >>> message1.created.tzinfo is None
 
66
        True
 
67
        >>> goal1.created.tzinfo is None
 
68
        True
 
69
 
 
70
        >>> evolve(context)
 
71
 
 
72
        >>> message1.created.tzinfo is None
 
73
        False
 
74
        >>> goal1.created.tzinfo is None
 
75
        False
 
76
 
 
77
    What if the intervention container doesn't exist yet in the
 
78
    application:
 
79
 
 
80
        >>> context = ContextStub()
 
81
        >>> app = getRootFolder(context)
 
82
        >>> evolve(context)
 
83
 
 
84
    """
 
85
 
 
86
 
 
87
def test_suite():
 
88
    return unittest.TestSuite([
 
89
        doctest.DocTestSuite(optionflags=doctest.ELLIPSIS
 
90
                                         | doctest.NORMALIZE_WHITESPACE
 
91
                                         | doctest.REPORT_NDIFF
 
92
                                         | doctest.REPORT_ONLY_FIRST_FAILURE),
 
93
        ])
 
94
 
 
95
if __name__ == '__main__':
 
96
    unittest.main(defaultTest='test_suite')
 
97