This file is indexed.

/usr/share/pyshared/zope/app/container/browser/tests/test_contents_functional.py is in python-zope.app.container 3.9.2-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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Functional tests for the Container's 'Contents' view
"""

import unittest

from persistent import Persistent
import transaction
from zope import copypastemove
from zope.interface import implements, Interface
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.dublincore.interfaces import IZopeDublinCore

from zope.app.container.interfaces import IReadContainer, IContained
from zope.app.testing import ztapi
from zope.app.testing.functional import BrowserTestCase
from zope.app.testing.functional import FunctionalDocFileSuite
from zope.app.container.testing import AppContainerLayer


class IImmovable(Interface):
    """Marker interface for immovable objects."""

class IUncopyable(Interface):
    """Marker interface for uncopyable objects."""

class File(Persistent):
    implements(IAttributeAnnotatable)

class ImmovableFile(File):
    implements(IImmovable)

class UncopyableFile(File):
    implements(IUncopyable)

class ObjectNonCopier(copypastemove.ObjectCopier):

    def copyable(self):
        return False

class ObjectNonMover(copypastemove.ObjectMover):

    def moveable(self):
        return False

class ReadOnlyContainer(Persistent):
    implements(IReadContainer, IContained)
    __parent__ = __name__ = None

    def __init__(self): self.data = {}
    def keys(self): return self.data.keys()
    def __getitem__(self, key): return self.data[key]
    def get(self, key, default=None): return self.data.get(key, default)
    def __iter__(self): return iter(self.data)
    def values(self): return self.data.values()
    def __len__(self): return len(self.data)
    def items(self): return self.data.items()
    def __contains__(self, key): return key in self.data
    def has_key(self, key): return self.data.has_key(key)


class Test(BrowserTestCase):

    def test_inplace_add(self):
        root = self.getRootFolder()
        self.assert_('foo' not in root)
        response = self.publish(
            '/@@contents.html',
            basic='mgr:mgrpw',
            form={'type_name': u'BrowserAdd__zope.site.folder.Folder'})
        body = ' '.join(response.getBody().split())
        self.assert_(body.find('type="hidden" name="type_name"') >= 0)
        self.assert_(body.find('input name="new_value"') >= 0)
        self.assert_(body.find('type="submit" name="container_cancel_button"')
                     >= 0)
        self.assert_(body.find('type="submit" name="container_rename_button"')
                     < 0)

        response = self.publish(
            '/@@contents.html',
            basic='mgr:mgrpw',
            form={'type_name': u'BrowserAdd__zope.site.folder.Folder',
                  'new_value': 'foo'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                         'http://localhost/@@contents.html')

        root._p_jar.sync()
        self.assert_('foo' in root)

    def test_inplace_rename_multiple(self):
        root = self.getRootFolder()
        root['foo'] = File()
        self.assert_('foo' in root)
        transaction.commit()

        # Check that we don't change mode if there are no items selected
        
        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'container_rename_button': u''})
        body = ' '.join(response.getBody().split())
        self.assert_(body.find('input name="new_value:list"') < 0)
        self.assert_(body.find('type="submit" name="container_cancel_button"')
                     < 0)
        self.assert_(body.find('type="submit" name="container_rename_button"')
                     >= 0)
        self.assert_(body.find('div class="page_error"')
                     >= 0)


        # Check normal multiple select

        
        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'container_rename_button': u'',
                                      'ids': ['foo']})
        body = ' '.join(response.getBody().split())
        self.assert_(body.find('input name="new_value:list"') >= 0)
        self.assert_(body.find('type="submit" name="container_cancel_button"')
                     >= 0)
        self.assert_(body.find('type="submit" name="container_rename_button"')
                     < 0)

        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'rename_ids': ['foo'],
                                      'new_value': ['bar']})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                         'http://localhost/@@contents.html')

        root._p_jar.sync()
        self.assert_('foo' not in root)
        self.assert_('bar' in root)


    def test_inplace_rename_single(self):
        root = self.getRootFolder()
        root['foo'] = File()
        self.assert_('foo' in root)
        transaction.commit()
        
        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'rename_ids': ['foo']})
        body = ' '.join(response.getBody().split())
        self.assert_(body.find('input name="new_value:list"') >= 0)
        self.assert_(body.find('type="submit" name="container_cancel_button"')
                     >= 0)
        self.assert_(body.find('type="submit" name="container_rename_button"')
                     < 0)

        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'rename_ids': ['foo'],
                                      'new_value': ['bar']})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                         'http://localhost/@@contents.html')

        root._p_jar.sync()
        self.assert_('foo' not in root)
        self.assert_('bar' in root)

    def test_inplace_change_title(self):
        root = self.getRootFolder()
        root['foo'] = File()
        transaction.commit()
        self.assert_('foo' in root)
        dc = IZopeDublinCore(root['foo'])
        self.assert_(dc.title == '')

        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'retitle_id': u'foo'})
        body = ' '.join(response.getBody().split())
        self.assert_(body.find('type="hidden" name="retitle_id"') >= 0)
        self.assert_(body.find('input name="new_value"') >= 0)
        self.assert_(body.find('type="submit" name="container_cancel_button"')
                     >= 0)
        self.assert_(body.find('type="submit" name="container_rename_button"')
                     < 0)

        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'retitle_id': u'foo',
                                      'new_value': u'test title'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                         'http://localhost/@@contents.html')

        root._p_jar.sync()
        self.assert_('foo' in root)
        dc = IZopeDublinCore(root['foo'])
        self.assert_(dc.title == 'test title')


    def test_pasteable_for_deleted_clipboard_item(self):
        """Tests Paste button visibility when copied item is deleted."""

        root = self.getRootFolder()
        root['foo'] = File()    # item to be copied/deleted
        root['bar'] = File()    # ensures that there's always an item in
                                # the collection view
        transaction.commit()

        # confirm foo in contents, Copy button visible, Paste not visible
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find(
            '<a href="foo/@@SelectedManagementView.html">foo</a>') != -1)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_copy_button"') != -1)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_paste_button"') == -1)

        # copy foo - confirm Paste visible
        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
            'ids' : ('foo',),
            'container_copy_button' : '' })
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
            'http://localhost/@@contents.html')
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_paste_button"') != -1)

        # delete foo -> nothing valid to paste -> Paste should not be visible
        del root['foo']
        transaction.commit()
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_paste_button"') == -1)      


    def test_paste_for_deleted_clipboard_item(self):
        """Tests paste operation when one of two copied items is deleted."""

        root = self.getRootFolder()
        root['foo'] = File()
        root['bar'] = File()
        transaction.commit()

        # confirm foo/bar in contents, Copy button visible, Paste not visible
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find(
            '<a href="foo/@@SelectedManagementView.html">foo</a>') != -1)
        self.assert_(response.getBody().find(
            '<a href="bar/@@SelectedManagementView.html">bar</a>') != -1)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_copy_button"') != -1)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_paste_button"') == -1)

        # copy foo and bar - confirm Paste visible
        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
            'ids' : ('foo', 'bar'),
            'container_copy_button' : '' })
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
            'http://localhost/@@contents.html')
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_paste_button"') != -1)

        # delete only foo -> bar still available -> Paste should be visible
        del root['foo']
        transaction.commit()
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find(
            '<input type="submit" name="container_paste_button"') != -1)

        # paste clipboard contents - only bar should be copied
        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
            'container_paste_button' : '' })
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
            'http://localhost/@@contents.html')
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        root._p_jar.sync()
        self.assertEqual(tuple(root.keys()), ('bar', 'bar-2'))

    def test_readonly_display(self):
        root = self.getRootFolder()
        root['foo'] = ReadOnlyContainer()
        transaction.commit()
        response = self.publish('/foo/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)

    def test_uncopyable_object(self):
        ztapi.provideAdapter(IUncopyable,
                             copypastemove.interfaces.IObjectCopier,
                             ObjectNonCopier)
        root = self.getRootFolder()
        root['uncopyable'] = UncopyableFile()
        transaction.commit()
        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'ids': [u'uncopyable'],
                                      'container_copy_button': u'Copy'})
        self.assertEqual(response.getStatus(), 200)
        body = response.getBody()
        self.assert_("cannot be copied" in body)

    def test_unmoveable_object(self):
        ztapi.provideAdapter(IImmovable,
                             copypastemove.interfaces.IObjectMover,
                             ObjectNonMover)
        root = self.getRootFolder()
        root['immovable'] = ImmovableFile()
        transaction.commit()
        response = self.publish('/@@contents.html',
                                basic='mgr:mgrpw',
                                form={'ids': [u'immovable'],
                                      'container_cut_button': u'Cut'})
        self.assertEqual(response.getStatus(), 200)
        body = response.getBody()
        self.assert_("cannot be moved" in body)

    def test_copy_then_delete_with_unicode_name(self):
        """Tests unicode on object copied then deleted (#238579)."""

        # create a file with an accentuated unicode name
        root = self.getRootFolder()
        root[u'voil\xe0'] = File()
        transaction.commit()

        # copy the object
        response = self.publish('/@@contents.html', basic='mgr:mgrpw', form={
            'ids' : (u'voil\xe0',),
            'container_copy_button' : '' })
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
            'http://localhost/@@contents.html')
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)

        # delete the object
        del root[u'voil\xe0']
        transaction.commit()
        response = self.publish('/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)


def test_suite():
    suite = unittest.TestSuite()
    Test.layer = AppContainerLayer
    suite.addTest(unittest.makeSuite(Test))
    index = FunctionalDocFileSuite("index.txt")
    index.layer = AppContainerLayer
    suite.addTest(index)
    return suite

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