1. Odd Simon Simonsen
  2. trac-011

Commits

cboos  committed fdb1496

[svn r9908] 0.11.7.1: backported r9724 (`resource_exists` for attachments) and the later bug fixes for the `resource_exists` changes (r9732, r9817).

  • Participants
  • Parent commits c97d20d
  • Branches 0.11-stable

Comments (0)

Files changed (3)

File trac/attachment.py

View file
  • Ignore whitespace
             return _("Attachments of %(parent)s",
                      parent=get_resource_name(self.env, resource.parent))
 
+    def resource_exists(self, resource):
+        try:
+            attachment = Attachment(self.env, resource)
+            return os.path.exists(attachment.path)
+        except ResourceNotFound:
+            return False
+
     # Internal methods
 
     def _do_save(self, req, attachment):

File trac/tests/attachment.py

View file
  • Ignore whitespace
 # -*- coding: utf-8 -*-
 
+from StringIO import StringIO
 import os
 import shutil
 import tempfile
 from trac.core import Component, implements
 from trac.log import logger_factory
 from trac.perm import IPermissionPolicy, PermissionCache
+from trac.resource import Resource, resource_exists
 from trac.test import EnvironmentStub, Mock
 from trac.wiki.formatter import Formatter
 
         attachment = Attachment(self.env, 'ticket', 42)
         self.assert_('ATTACHMENT_VIEW' in self.perm(attachment.resource))
 
+    def test_resource_doesnt_exist(self):
+        r = Resource('wiki', 'WikiStart').child('attachment', 'file.txt')
+        self.assertEqual(False, AttachmentModule(self.env).resource_exists(r))
+
+    def test_resource_exists(self):
+        att = Attachment(self.env, 'wiki', 'WikiStart')
+        att.insert('file.txt', StringIO(''), 1)
+        self.assertTrue(resource_exists(self.env, att.resource))
+
 
 def suite():
     suite = unittest.TestSuite()

File trac/ticket/api.py

View file
  • Ignore whitespace
         >>> from trac.ticket.model import Ticket
         >>> t = Ticket(env)
         >>> t['summary'] = 'Test resource_exists...'
-        >>> t.insert()
+        >>> int(t.insert())
         1
         >>> resource_exists(env, t.resource)
         True