incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/2] git commit: [#6815] Include assigned_to field in Allura tracker import
Date Wed, 13 Nov 2013 23:16:59 GMT
Updated Branches:
  refs/heads/master e7838a0f8 -> 9dec93d74


[#6815] Include assigned_to field in Allura tracker import

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/master
Commit: 23cc1e8333b29ac0a99fa8959bee8328fdf4bdf9
Parents: e7838a0
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Nov 8 18:37:58 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Nov 13 23:14:45 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/forge/tracker.py  | 18 ++++++++---
 .../forgeimporters/tests/forge/test_tracker.py  | 34 ++++++++++++++------
 2 files changed, 38 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/23cc1e83/ForgeImporters/forgeimporters/forge/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/forge/tracker.py b/ForgeImporters/forgeimporters/forge/tracker.py
index a9a17bb..c758651 100644
--- a/ForgeImporters/forgeimporters/forge/tracker.py
+++ b/ForgeImporters/forgeimporters/forge/tracker.py
@@ -127,12 +127,17 @@ class ForgeTrackerImporter(ToolImporter):
             M.session.artifact_orm_session._get().skip_mod_date = True
             for ticket_json in tracker_json['tickets']:
                 reporter = self.get_user(ticket_json['reported_by'])
+                owner = self.get_user(ticket_json['assigned_to'])
                 with h.push_config(c, user=reporter, app=app):
                     self.max_ticket_num = max(ticket_json['ticket_num'], self.max_ticket_num)
                     ticket = TM.Ticket(
                             app_config_id=app.config._id,
                             import_id=import_id_converter.expand(ticket_json['ticket_num'],
app),
-                            description=self.annotate(ticket_json['description'], reporter,
ticket_json['reported_by']),
+                            description=self.annotate(
+                                self.annotate(
+                                    ticket_json['description'],
+                                    owner, ticket_json['assigned_to'], label=' owned'),
+                                reporter, ticket_json['reported_by'], label=' created'),
                             created_date=dateutil.parser.parse(ticket_json['created_date']),
                             mod_date=dateutil.parser.parse(ticket_json['mod_date']),
                             ticket_num=ticket_json['ticket_num'],
@@ -142,7 +147,8 @@ class ForgeTrackerImporter(ToolImporter):
                             labels=ticket_json['labels'],
                             votes_down=ticket_json['votes_down'],
                             votes_up=ticket_json['votes_up'],
-                            votes = ticket_json['votes_up'] - ticket_json['votes_down'],
+                            votes=ticket_json['votes_up'] - ticket_json['votes_down'],
+                            assigned_to_id=owner._id,
                         )
                     ticket.private = ticket_json['private']  # trigger the private property
                     self.process_comments(ticket, ticket_json['discussion_thread']['posts'])
@@ -170,14 +176,16 @@ class ForgeTrackerImporter(ToolImporter):
             M.session.artifact_orm_session._get().skip_mod_date = False
 
     def get_user(self, username):
+        if username is None:
+            return M.User.anonymous()
         user = M.User.by_username(username)
         if not user:
             user = M.User.anonymous()
         return user
 
-    def annotate(self, text, user, username):
-        if user._id is None:
-            return '*Originally by:* %s\n\n%s' % (username, text)
+    def annotate(self, text, user, username, label=''):
+        if username and user.is_anonymous():
+            return '*Originally%s by:* %s\n\n%s' % (label, username, text)
         return text
 
     def process_comments(self, ticket, comments):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/23cc1e83/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 321643e..0b8fa05 100644
--- a/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
@@ -53,6 +53,7 @@ class TestTrackerImporter(TestCase):
                 'tickets': [
                         {
                                 'reported_by': 'rb1',
+                                'assigned_to': 'at1',
                                 'ticket_num': 1,
                                 'description': 'd1',
                                 'created_date': '2013-09-01',
@@ -68,6 +69,7 @@ class TestTrackerImporter(TestCase):
                             },
                         {
                                 'reported_by': 'rb2',
+                                'assigned_to': 'at2',
                                 'ticket_num': 100,
                                 'description': 'd2',
                                 'created_date': '2013-09-03',
@@ -83,9 +85,14 @@ class TestTrackerImporter(TestCase):
                             },
                     ],
             })
-        reporter = mock.Mock()
-        importer.get_user = mock.Mock(return_value=reporter)
-        importer.annotate = mock.Mock(side_effect=['ad1', 'ad2'])
+        anonymous = mock.Mock(_id=None, is_anonymous=lambda:True)
+        reporter = mock.Mock(is_anonymous=lambda:False)
+        author = mock.Mock(is_anonymous=lambda:False)
+        importer.get_user = mock.Mock(side_effect=[
+                reporter, author,
+                anonymous, anonymous,
+            ])
+        importer.annotate = mock.Mock(side_effect=['ad1', 'aad1', 'ad2', 'aad2'])
         importer.process_comments = mock.Mock()
         importer.process_bins = mock.Mock()
         project, user = mock.Mock(), mock.Mock()
@@ -112,8 +119,10 @@ class TestTrackerImporter(TestCase):
                 foo='bar',
             )
         self.assertEqual(importer.annotate.call_args_list, [
-                mock.call('d1', reporter, 'rb1'),
-                mock.call('d2', reporter, 'rb2'),
+                mock.call('d1', author, 'at1', label=' owned'),
+                mock.call('ad1', reporter, 'rb1', label=' created'),
+                mock.call('d2', anonymous, 'at2', label=' owned'),
+                mock.call('ad2', anonymous, 'rb2', label=' created'),
             ])
         self.assertEqual(TM.Ticket.call_args_list, [
                 mock.call(
@@ -123,7 +132,7 @@ class TestTrackerImporter(TestCase):
                                 'app_config_id': 'orig_id',
                                 'source_id': 1,
                             },
-                        description='ad1',
+                        description='aad1',
                         created_date=datetime(2013, 9, 1),
                         mod_date=datetime(2013, 9, 2),
                         ticket_num=1,
@@ -134,6 +143,7 @@ class TestTrackerImporter(TestCase):
                         votes_down=1,
                         votes_up=2,
                         votes=1,
+                        assigned_to_id=author._id,
                     ),
                 mock.call(
                         app_config_id=app.config._id,
@@ -142,7 +152,7 @@ class TestTrackerImporter(TestCase):
                                 'app_config_id': 'orig_id',
                                 'source_id': 100,
                             },
-                        description='ad2',
+                        description='aad2',
                         created_date=datetime(2013, 9, 3),
                         mod_date=datetime(2013, 9, 4),
                         ticket_num=100,
@@ -153,6 +163,7 @@ class TestTrackerImporter(TestCase):
                         votes_down=3,
                         votes_up=5,
                         votes=2,
+                        assigned_to_id=None,
                     ),
             ])
         self.assertEqual(tickets[0].private, False)
@@ -211,16 +222,21 @@ class TestTrackerImporter(TestCase):
         self.assertEqual(importer.get_user('foo'), 'bar')
         self.assertEqual(M.User.anonymous.call_count, 0)
 
+        self.assertEqual(importer.get_user(None), 'anon')
+        self.assertEqual(M.User.anonymous.call_count, 1)
+
         M.User.by_username.return_value = None
         self.assertEqual(importer.get_user('foo'), 'anon')
-        self.assertEqual(M.User.anonymous.call_count, 1)
+        self.assertEqual(M.User.anonymous.call_count, 2)
 
     def test_annotate(self):
         importer = tracker.ForgeTrackerImporter()
         user = mock.Mock(_id=1)
+        user.is_anonymous.return_value = False
         self.assertEqual(importer.annotate('foo', user, 'bar'), 'foo')
-        user._id = None
+        user.is_anonymous.return_value = True
         self.assertEqual(importer.annotate('foo', user, 'bar'), '*Originally by:* bar\n\nfoo')
+        self.assertEqual(importer.annotate('foo', user, None), 'foo')
 
     @mock.patch.object(tracker, 'File')
     @mock.patch.object(tracker, 'c')


Mime
View raw message