This file is indexed.

/usr/lib/python2.7/dist-packages/schooltool/intervention/generations/tests/test_evolve7.py is in python-schooltool.intervention 2.7.1-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# coding=UTF8
#
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2009 Shuttleworth Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
"""
Unit tests for schooltool.intervention.generations.evolve7
"""

from datetime import datetime
import unittest
import doctest

from persistent import Persistent
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.app.generations.utility import getRootFolder
from zope.app.testing import setup
from zope.component.hooks import getSite, setSite
from zope.container.btree import BTreeContainer
from zope.container.contained import Contained
from zope.interface import implements
from zope.site.folder import Folder

from schooltool.app.interfaces import ISchoolToolApplication
from schooltool.basicperson.person import BasicPerson
from schooltool.contact.contact import Contact
from schooltool.contact.interfaces import IContactable
from schooltool.generations.tests import ContextStub
from schooltool.generations.tests import setUp, tearDown
from schooltool.person.interfaces import IPerson

from schooltool.intervention.generations.tests import provideAdapters
from schooltool.intervention.generations.evolve7 import evolve
from schooltool.intervention.intervention import InterventionMessage
from schooltool.intervention.intervention import InterventionGoal


class ParentStub(Persistent, Contained):
    implements(IAttributeAnnotatable)
    first_name = 'Parent'
    last_name = 'Name'


def contactName(contact):
    return '%s %s' % (contact.first_name, contact.last_name)


def doctest_evolve7():
    """Evolution to generation 7.

    We need an app.

        >>> provideAdapters()
        >>> context = ContextStub(app)

    We need a teacher, a student and a parent.

        >>> persons = app[u'persons'] = BTreeContainer()
        >>> jteacher = persons['jteacher'] = BasicPerson('jteacher', 'John', 'Teacher')
        >>> jstudent = persons['jstudent'] = BasicPerson('jstudent', 'Jane', 'Student')
        >>> parent = persons['parent'] = ParentStub()
        >>> IContactable(jstudent).contacts.add(parent)

    Finally we need an intervention root, schoolyear and student.

        >>> root = app[u'schooltool.interventions'] = BTreeContainer()
        >>> year = root['thisyear'] = BTreeContainer()
        >>> student = year['jstudent'] = BTreeContainer()
        >>> messages = student['messages'] = BTreeContainer()
        >>> goals = student['goals'] = BTreeContainer()

    Our first test will be with a message and goal with all good ids.

        >>> message1 = messages['1'] = InterventionMessage('', '', '')
        >>> message1.__dict__['sender'] = 'jteacher'
        >>> message1.__dict__['recipients'] = ['jstudent', 'jstudent:1']

        >>> goal1 = goals['1'] = InterventionGoal('', '', '', '', '', '', '', 
        ...                                       '')
        >>> goal1.__dict__['creator'] = 'jteacher'
        >>> goal1.__dict__['_persons_responsible'] = ['jstudent', 'jstudent:1']
        >>> goal1.__dict__['at_one_time_responsible'] = ['jstudent', 'jstudent:1']

    We'll run the evolve script, testing the effected values before and after:

        >>> message1.__dict__['sender']
        'jteacher'
        >>> message1.__dict__['recipients']
        ['jstudent', 'jstudent:1']
        >>> goal1.__dict__['creator']
        'jteacher'
        >>> goal1.__dict__['_persons_responsible']
        ['jstudent', 'jstudent:1']
        >>> goal1.__dict__['at_one_time_responsible']
        ['jstudent', 'jstudent:1']

        >>> evolve(context)

        >>> 'sender' in message1.__dict__
        False
        >>> [contactName(contact) for contact in message1.sender]
        ['John Teacher']
        >>> 'recipients' in message1.__dict__
        False
        >>> [contactName(contact) for contact in message1.recipients]
        ['Jane Student', 'Parent Name']
        >>> 'creator' in goal1.__dict__
        False
        >>> [contactName(contact) for contact in goal1.creator]
        ['John Teacher']
        >>> '_persons_responsible' in goal1.__dict__
        False
        >>> [contactName(contact) for contact in goal1._persons_responsible]
        ['Jane Student', 'Parent Name']
        >>> 'at_one_time_responsible' in goal1.__dict__
        False
        >>> [contactName(contact) for contact in goal1.at_one_time_responsible]
        ['Jane Student', 'Parent Name']

    Our second test will be with a message and goal with invalid ids.

        >>> message2 = messages['2'] = InterventionMessage('', '', '')
        >>> message2.__dict__['sender'] = 'invalid_id'
        >>> message2.__dict__['recipients'] = ['invalid_id', 'jstudent:2']

        >>> goal2 = goals['2'] = InterventionGoal('', '', '', '', '', '', '', 
        ...                                       '')
        >>> goal2.__dict__['creator'] = 'invalid_id'
        >>> goal2.__dict__['_persons_responsible'] = ['invalid_id', 'jstudent:2']
        >>> goal2.__dict__['at_one_time_responsible'] = ['invalid_id', 'invalid_id:1']

    We'll run the evolve script, testing the effected values before and after:

        >>> message2.__dict__['sender']
        'invalid_id'
        >>> message2.__dict__['recipients']
        ['invalid_id', 'jstudent:2']
        >>> goal2.__dict__['creator']
        'invalid_id'
        >>> goal2.__dict__['_persons_responsible']
        ['invalid_id', 'jstudent:2']
        >>> goal2.__dict__['at_one_time_responsible']
        ['invalid_id', 'invalid_id:1']

        >>> evolve(context)

        >>> 'sender' in message2.__dict__
        False
        >>> [contactName(contact) for contact in message2.sender]
        []
        >>> 'recipients' in message2.__dict__
        False
        >>> [contactName(contact) for contact in message2.recipients]
        []
        >>> 'creator' in goal2.__dict__
        False
        >>> [contactName(contact) for contact in goal2.creator]
        []
        >>> '_persons_responsible' in goal2.__dict__
        False
        >>> [contactName(contact) for contact in goal2._persons_responsible]
        []
        >>> 'at_one_time_responsible' in goal2.__dict__
        False
        >>> [contactName(contact) for contact in goal2.at_one_time_responsible]
        []

    What if the intervention container doesn't exist yet in the
    application:

        >>> del app[u'schooltool.interventions']
        >>> context = ContextStub(app)
        >>> evolve(context)

    """


def test_suite():
    return unittest.TestSuite([
        doctest.DocTestSuite(setUp=setUp, tearDown=tearDown,
                             optionflags=doctest.ELLIPSIS
                             | doctest.NORMALIZE_WHITESPACE
                             | doctest.REPORT_NDIFF
                             | doctest.REPORT_ONLY_FIRST_FAILURE),
        ])


if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')