This file is indexed.

/usr/share/pyshared/zope/dublincore/tests/test_creatorannotator.py is in python-zope.dublincore 3.8.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
##############################################################################
#
# 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.
#
##############################################################################
"""Tests creator annotation.
"""
import unittest

class CreatorAnnotatorTests(unittest.TestCase):

    def setUp(self):
        from zope.testing.cleanup import cleanUp
        cleanUp()
        self._makeInterface()
        self._registerAdapter()

    def tearDown(self):
        from zope.testing.cleanup import cleanUp
        from zope.security.management import endInteraction
        endInteraction()
        cleanUp()

    def _callFUT(self, event):
        from zope.dublincore.creatorannotator import CreatorAnnotator
        return CreatorAnnotator(event)

    def _makeInterface(self):
        from zope.interface import Interface

        class IDummyContent(Interface):
            pass

        self._iface = IDummyContent

    def _registerAdapter(self):
        from zope.component import provideAdapter
        from zope.dublincore.interfaces import IZopeDublinCore
        provideAdapter(DummyDCAdapter, (self._iface, ), IZopeDublinCore)

    def _makeContextAndEvent(self):

        from zope.interface import implements

        class DummyDublinCore(object):
            implements(self._iface)
            creators = ()

        class DummyEvent(object):
            def __init__(self, object):
                self.object = object

        context = DummyDublinCore()
        event = DummyEvent(context)
        return context, event

    def _setPrincipal(self, id):
        from zope.security.management import newInteraction
        class DummyPrincipal(object):
            title = 'TITLE'
            description = 'DESCRIPTION'
            def __init__(self, id):
                self.id = id
        if id is None:
            newInteraction(DummyRequest(None))
        else:
            newInteraction(DummyRequest(DummyPrincipal(id)))

    def test_w_no_request(self):
        context, event = self._makeContextAndEvent()
        self._callFUT(event)
        self.assertEqual(context.creators, ())

    def test_w_request_no_existing_creators(self):
        context, event = self._makeContextAndEvent()
        self._setPrincipal('phred')
        self._callFUT(event)
        self.assertEqual(context.creators, ('phred',))

    def test_w_request_w_existing_creator_nomatch(self):
        context, event = self._makeContextAndEvent()
        context.creators = ('bharney',)
        self._setPrincipal('phred')
        self._callFUT(event)
        self.assertEqual(context.creators, ('bharney', 'phred',))

    def test_w_request_w_existing_creator_match(self):
        context, event = self._makeContextAndEvent()
        context.creators = ('bharney', 'phred')
        self._setPrincipal('phred')
        self._callFUT(event)
        self.assertEqual(context.creators, ('bharney', 'phred',))

    def test_w_request_no_principal(self):
        context, event = self._makeContextAndEvent()
        context.creators = ('bharney', 'phred')
        self._setPrincipal(None)
        self._callFUT(event)
        self.assertEqual(context.creators, ('bharney', 'phred',))


class CreatorAnnotatorObjectEventTests(CreatorAnnotatorTests):

    def _callFUT(self, event):
        from zope.dublincore.creatorannotator import CreatorAnnotator
        return CreatorAnnotator(event.object, event)


class DummyDCAdapter(object):

    def _getcreator(self):
        return self.context.creators
    def _setcreator(self, value):
        self.context.creators = value
    creators = property(_getcreator, _setcreator, None, "Adapted Creators")

    def __init__(self, context):
        self.context = context


class DummyRequest(object):

    def __init__(self, principal):
        self.principal = principal
        self.interaction = None