incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [2/3] git commit: [#6464] Force ticket numbers to match when importing from GC
Date Tue, 20 Aug 2013 21:41:44 GMT
[#6464] Force ticket numbers to match when importing from GC

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

Branch: refs/heads/cj/6464
Commit: fa955f4c00f5e524be6c7588b67475c0960231ce
Parents: ef4918b
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Tue Aug 20 21:39:30 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Aug 20 21:39:30 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/base.py            |  1 +
 ForgeImporters/forgeimporters/google/__init__.py |  2 +-
 ForgeImporters/forgeimporters/google/tracker.py  | 19 +++++++++++++------
 .../tests/google/functional/test_tracker.py      |  7 ++++---
 .../forgeimporters/tests/google/test_tracker.py  | 17 +++++++++--------
 5 files changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fa955f4c/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index ee34ab3..49397a5 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -47,6 +47,7 @@ class ProjectImportForm(schema.Schema):
         provider = ProjectRegistrationProvider.get()
         self.add_field('tools', ToolsValidator(source))
         self.add_field('project_shortname', provider.shortname_validator)
+        self.allow_extra_fields = True
 
     neighborhood = fev.PlainText(not_empty=True)
     project_name = fev.UnicodeString(not_empty=True, max=40)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fa955f4c/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 18a6209..902683a 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -177,7 +177,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
             if len(issue_ids) <= 0:
                 return
             for issue_id in issue_ids:
-                yield cls(project_name, 'issue', issue_id=issue_id)
+                yield (int(issue_id), cls(project_name, 'issue', issue_id=issue_id))
             start += limit
 
     def get_issue_summary(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fa955f4c/ForgeImporters/forgeimporters/google/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tracker.py b/ForgeImporters/forgeimporters/google/tracker.py
index fb2c845..e96678f 100644
--- a/ForgeImporters/forgeimporters/google/tracker.py
+++ b/ForgeImporters/forgeimporters/google/tracker.py
@@ -43,6 +43,12 @@ class GoogleCodeTrackerImporter(ToolImporter):
             type='select',
         )
 
+    def __init__(self, *args, **kwargs):
+        super(GoogleCodeTrackerImporter, self).__init__(*args, **kwargs)
+        self.open_milestones = set()
+        self.custom_fields = {}
+        self.max_ticket_num = 0
+
     def import_tool(self, project, user, project_name, mount_point=None,
             mount_label=None, **kw):
         app = project.install_app('tickets', mount_point, mount_label,
@@ -51,21 +57,22 @@ class GoogleCodeTrackerImporter(ToolImporter):
                 closed_status_names='Fixed Verified Invalid Duplicate WontFix Done',
             )
         ThreadLocalORMSession.flush_all()
-        self.open_milestones = set()
-        self.custom_fields = {}
         try:
             M.session.artifact_orm_session._get().skip_mod_date = True
             with h.push_config(c, user=M.User.anonymous(), app=app):
-                for issue in GoogleCodeProjectExtractor.iter_issues(project_name):
-                    ticket = TM.Ticket.new()
+                for ticket_num, issue in GoogleCodeProjectExtractor.iter_issues(project_name):
+                    self.max_ticket_num = max(ticket_num, self.max_ticket_num)
+                    ticket = TM.Ticket(
+                        app_config_id=app.config._id,
+                        custom_fields=dict(),
+                        ticket_num=ticket_num)
                     self.process_fields(ticket, issue)
                     self.process_labels(ticket, issue)
                     self.process_comments(ticket, issue)
                     session(ticket).flush(ticket)
                     session(ticket).expunge(ticket)
-                # app.globals gets expunged every time Ticket.new() is called :-(
-                app.globals = TM.Globals.query.get(app_config_id=app.config._id)
                 app.globals.custom_fields = self.postprocess_custom_fields()
+                app.globals.last_ticket_num = self.max_ticket_num
                 ThreadLocalORMSession.flush_all()
             g.post_event('project_updated')
             return app

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fa955f4c/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py b/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
index d2e423c..813a8b0 100644
--- a/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
@@ -46,12 +46,12 @@ class TestGCTrackerImporter(TestCase):
         extractor.url = "http://test/issue/?id=1"
         return extractor
 
-    def _make_ticket(self, issue):
+    def _make_ticket(self, issue, issue_id=1):
         self.assertIsNone(self.project.app_instance('test-issue'))
         with mock.patch.object(base.h, 'urlopen') as urlopen,\
              mock.patch.object(google.tracker, 'GoogleCodeProjectExtractor') as GPE:
             urlopen.side_effect = lambda req, **kw: mock.Mock(read=req.get_full_url)
-            GPE.iter_issues.return_value = [issue]
+            GPE.iter_issues.return_value = [(issue_id, issue)]
             gti = google.tracker.GoogleCodeTrackerImporter()
             gti.import_tool(self.project, self.user, 'test-issue-project', mount_point='test-issue')
         c.app = self.project.app_instance('test-issue')
@@ -237,9 +237,10 @@ class TestGCTrackerImporter(TestCase):
                 self._assert_attachments(actual.attachments, *expected['attachments'])
 
     def test_globals(self):
-        globals = self._make_ticket(self.test_issue).globals
+        globals = self._make_ticket(self.test_issue, issue_id=6).globals
         self.assertEqual(globals.open_status_names, 'New Accepted Started')
         self.assertEqual(globals.closed_status_names, 'Fixed Verified Invalid Duplicate WontFix
Done')
+        self.assertEqual(globals.last_ticket_num, 6)
         self.assertItemsEqual(globals.custom_fields, [
                 {
                     'label': 'Milestone',

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fa955f4c/ForgeImporters/forgeimporters/tests/google/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_tracker.py b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
index 3d0774f..48ddc44 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
@@ -39,8 +39,8 @@ class TestTrackerImporter(TestCase):
         importer.postprocess_custom_fields = mock.Mock()
         project, user = mock.Mock(), mock.Mock()
         app = project.install_app.return_value
-        issues = gpe.iter_issues.return_value = [mock.Mock(), mock.Mock()]
-        tickets = TM.Ticket.new.side_effect = [mock.Mock(), mock.Mock()]
+        issues = gpe.iter_issues.return_value = [(50, mock.Mock()), (100, mock.Mock())]
+        tickets = TM.Ticket.side_effect = [mock.Mock(), mock.Mock()]
 
         importer.import_tool(project, user, project_name='project_name',
                 mount_point='mount_point', mount_label='mount_label')
@@ -52,16 +52,16 @@ class TestTrackerImporter(TestCase):
             )
         gpe.iter_issues.assert_called_once_with('project_name')
         self.assertEqual(importer.process_fields.call_args_list, [
-                mock.call(tickets[0], issues[0]),
-                mock.call(tickets[1], issues[1]),
+                mock.call(tickets[0], issues[0][1]),
+                mock.call(tickets[1], issues[1][1]),
             ])
         self.assertEqual(importer.process_labels.call_args_list, [
-                mock.call(tickets[0], issues[0]),
-                mock.call(tickets[1], issues[1]),
+                mock.call(tickets[0], issues[0][1]),
+                mock.call(tickets[1], issues[1][1]),
             ])
         self.assertEqual(importer.process_comments.call_args_list, [
-                mock.call(tickets[0], issues[0]),
-                mock.call(tickets[1], issues[1]),
+                mock.call(tickets[0], issues[0][1]),
+                mock.call(tickets[1], issues[1][1]),
             ])
         self.assertEqual(tlos.flush_all.call_args_list, [
                 mock.call(),
@@ -75,6 +75,7 @@ class TestTrackerImporter(TestCase):
                 mock.call(tickets[0]),
                 mock.call(tickets[1]),
             ])
+        self.assertEqual(app.globals.last_ticket_num, 100)
         g.post_event.assert_called_once_with('project_updated')
 
     def test_custom_fields(self):


Mime
View raw message