Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/units/model/post.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/model/post.py')
-rwxr-xr-xtests/units/model/post.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/units/model/post.py b/tests/units/model/post.py
index 91a0298..931bd66 100755
--- a/tests/units/model/post.py
+++ b/tests/units/model/post.py
@@ -3,6 +3,7 @@
from __init__ import tests
+from sugar_network import db
from sugar_network.client import Connection, keyfile
from sugar_network.model.user import User
from sugar_network.model.context import Context
@@ -41,6 +42,25 @@ class PostTest(tests.Test):
context,
client.get(['post', comment, 'context']))
+ def test_RatingSort(self):
+ directory = db.Volume('db', [Post])['post']
+
+ directory.create({'guid': '1', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [0, 0]})
+ directory.create({'guid': '2', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [1, 2]})
+ directory.create({'guid': '3', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [1, 4]})
+ directory.create({'guid': '4', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [10, 10]})
+ directory.create({'guid': '5', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'rating': [30, 90]})
+
+ self.assertEqual(
+ ['1', '2', '3', '4', '5'],
+ [i.guid for i in directory.find()[0]])
+ self.assertEqual(
+ ['1', '4', '2', '5', '3'],
+ [i.guid for i in directory.find(order_by='rating')[0]])
+ self.assertEqual(
+ ['3', '5', '2', '4', '1'],
+ [i.guid for i in directory.find(order_by='-rating')[0]])
+
if __name__ == '__main__':
tests.main()