~ubuntu-branches/ubuntu/precise/trac/precise

« back to all changes in this revision

Viewing changes to trac/tests/attachment.py

  • Committer: Bazaar Package Importer
  • Author(s): W. Martin Borgert
  • Date: 2009-09-15 21:43:38 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20090915214338-q3ecy6qxwxfzf9y8
Tags: 0.11.5-2
* Set exec bit for *_frontends (Closes: #510441), thanks to Torsten
  Landschoff for the patch.
* Move python-psycopg2 and python-mysql from Suggests to Depends as
  alternative to python-psqlite2 (Closes: #513117).
* Use debhelper 7 (Closes: #497862).
* Don't compress *-hook files and don't install MS-Windows *.cmd
  files (Closes: #526142), thanks to Jan Dittberner for the patch.
* Add README.source to point to dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
 
1
# -*- coding: utf-8 -*-
2
2
 
3
3
import os
4
4
import shutil
6
6
import unittest
7
7
import time
8
8
 
9
 
from trac.attachment import Attachment, AttachmentModule
 
9
from trac.attachment import Attachment, AttachmentModule, \
 
10
                            LegacyAttachmentPolicy
 
11
from trac.core import Component, implements
10
12
from trac.log import logger_factory
 
13
from trac.perm import IPermissionPolicy, PermissionCache
11
14
from trac.test import EnvironmentStub, Mock
12
15
from trac.wiki.formatter import Formatter
13
16
 
14
17
 
 
18
class TicketOnlyViewsTicket(Component):
 
19
    implements(IPermissionPolicy)
 
20
 
 
21
    def check_permission(self, action, username, resource, perm):
 
22
        if action.startswith('TICKET_'):
 
23
            return resource.realm == 'ticket'
 
24
        else:
 
25
            return None
 
26
 
 
27
 
15
28
class AttachmentTestCase(unittest.TestCase):
16
29
 
17
30
    def setUp(self):
19
32
        self.env.path = os.path.join(tempfile.gettempdir(), 'trac-tempenv')
20
33
        os.mkdir(self.env.path)
21
34
        self.attachments_dir = os.path.join(self.env.path, 'attachments')
 
35
        self.env.config.set('trac', 'permission_policies',
 
36
                            'TicketOnlyViewsTicket, LegacyAttachmentPolicy')
22
37
        self.env.config.set('attachment', 'max_size', 512)
23
38
 
24
 
        self.perm = Mock(__contains__=lambda x: True, require=lambda x: None)
 
39
        self.perm = PermissionCache(self.env)
25
40
 
26
41
    def tearDown(self):
27
42
        shutil.rmtree(self.env.path)
 
43
        self.env.reset_db()
28
44
 
29
45
    def test_get_path(self):
30
46
        attachment = Attachment(self.env, 'ticket', 42)
109
125
 
110
126
        attachment.delete()
111
127
 
 
128
    def test_legacy_permission_on_parent(self):
 
129
        """Ensure that legacy action tests are done on parent.  As
 
130
        `ATTACHMENT_VIEW` maps to `TICKET_VIEW`, the `TICKET_VIEW` is tested
 
131
        against the ticket's resource."""
 
132
        attachment = Attachment(self.env, 'ticket', 42)
 
133
        self.assert_('ATTACHMENT_VIEW' in self.perm(attachment.resource))
 
134
 
112
135
 
113
136
def suite():
114
137
    suite = unittest.TestSuite()