incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [5/6] git commit: [#6541] Added import_id and AuditLog to Trac ticket importer
Date Fri, 06 Sep 2013 15:11:45 GMT
[#6541] Added import_id and AuditLog to Trac ticket importer

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/3434c41c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/3434c41c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/3434c41c

Branch: refs/heads/db/6541
Commit: 3434c41c5d262629f16930648ddda3f73b185bd8
Parents: caddc07
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Wed Aug 28 20:32:05 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 6 15:11:06 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/trac/tests/test_tickets.py       | 16 ++++++++++++++--
 ForgeImporters/forgeimporters/trac/tickets.py       | 15 +++++++++++++--
 2 files changed, 27 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3434c41c/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
index 74e1049..2e0c199 100644
--- a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
@@ -19,6 +19,8 @@ import json
 from unittest import TestCase
 from mock import Mock, patch
 
+from tg import config
+
 from allura.tests import TestController
 from allura.tests.decorators import with_tracker
 
@@ -31,18 +33,21 @@ from forgeimporters.trac.tickets import (
 class TestTracTicketImporter(TestCase):
     @patch('forgeimporters.trac.tickets.session')
     @patch('forgeimporters.trac.tickets.g')
+    @patch('forgeimporters.trac.tickets.AuditLog')
     @patch('forgeimporters.trac.tickets.import_tracker')
     @patch('forgeimporters.trac.tickets.AlluraImportApiClient')
     @patch('forgeimporters.trac.tickets.datetime')
     @patch('forgeimporters.trac.tickets.ApiTicket')
     @patch('forgeimporters.trac.tickets.TracExport')
-    def test_import_tool(self, TracExport, ApiTicket, dt, ApiClient, import_tracker, g, session):
+    def test_import_tool(self, TracExport, ApiTicket, dt, ApiClient, import_tracker, AuditLog,
g, session):
         from datetime import datetime, timedelta
         now = datetime.utcnow()
         dt.utcnow.return_value = now
         user_map = {"orig_user":"new_user"}
         importer = TracTicketImporter()
         app = Mock(name='ForgeTrackerApp')
+        app.config.options.mount_point = 'bugs'
+        app.config.options.get = lambda *a: getattr(app.config.options, *a)
         project = Mock(name='Project', shortname='myproject')
         project.install_app.return_value = app
         user = Mock(name='User', _id='id')
@@ -55,7 +60,11 @@ class TestTracTicketImporter(TestCase):
                     )
         self.assertEqual(res, app)
         project.install_app.assert_called_once_with(
-                'Tickets', mount_point='bugs', mount_label='Bugs')
+                'Tickets', mount_point='bugs', mount_label='Bugs',
+                import_id={
+                        'source': 'Trac',
+                        'trac_url': 'http://example.com/trac/url/',
+                    })
         TracExport.return_value = []
         TracExport.assert_called_once_with('http://example.com/trac/url/')
         ApiTicket.assert_called_once_with(
@@ -67,6 +76,9 @@ class TestTracTicketImporter(TestCase):
                 api_client, 'myproject', 'bugs',
                 {"user_map": user_map}, '[]',
                 validate=False)
+        AuditLog.log.assert_called_once_with(
+                'import tool bugs from http://example.com/trac/url/',
+                project=project, user=user)
         g.post_event.assert_called_once_with('project_updated')
 
     @patch('forgeimporters.trac.tickets.session')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3434c41c/ForgeImporters/forgeimporters/trac/tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tickets.py b/ForgeImporters/forgeimporters/trac/tickets.py
index 3063d71..e5238e3 100644
--- a/ForgeImporters/forgeimporters/trac/tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tickets.py
@@ -43,7 +43,7 @@ from allura.lib.decorators import require_post, task
 from allura.lib.import_api import AlluraImportApiClient
 from allura.lib import validators as v
 from allura.lib import helpers as h
-from allura.model import ApiTicket
+from allura.model import ApiTicket, AuditLog
 from allura.scripts.trac_export import (
         TracExport,
         DateJSONEncoder,
@@ -117,7 +117,11 @@ class TracTicketImporter(ToolImporter):
                 'Tickets',
                 mount_point=mount_point,
                 mount_label=mount_label or 'Tickets',
-                )
+                import_id={
+                        'source': self.source,
+                        'trac_url': trac_url,
+                    },
+            )
         session(app.config).flush(app.config)
         session(app.globals).flush(app.globals)
         try:
@@ -132,6 +136,13 @@ class TracTicketImporter(ToolImporter):
             import_tracker(cli, project.shortname, mount_point,
                     {'user_map': json.loads(user_map) if user_map else {}},
                     export_string, validate=False)
+            AuditLog.log(
+                'import tool %s from %s' % (
+                        app.config.options.mount_point, 
+                        trac_url, 
+                    ), 
+                project=project, user=user, 
+            ) 
             g.post_event('project_updated')
             return app
         except Exception as e:


Mime
View raw message