trustcafe-api-wrapper/tests/wrappers/vote.py
2026-04-16 21:31:32 +01:00

53 lines
2.4 KiB
Python

import unittest
from trustcafeapiwrapper.wrappers.vote.votecast import votecast
class TestVoteCast(unittest.TestCase):
def test_vote_cast_to_post(self):
vote = 'up'
parent_path = '/'
item_path = '/post/12345'
result = votecast(vote, parent_path, item_path)
self.assertIsInstance(result, dict)
self.assertIn("job_function", result)
self.assertIn("payload", result)
self.assertEqual(result["job_function"], "vote.votecast")
self.assertEqual(result["payload"]["vote"], vote)
self.assertEqual(result["payload"]["parent"]["pk"], "maintrunk#maintrunk")
self.assertEqual(result["payload"]["parent"]["sk"], "post#12345")
self.assertEqual(result["payload"]["parent"]["entity"], "post")
self.assertEqual(result["payload"]["parent"]["slug"], "12345")
def test_vote_cast_to_comment(self):
vote = 'down'
parent_path = '/post/12345'
item_path = '/comment/67890'
result = votecast(vote, parent_path, item_path)
self.assertIsInstance(result, dict)
self.assertIn("job_function", result)
self.assertIn("payload", result)
self.assertEqual(result["job_function"], "vote.votecast")
self.assertEqual(result["payload"]["vote"], vote)
self.assertEqual(result["payload"]["parent"]["pk"], "post#12345")
self.assertEqual(result["payload"]["parent"]["sk"], "comment#67890")
self.assertEqual(result["payload"]["parent"]["entity"], "comment")
self.assertEqual(result["payload"]["parent"]["slug"], "67890")
def test_vote_cast_with_parent_key(self):
vote = 'up'
parent_key = {
'pk': 'post#12345',
'sk': 'comment#67890'
}
result = votecast(vote, item_key=parent_key)
self.assertIsInstance(result, dict)
self.assertIn("job_function", result)
self.assertIn("payload", result)
self.assertEqual(result["job_function"], "vote.votecast")
self.assertEqual(result["payload"]["vote"], vote)
self.assertEqual(result["payload"]["parent"]["pk"], "post#12345")
self.assertEqual(result["payload"]["parent"]["sk"], "comment#67890")
self.assertEqual(result["payload"]["parent"]["entity"], "comment")
self.assertEqual(result["payload"]["parent"]["slug"], "67890")