incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [02/20] git commit: [#6640] expose votes_up and votes_down in ticket API & export
Date Tue, 10 Sep 2013 15:11:03 GMT
[#6640] expose votes_up and votes_down in ticket API & export


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

Branch: refs/heads/cj/6540
Commit: f3d3166dff92da0488fdbb6f9b8fc3ad3a1019a5
Parents: f190769
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Mon Sep 9 20:22:47 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Sep 9 20:22:47 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py                           |  6 ++++++
 Allura/allura/tests/unit/test_mixins.py                   | 10 ++++++++++
 ForgeTracker/forgetracker/model/ticket.py                 |  7 ++++++-
 ForgeTracker/forgetracker/tests/unit/test_ticket_model.py |  9 ++++++++-
 4 files changed, 30 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f3d3166d/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 294c3d0..82baad6 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -893,3 +893,9 @@ class VotableArtifact(MappedClass):
         if votes_count == 0:
             return 0
         return int(float(self.votes_up) / votes_count * 100)
+
+    def __json__(self):
+        return {
+            'votes_up': self.votes_up,
+            'votes_down': self.votes_down,
+        }

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f3d3166d/Allura/allura/tests/unit/test_mixins.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_mixins.py b/Allura/allura/tests/unit/test_mixins.py
index a35cbb6..a6c508f 100644
--- a/Allura/allura/tests/unit/test_mixins.py
+++ b/Allura/allura/tests/unit/test_mixins.py
@@ -75,3 +75,13 @@ class TestVotableArtifact(object):
         assert vote.votes_down_users == [self.user1.username]
         assert vote.votes_up == 0
         assert len(vote.votes_up_users) == 0
+
+    def test_json(self):
+        vote = VotableArtifact()
+        assert vote.__json__() == {'votes_up': 0, 'votes_down': 0}
+
+        vote.vote_down(self.user1)
+        assert vote.__json__() == {'votes_up': 0, 'votes_down': 1}
+
+        vote.vote_up(self.user2)
+        assert vote.__json__() == {'votes_up': 1, 'votes_down': 1}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f3d3166d/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index d16039e..9995257 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -947,7 +947,12 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
         return ticket
 
     def __json__(self):
-        return dict(super(Ticket,self).__json__(),
+        parents_json = {}
+        for parent in reversed(type(self).mro()):
+            if parent != type(self) and hasattr(parent, '__json__'):
+                parents_json.update(parent.__json__(self))
+
+        return dict(parents_json,
             created_date=self.created_date,
             ticket_num=self.ticket_num,
             summary=self.summary,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f3d3166d/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
index 145bc7c..7f7fdd7 100644
--- a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
+++ b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py
@@ -21,7 +21,7 @@ import urllib2
 
 from ming.orm.ormsession import ThreadLocalORMSession
 from ming import schema
-from nose.tools import raises, assert_raises, assert_equal
+from nose.tools import raises, assert_raises, assert_equal, assert_in
 
 from forgetracker.model import Ticket, TicketAttachment
 from forgetracker.tests.unit import TrackerTestWithModel
@@ -277,3 +277,10 @@ class TestTicketModel(TrackerTestWithModel):
         ThreadLocalORMSession.flush_all()
         assert_equal(len(ticket.attachments), 1)
         assert_equal(ticket.attachments.first().filename, 'test_ticket_model.py')
+
+    def test_json_parents(self):
+        ticket = Ticket.new()
+        json_keys = ticket.__json__().keys()
+        assert_in('related_artifacts', json_keys)  # from Artifact
+        assert_in('votes_up', json_keys)  # VotableArtifact
+        assert_in('ticket_num', json_keys)  # Ticket


Mime
View raw message