You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/08/21 22:12:33 UTC

[17/50] git commit: [#3153] ticket:389 bulk_export outline for tracker

[#3153] ticket:389 bulk_export outline for tracker


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

Branch: refs/heads/db/3154b
Commit: 7c5fbbaaf156d15943234247bc08011d5a37a320
Parents: 5bb5c80
Author: Anton Kasyanov <mi...@gmail.com>
Authored: Mon Jul 22 19:23:02 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Aug 21 18:12:24 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py                |  9 ++++-
 ForgeTracker/forgetracker/tests/test_app.py | 47 ++++++++++++++++++++++++
 ForgeTracker/forgetracker/tracker_main.py   | 14 ++++++-
 3 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7c5fbbaa/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index e68eafb..8095f79 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -363,7 +363,14 @@ class DateTimeConverter(FancyValidator):
 def absurl(url):
     if url is None: return None
     if '://' in url: return url
-    return request.scheme + '://' + request.host + url
+    # some __json__ methods call absurl
+    # and in tests request is not set so exception raises
+    # this check prevents it
+    try:
+        host = request.scheme + '://' + request.host
+    except TypeError:
+        host = ''
+    return host + url
 
 def diff_text(t1, t2, differ=None):
     t1_lines = t1.replace('\r', '').split('\n')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7c5fbbaa/ForgeTracker/forgetracker/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/test_app.py b/ForgeTracker/forgetracker/tests/test_app.py
new file mode 100644
index 0000000..9c7e61e
--- /dev/null
+++ b/ForgeTracker/forgetracker/tests/test_app.py
@@ -0,0 +1,47 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+import datetime
+import tempfile
+import json
+import operator
+
+from nose.tools import assert_equal
+
+from allura import model as M
+from allura.tests import decorators as td
+from forgetracker import model as TM
+from forgetracker.tests.functional.test_root import TrackerTestController
+
+
+class TestBulkExport(TrackerTestController):
+    @td.with_tracker
+    def setup_with_tools(self):
+        super(TestBulkExport, self).setup_with_tools()
+        self.project = M.Project.query.get(shortname='test')
+        self.tracker = self.project.app_instance('bugs')
+        self.new_ticket(summary='foo', _milestone='1.0')
+
+    def test_bulk_export(self):
+        f = tempfile.TemporaryFile()
+        self.tracker.bulk_export(f)
+        f.seek(0)
+        tracker = json.loads(f.read())
+        #tickets = sorted(tracker['tickets'], key=operator.itemgetter('title'))
+        tickets = tracker['tickets']
+        print tickets
+        assert_equal(len(tickets), 1)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7c5fbbaa/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index cc28879..ff540c3 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -28,7 +28,7 @@ import jinja2
 
 # Non-stdlib imports
 import pkg_resources
-from tg import expose, validate, redirect, flash, url, config
+from tg import expose, validate, redirect, flash, url, config, jsonify
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from paste.deploy.converters import aslist
 from pylons import tmpl_context as c, app_globals as g
@@ -407,6 +407,18 @@ class ForgeTrackerApp(Application):
         TM.Globals.query.remove(app_config_id)
         super(ForgeTrackerApp, self).uninstall(project)
 
+    def bulk_export(self, f):
+        f.write('{"tickets": [')
+        tickets = TM.Ticket.query.find(dict(
+            app_config_id=self.config._id,
+            deleted=False)).all()
+        count = len(tickets)
+        for i, ticket in enumerate(tickets):
+            json.dump(ticket, f, cls=jsonify.GenericJSON)
+            if i < (count - 1):
+                f.write(',')
+        f.write(']}')
+
     @property
     def bins(self):
         return TM.Bin.query.find(dict(app_config_id=self.config._id)).sort('summary').all()