allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [3/4] git commit: [#6541] Added import_id and AuditLog to Trac ticket importer
Date Wed, 28 Aug 2013 20:49:47 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/581f197a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/581f197a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/581f197a

Branch: refs/heads/cj/6541
Commit: 581f197af2c779838cadb0c8a93051f152ea11e0
Parents: 875ea62
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Wed Aug 28 20:32:05 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed Aug 28 20:32:05 2013 +0000

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


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/581f197a/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 953c6d7..7ecd2f6 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,30 +33,38 @@ 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')
-        res = importer.import_tool(project, user,
-                mount_point='bugs',
-                mount_label='Bugs',
-                trac_url='http://example.com/trac/url',
-                user_map=json.dumps(user_map),
+        with patch.dict(config, {'base_url': 'http://base.com/'}):
+            res = importer.import_tool(project, user,
+                    mount_point='bugs',
+                    mount_label='Bugs',
+                    trac_url='http://example.com/trac/url',
+                    user_map=json.dumps(user_map),
                 )
         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(
@@ -66,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')
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/581f197a/ForgeImporters/forgeimporters/trac/tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tickets.py b/ForgeImporters/forgeimporters/trac/tickets.py
index 3e0e486..06b3381 100644
--- a/ForgeImporters/forgeimporters/trac/tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tickets.py
@@ -42,7 +42,7 @@ from allura.controllers import BaseController
 from allura.lib.decorators import require_post, task
 from allura.lib.import_api import AlluraImportApiClient
 from allura.lib import validators as v
-from allura.model import ApiTicket
+from allura.model import ApiTicket, AuditLog
 from allura.scripts.trac_export import (
         TracExport,
         DateJSONEncoder,
@@ -113,7 +113,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)
         export = [ticket for ticket in TracExport(trac_url)]
@@ -127,5 +131,12 @@ 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


Mime
View raw message