allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [24/50] [abbrv] git commit: [#4213] ticket:344 set buf_len for ResettableStream().seek
Date Thu, 11 Jul 2013 21:58:44 GMT
[#4213]  ticket:344 set buf_len for ResettableStream().seek


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/34394746
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/34394746
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/34394746

Branch: refs/heads/db/6277
Commit: 34394746fdf7d6fa324c8987f2d5c9938e897118
Parents: 3ae3c36
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Wed May 22 15:38:03 2013 +0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Sun Jul 7 06:08:00 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/import_support.py       |  9 +++++++--
 .../forgetracker/tests/unit/test_ticket_model.py  | 18 +++++++++++++++++-
 2 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/34394746/ForgeTracker/forgetracker/import_support.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py
index 4c0f72f..1ea391b 100644
--- a/ForgeTracker/forgetracker/import_support.py
+++ b/ForgeTracker/forgetracker/import_support.py
@@ -69,13 +69,18 @@ class ResettableStream(object):
         data += self.fp.read(size)
         self.stream_pos += len(data)
         return data
-        
+
     def seek(self, pos):
+        if self.buf is None:
+            data = self.fp.read(self.buf_size)
+            self.buf = StringIO(data)
+            self.buf_len = len(data)
+
         if self.stream_pos > self.buf_len:
             assert False, 'Started reading stream body, cannot reset pos'
         self.buf.seek(pos)
         self.buf_pos = pos
-        
+
     def tell(self):
         if self.buf_pos < self.stream_pos:
             return self.buf_pos

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/34394746/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
index 9cca6df..c53afad 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
@@ -17,13 +17,15 @@
 
 from pylons import tmpl_context as c
 from datetime import datetime
+import urllib2
 
 from ming.orm.ormsession import ThreadLocalORMSession
 from ming import schema
 from nose.tools import raises, assert_raises, assert_equal
 
-from forgetracker.model import Ticket
+from forgetracker.model import Ticket, TicketAttachment
 from forgetracker.tests.unit import TrackerTestWithModel
+from forgetracker.import_support import ResettableStream
 from allura.model import Feed, Post, User
 from allura.lib import helpers as h
 from allura.tests import decorators as td
@@ -261,3 +263,17 @@ class TestTicketModel(TrackerTestWithModel):
         message += '\n- **_user_field_2**: test-user-0 (user not in project)'
         message += '\n- **assigned_to**: test-user-0 (user not in project)'
         assert_equal(post.text, message)
+
+    @td.with_tool('test', 'Tickets', 'bugs', username='test-user')
+    def test_attach_with_resettable_stream(self):
+        with h.push_context(c.project._id, app_config_id=c.app.config._id):
+            ticket = Ticket.new()
+            ticket.summary = 'test ticket'
+            ticket.description = 'test description'
+        assert_equal(len(ticket.attachments), 0)
+        f = urllib2.urlopen('http://sourceforge.net/apps/trac/sourceforge/raw-attachment/ticket/204/SF%20display%20error.JPG')
+        TicketAttachment.save_attachment('filename.txt', ResettableStream(f),
+                                            artifact_id=ticket._id)
+        ThreadLocalORMSession.flush_all()
+        assert_equal(len(ticket.attachments), 1)
+        assert_equal(ticket.attachments.first().filename, 'filename.txt')


Mime
View raw message