This file is indexed.

/usr/lib/python2.7/dist-packages/schooltool/gradebook/generations/tests/test_evolve4.py is in python-schooltool.gradebook 2.6.3-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
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2011 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.gradebook.generations.evolve4
"""

import unittest, doctest

from persistent.mapping import PersistentMapping
from zope.annotation.interfaces import IAnnotations
from zope.app.generations.utility import getRootFolder
from zope.app.testing import setup
from zope.component.hooks import getSite, setSite
from zope.site import LocalSiteManager

from schooltool.gradebook.generations.tests import ContextStub
from schooltool.gradebook.generations.evolve4 import evolve

VOCABULARY_NAME = 'schooltool.gradebook.activities'
CATEGORY_KEY = 'schooltool.gradebook.category'


class VocabularyStub(dict):

    default_key = None

    def getKeys(self):
        return self.keys()

    def queryValue(self, key, lang):
        assert lang == 'en'
        return self.get(key)

    def getDefaultKey(self):
        return self.default_key


def addOptionStorage(app, storages={}, default=None):
    annotations = IAnnotations(app)
    storage = PersistentMapping()
    for st_key, data in storages.items():
        storage[st_key] = VocabularyStub(data)
        storage[st_key].default_key = default
    annotations['optionstorage'] = storage


def doctest_evolve4():
    r"""Evolution to generation 4.

    First, we'll set up the app object:

        >>> context = ContextStub()
        >>> app = getRootFolder(context)
        >>> app.setSiteManager(LocalSiteManager(app))
        >>> setSite(app)

        >>> addOptionStorage(app, {VOCABULARY_NAME: {
        ...     u'assignment': u'Assignment',
        ...     u'essay': u'Essay',
        ...     u'homework': u'Homework',
        ...     }}, default=u'essay')

        >>> CATEGORY_KEY in app
        False

        >>> anns = IAnnotations(app)
        >>> 'optionstorage' in anns
        True

    Let's evolve.

        >>> evolve(context)

    Category container was added to app, it's values copied from
    respective option storage container:

        >>> cats = app[CATEGORY_KEY]
        >>> cats
        <schooltool.gradebook.category.CategoryContainer ...>

        >>> cats.default_key
        u'essay'

        >>> sorted(cats.items())
        [(u'assignment', u'Assignment'),
         (u'essay', u'Essay'),
         (u'homework', u'Homework')]

    Optionstorage was removed from annotations completely.

        >>> anns = IAnnotations(app)

        >>> 'optionstorage' in anns
        False

    """


def doctest_evolve4_garbage_storages():
    r"""Evolution to generation 4.

    First, we'll set up the app object:

        >>> context = ContextStub()
        >>> app = getRootFolder(context)
        >>> app.setSiteManager(LocalSiteManager(app))
        >>> setSite(app)

        >>> addOptionStorage(app, {VOCABULARY_NAME: {
        ...         u'assignment': u'Assignment',
        ...         u'essay': u'Essay',
        ...         u'homework': u'Homework'},
        ...         'some.plugin.data': {}
        ...     },
        ...     default=u'essay')

        >>> CATEGORY_KEY in app
        False

        >>> anns = IAnnotations(app)
        >>> 'optionstorage' in anns
        True

    Let's evolve.

        >>> evolve(context)

    Category container was added to app, it's values copied from
    respective option storage container:

        >>> cats = app[CATEGORY_KEY]
        >>> cats
        <schooltool.gradebook.category.CategoryContainer ...>

        >>> cats.default_key
        u'essay'

        >>> sorted(cats.items())
        [(u'assignment', u'Assignment'),
         (u'essay', u'Essay'),
         (u'homework', u'Homework')]

    But this time, option storage was left with plugins' data.

        >>> anns = IAnnotations(app)

        >>> 'optionstorage' in anns
        True

        >>> sorted(anns['optionstorage'])
        ['some.plugin.data']

    """


def setUp(test):
    setup.placelessSetUp()
    setup.setUpAnnotations()
    setSite()

def tearDown(test):
    setSite()
    setup.placelessTearDown()


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

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