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.py176
1 files changed, 119 insertions, 57 deletions
diff --git a/tests/units/model/post.py b/tests/units/model/post.py
index dc6f6f4..45b85e1 100755
--- a/tests/units/model/post.py
+++ b/tests/units/model/post.py
@@ -8,74 +8,27 @@ from sugar_network.client import Connection, keyfile
from sugar_network.model.user import User
from sugar_network.model.context import Context
from sugar_network.model.post import Post
-from sugar_network.model.release import Release
+from sugar_network.toolkit.coroutine import this
from sugar_network.toolkit import http
class PostTest(tests.Test):
- def test_SetContext(self):
- volume = self.start_master([User, Context, Release, Post])
- client = Connection(auth=http.SugarAuth(keyfile.value))
-
- self.assertRaises(http.NotFound, client.post, ['post'], {'type': 'comment', 'title': '', 'message': '', 'topic': 'absent'})
-
- context = client.post(['context'], {
- 'type': 'package',
- 'title': 'title',
- 'summary': 'summary',
- 'description': 'description',
- })
- topic = client.post(['post'], {
- 'context': context,
- 'title': 'title',
- 'message': 'message',
- 'type': 'update',
- })
- comment = client.post(['post'], {
- 'topic': topic,
- 'title': 'title',
- 'message': 'message',
- 'type': 'comment',
- })
- self.assertEqual(
- 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]])
-
def test_FindComments(self):
directory = db.Volume('db', [Post])['post']
- directory.create({'guid': '1', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'foo'},
+ directory.create({'guid': '1', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'foo'}},
}})
- directory.create({'guid': '2', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'bar'},
+ directory.create({'guid': '2', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'bar'}},
}})
- directory.create({'guid': '3', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'bar'},
- '2': {'message': 'foo'},
+ directory.create({'guid': '3', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'bar'}},
+ '2': {'value': {'en': 'foo'}},
}})
- directory.create({'guid': '4', 'context': '', 'type': 'comment', 'title': '', 'message': '', 'comments': {
- '1': {'message': 'foo bar'},
+ directory.create({'guid': '4', 'context': '', 'type': 'post', 'title': {}, 'message': {}, 'comments': {
+ '1': {'value': {'en': 'foo bar'}},
}})
self.assertEqual(
@@ -92,6 +45,115 @@ class PostTest(tests.Test):
['1', '3', '4'],
[i.guid for i in directory.find(query='comments:foo')[0]])
+ def test_ShiftContextRating(self):
+ volume = db.Volume('db', [Context, Post])
+ this.volume = volume
+
+ context = volume['context'].create({
+ 'type': 'activity',
+ 'title': {},
+ 'summary': {},
+ 'description': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 0,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 1,
+ })
+ self.assertEqual([1, 1], volume['context'][context]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 2,
+ })
+ self.assertEqual([2, 3], volume['context'][context]['rating'])
+
+ def test_ShiftTopicRating(self):
+ volume = db.Volume('db2', [Context, Post])
+ this.volume = volume
+
+ context = volume['context'].create({
+ 'type': 'activity',
+ 'title': {},
+ 'summary': {},
+ 'description': {},
+ })
+ topic = volume['post'].create({
+ 'context': context,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([0, 0], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([0, 0], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 0,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([0, 0], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 1,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([1, 1], volume['post'][topic]['rating'])
+
+ volume['post'].create({
+ 'context': context,
+ 'topic': topic,
+ 'type': 'post',
+ 'title': {},
+ 'message': {},
+ 'vote': 2,
+ })
+ self.assertEqual([0, 0], volume['context'][context]['rating'])
+ self.assertEqual([2, 3], volume['post'][topic]['rating'])
+
if __name__ == '__main__':
tests.main()