allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexlub...@apache.org
Subject allura git commit: [#7789] ticket:680 Return more fields in ticket API search results
Date Fri, 14 Nov 2014 15:17:48 GMT
Repository: allura
Updated Branches:
  refs/heads/master 915152493 -> 4d9f918a6


[#7789] ticket:680 Return more fields in ticket API search results


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

Branch: refs/heads/master
Commit: 4d9f918a67ad5ca5078a7534b61b1fddadf6f603
Parents: 9151524
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Nov 10 10:56:01 2014 +0000
Committer: Alexander Luberg <aluberg@slashdotmedia.com>
Committed: Fri Nov 14 07:16:40 2014 -0800

----------------------------------------------------------------------
 .../forgetracker/tests/functional/test_rest.py  | 43 +++++++++++++-------
 ForgeTracker/forgetracker/tracker_main.py       | 10 ++++-
 2 files changed, 36 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/4d9f918a/ForgeTracker/forgetracker/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_rest.py b/ForgeTracker/forgetracker/tests/functional/test_rest.py
index 455cff5..7c650be 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_rest.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_rest.py
@@ -191,23 +191,31 @@ class TestRestDiscussion(TestTrackerApiBase):
 
 class TestRestSearch(TestTrackerApiBase):
 
+    @property
+    def ticket(self):
+        return TM.Ticket(
+            ticket_num=5,
+            summary='our test ticket',
+            status='open',
+            labels=['tiny', 'minor'])
+
     @patch('forgetracker.model.Ticket.paged_search')
     def test_no_criteria(self, paged_search):
-        paged_search.return_value = dict(tickets=[
-            TM.Ticket(ticket_num=5, summary='our test ticket'),
-        ])
+        paged_search.return_value = dict(tickets=[self.ticket])
         r = self.api_get('/rest/p/test/bugs/search')
         assert_equal(r.status_int, 200)
-        assert_equal(r.json, {'tickets': [
-            {'summary': 'our test ticket', 'ticket_num': 5},
-        ]})
+        assert_equal(r.json['tickets'][0]['summary'], 'our test ticket')
+        assert_equal(r.json['tickets'][0]['ticket_num'], 5)
+        assert_equal(r.json['tickets'][0]['status'], 'open')
+        assert_equal(r.json['tickets'][0]['labels'], ['tiny', 'minor'])
+        assert 'description' not in r.json
+        assert 'discussion_thread' not in r.json
 
     @patch('forgetracker.model.Ticket.paged_search')
     def test_some_criteria(self, paged_search):
         q = 'labels:testing && status:open'
-        paged_search.return_value = dict(tickets=[
-            TM.Ticket(ticket_num=5, summary='our test ticket'),
-        ],
+        paged_search.return_value = dict(
+            tickets=[self.ticket],
             sort='status',
             limit=2,
             count=1,
@@ -217,9 +225,14 @@ class TestRestSearch(TestTrackerApiBase):
         r = self.api_get('/rest/p/test/bugs/search',
                          q=q, sort='status', limit='2')
         assert_equal(r.status_int, 200)
-        assert_equal(r.json, {'limit': 2, 'q': q, 'sort': 'status', 'count': 1,
-                              'page': 0, 'tickets': [
-                                  {'summary': 'our test ticket',
-                                   'ticket_num': 5},
-                              ]
-                              })
+        assert_equal(r.json['limit'], 2)
+        assert_equal(r.json['q'], q)
+        assert_equal(r.json['sort'], 'status')
+        assert_equal(r.json['count'], 1)
+        assert_equal(r.json['page'], 0)
+        assert_equal(r.json['tickets'][0]['summary'], 'our test ticket')
+        assert_equal(r.json['tickets'][0]['ticket_num'], 5)
+        assert_equal(r.json['tickets'][0]['status'], 'open')
+        assert_equal(r.json['tickets'][0]['labels'], ['tiny', 'minor'])
+        assert 'description' not in r.json
+        assert 'discussion_thread' not in r.json

http://git-wip-us.apache.org/repos/asf/allura/blob/4d9f918a/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index d37b5b1..fd8917e 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -1717,10 +1717,16 @@ class RootRestController(BaseController):
 
     @expose('json:')
     def search(self, q=None, limit=100, page=0, sort=None, **kw):
+        def _convert_ticket(t):
+            t = t.__json__()
+            # just pop out all the heavy stuff
+            for field in ['description', 'discussion_thread']:
+                t.pop(field, None)
+            return t
+
         results = TM.Ticket.paged_search(
             c.app.config, c.user, q, limit, page, sort, show_deleted=False)
-        results['tickets'] = [dict(ticket_num=t.ticket_num, summary=t.summary)
-                              for t in results['tickets']]
+        results['tickets'] = map(_convert_ticket, results['tickets'])
         return results
 
     @expose()


Mime
View raw message