/usr/lib/python2.7/dist-packages/schooltool/lyceum/journal/browser/tests/test_table.py is in python-schooltool.lyceum.journal 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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | #
#
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2007 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 lyceum journal.
"""
import unittest, doctest
from zope.app.testing import setup
from zope.interface import implements
from zope.publisher.browser import TestRequest
def doctest_SelectStudentCellFormatter():
"""Tests for SelectStudentCellFormatter.
>>> from schooltool.lyceum.journal.browser.table import SelectStudentCellFormatter
>>> formatter = SelectStudentCellFormatter(None)
>>> request = TestRequest()
SelectStudentCellFormatter takes some parameters from the request,
and adds them to the url that has the person displayed in the row
selected:
>>> request.form = {'event_id': "some-event-id",
... 'month': "july"}
>>> formatter.extra_parameters(request)
[('event_id', 'some-event-id'),
('month', 'july')]
Parameters that are not relevant to the state of the view get
ignored:
>>> request.form = {'event_id': "some-event-id",
... 'month': "july",
... 'some-thing-else': 'is-ignored'}
>>> formatter.extra_parameters(request)
[('event_id', 'some-event-id'),
('month', 'july')]
The formatter renders the url of the journal, and adds student
parameter set to the __name__ of the student that is being
rendered:
>>> class TableFormatterStub(object):
... pass
>>> table_formatter = TableFormatterStub()
>>> table_formatter.request = request
>>> class PersonStub(object):
... __name__ = "john"
>>> item = PersonStub()
>>> formatter("John", item, table_formatter)
'<a class="select-row" href="http://127.0.0.1/index.html?student=john&event_id=some-event-id&month=july">John</a>'
"""
def doctest_SelectableRowTableFormatter():
r"""Tests for SelectableRowTableFormatter.
SelectableRowTableFormatter is a special table formatter that
allows you to select items, and have rows for these items
displayed in some special way when rendering the table.
>>> from schooltool.lyceum.journal.browser.table import SelectableRowTableFormatter
>>> request = TestRequest()
>>> class ColumnStub(object):
... def renderCell(self, item, formatter):
... return "I am %s" % item
It still works with simple columns that have no way to get
selected:
>>> columns = [ColumnStub()]
>>> formatter = SelectableRowTableFormatter("context", request, [],
... selected_items=["Pete"],
... columns=columns)
>>> formatter.row = 0
>>> print formatter.renderRow("John")
<tr class="odd">
<td>
I am John
</td>
</tr>
As this table formatter inherits from AlternatingRowFormatter the
next row is "even":
>>> print formatter.renderRow("Pete")
<tr class="even">
<td>
I am Pete
</td>
</tr>
If column implements ISelectableColumn, and the row being rendered
is for a selected item - cells will be rendered in a special way:
>>> from schooltool.lyceum.journal.browser.interfaces import ISelectableColumn
>>> class SelectableColumnStub(ColumnStub):
... implements(ISelectableColumn)
... def renderSelectedCell(self, item, formatter):
... return "I am Selected %s" % item
John is not selected:
>>> columns[0] = SelectableColumnStub()
>>> print formatter.renderRow("John")
<tr class="odd">
<td>
I am John
</td>
</tr>
But Pete is:
>>> print formatter.renderRow("Pete")
<tr class="even">
<td>
I am Selected Pete
</td>
</tr>
Another type of columns is IIndependentColumn, "independent"
columns render their own TD tags, so they can style themselves any
way they want:
>>> from schooltool.lyceum.journal.browser.interfaces import IIndependentColumn
>>> class IndependentColumnStub(ColumnStub):
... implements(IIndependentColumn)
... def renderCell(self, item, formatter):
... return '<td class="special">\nI am %s\n</td>' % item
>>> columns[0] = IndependentColumnStub()
>>> print formatter.renderRow("John")
<tr class="odd">
<td class="special">
I am John
</td>
</tr>
The column did not implement ISelectableColumn, so Pete is
rendered the same way as John was:
>>> print formatter.renderRow("Pete")
<tr class="even">
<td class="special">
I am Pete
</td>
</tr>
Columns can implement both interfaces ISelectableColumn and
IIndependentColumn at the same time, so they will render their own
TD tags, and get displayed differently when the row is selected:
>>> class SelectableIndependentColumn(IndependentColumnStub):
... implements(ISelectableColumn)
... def renderSelectedCell(self, item, formatter):
... return '<td class="selected">\nI am %s\n</td>' % item
>>> columns[0] = SelectableIndependentColumn()
>>> print formatter.renderRow("John")
<tr class="odd">
<td class="special">
I am John
</td>
</tr>
The TD for Pete gets it's class set to "selected":
>>> print formatter.renderRow("Pete")
<tr class="even">
<td class="selected">
I am Pete
</td>
</tr>
"""
def setUp(test):
setup.placelessSetUp()
setup.setUpTraversal()
def tearDown(test):
setup.placelessTearDown()
def test_suite():
optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
return doctest.DocTestSuite(optionflags=optionflags,
setUp=setUp, tearDown=tearDown)
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
|