allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [2/7] git commit: [#4213] ticket:344 refactored and fixed tests
Date Mon, 08 Jul 2013 16:50:22 GMT
[#4213]  ticket:344 refactored and fixed tests


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

Branch: refs/heads/master
Commit: d8ed95c4df193ee74e288140749ac785916f0a55
Parents: 3439474
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Fri May 31 14:23:40 2013 +0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Sun Jul 7 06:08:00 2013 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/import_support.py           | 14 ++++++--------
 .../forgetracker/tests/unit/test_ticket_model.py      |  6 +++---
 2 files changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d8ed95c4/ForgeTracker/forgetracker/import_support.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py
index 1ea391b..6970004 100644
--- a/ForgeTracker/forgetracker/import_support.py
+++ b/ForgeTracker/forgetracker/import_support.py
@@ -50,14 +50,16 @@ class ResettableStream(object):
         self.buf_size = header_size if header_size >= 0 else self.HEADER_BUF_SIZE
         self.buf_pos = 0
         self.stream_pos = 0
-        
-    def read(self, size=-1):
+
+    def _read_header(self):
         if self.buf is None:
             data = self.fp.read(self.buf_size)
             self.buf = StringIO(data)
             self.buf_len = len(data)
             self.stream_pos = self.buf_len
-        
+
+    def read(self, size=-1):
+        self._read_header()
         data = ''
         if self.buf_pos < self.stream_pos:
             data = self.buf.read(size)
@@ -71,11 +73,7 @@ class ResettableStream(object):
         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)
-
+        self._read_header()
         if self.stream_pos > self.buf_len:
             assert False, 'Started reading stream body, cannot reset pos'
         self.buf.seek(pos)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d8ed95c4/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 c53afad..145bc7c 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
@@ -271,9 +271,9 @@ class TestTicketModel(TrackerTestWithModel):
             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),
+        f = urllib2.urlopen('file://%s' % __file__)
+        TicketAttachment.save_attachment('test_ticket_model.py', ResettableStream(f),
                                             artifact_id=ticket._id)
         ThreadLocalORMSession.flush_all()
         assert_equal(len(ticket.attachments), 1)
-        assert_equal(ticket.attachments.first().filename, 'filename.txt')
+        assert_equal(ticket.attachments.first().filename, 'test_ticket_model.py')


Mime
View raw message