You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/09/17 21:57:39 UTC

[12/50] git commit: [#6640] expose votes_up and votes_down in ticket API & export

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

Branch: refs/heads/cj/6422
Commit: 6e4fe74ed10b05cfff37a981e7849d0575ec0776
Parents: 815ef4f
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Mon Sep 9 20:22:47 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Sep 10 12:52:05 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/6e4fe74e/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 46c4b01..3910cad 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -896,3 +896,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/6e4fe74e/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/6e4fe74e/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 1d4aeb2..505a991 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/6e4fe74e/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