allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [1/2] git commit: [#7580] ticket:619 Add attachments to the ticket during allura import
Date Mon, 11 Aug 2014 10:41:39 GMT
Repository: allura
Updated Branches:
  refs/heads/je/42cc_7580 [created] 58b9b3ad4


[#7580] ticket:619 Add attachments to the ticket during allura import


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

Branch: refs/heads/je/42cc_7580
Commit: 30bd6635087bd1d519afbf456a868e7de53acf4e
Parents: 84b1a1a
Author: discort <lexad-al@bk.ru>
Authored: Wed Aug 6 10:58:03 2014 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Fri Aug 8 16:09:00 2014 +0300

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/forge/tracker.py  |  3 +++
 .../forgeimporters/tests/forge/test_tracker.py  | 24 ++++++++++++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/30bd6635/ForgeImporters/forgeimporters/forge/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/forge/tracker.py b/ForgeImporters/forgeimporters/forge/tracker.py
index 96c352f..2937b63 100644
--- a/ForgeImporters/forgeimporters/forge/tracker.py
+++ b/ForgeImporters/forgeimporters/forge/tracker.py
@@ -153,6 +153,9 @@ class ForgeTrackerImporter(ToolImporter):
                         ticket_json['votes_down'],
                         assigned_to_id=owner._id,
                     )
+                    # add an attachment to the ticket
+                    ticket.add_multiple_attachments([File(a['url'])
+                                                    for a in ticket_json['attachments']])
                     # trigger the private property
                     ticket.private = ticket_json['private']
                     self.process_comments(

http://git-wip-us.apache.org/repos/asf/allura/blob/30bd6635/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/forge/test_tracker.py b/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
index 152f222..88f6b53 100644
--- a/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
@@ -17,6 +17,8 @@
 
 from datetime import datetime
 from unittest import TestCase
+from cgi import FieldStorage
+from cStringIO import StringIO
 
 import mock
 from ming.odm import ThreadLocalORMSession
@@ -27,6 +29,7 @@ from allura.tests.decorators import with_tracker
 
 from allura import model as M
 from forgeimporters.forge import tracker
+from forgetracker import model as TM
 
 
 class TestTrackerImporter(TestCase):
@@ -55,6 +58,7 @@ class TestTrackerImporter(TestCase):
                 {
                     'reported_by': 'rb1',
                     'assigned_to': 'at1',
+                    'attachments': [],
                     'ticket_num': 1,
                     'description': 'd1',
                     'created_date': '2013-09-01',
@@ -72,6 +76,7 @@ class TestTrackerImporter(TestCase):
                     'reported_by': 'rb2',
                     'assigned_to': 'at2',
                     'ticket_num': 100,
+                    'attachments': [],
                     'description': 'd2',
                     'created_date': '2013-09-03',
                     'mod_date': '2013-09-04',
@@ -196,6 +201,25 @@ class TestTrackerImporter(TestCase):
         g.post_event.assert_called_once_with('project_updated')
         app.globals.invalidate_bin_counts.assert_called_once_with()
 
+    def test_ticket_attach(self):
+        test_file1 = FieldStorage()
+        test_file1.name = 'test_file_1'
+        test_file1.filename = 'test_file_1.txt'
+        test_file1.type = 'text/plain'
+        test_file1.file = StringIO('test_file_1\n')
+        test_file2 = FieldStorage()
+        test_file2.name = 'test_file_2'
+        test_file2.filename = 'test_file_2.txt'
+        test_file2.type = 'text/plain'
+        test_file2.file = StringIO('test_file_2\n')
+        ticket = TM.Ticket(ticket_num=666)
+        ticket.add_multiple_attachments([test_file1, test_file2])
+        ThreadLocalORMSession.flush_all()
+        attaches = ticket.attachments
+        self.assertEqual(len(attaches), 2)
+        assert 'test_file_1.txt' in [attaches[0].filename, attaches[1].filename]
+        assert 'test_file_2.txt' in [attaches[0].filename, attaches[1].filename]
+                
     @mock.patch.object(tracker, 'ThreadLocalORMSession')
     @mock.patch.object(tracker, 'M')
     @mock.patch.object(tracker, 'h')


Mime
View raw message