incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [12/50] git commit: [#3153] ticket:389 bulk_export outline for tracker
Date Fri, 23 Aug 2013 16:58:12 GMT
[#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/21ed41e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/21ed41e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/21ed41e3

Branch: refs/heads/cj/6530
Commit: 21ed41e3aa84f24a03d3b01b4e4e675b9082606d
Parents: f0d671e
Author: Anton Kasyanov <mind1master@gmail.com>
Authored: Mon Jul 22 19:23:02 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Aug 22 20:04:41 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/21ed41e3/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/21ed41e3/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/21ed41e3/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()


Mime
View raw message