137 lines
No EOL
6 KiB
Python
137 lines
No EOL
6 KiB
Python
import unittest
|
|
from trustcafeapiwrapper.wrappers.post.update_post import update_post
|
|
class TestUpdatePost(unittest.TestCase):
|
|
def setUp(self):
|
|
self.post_text = "This is an updated test post created via the update_post wrapper function."
|
|
self.blur_label = None
|
|
self.card_url = None
|
|
self.collaborative = False
|
|
|
|
def test_update_post(self):
|
|
result = update_post(
|
|
parent_path='/',
|
|
post_path='/post/1235-abcv',
|
|
post_text=self.post_text,
|
|
blur_label=self.blur_label,
|
|
card_url=self.card_url,
|
|
collaborative=self.collaborative
|
|
)
|
|
self.assertIsInstance(result, dict)
|
|
self.assertIn("job_function", result)
|
|
self.assertIn("payload", result)
|
|
self.assertEqual(result["job_function"], "post.update")
|
|
self.assertEqual(result["payload"]["postText"], self.post_text)
|
|
self.assertEqual(result["payload"]["postSlug"], "1235-abcv")
|
|
self.assertEqual(result["payload"]["key"]["pk"], "maintrunk#maintrunk")
|
|
self.assertEqual(result["payload"]["key"]["sk"], "post#1235-abcv")
|
|
self.assertNotIn("slug", result["payload"]["key"])
|
|
|
|
def test_update_post_with_post_key(self):
|
|
post_key = {
|
|
"pk": "maintrunk#maintrunk",
|
|
"sk": "post#1235-abcv"
|
|
}
|
|
result = update_post(
|
|
post_key=post_key,
|
|
post_text=self.post_text,
|
|
blur_label=self.blur_label,
|
|
card_url=self.card_url,
|
|
collaborative=self.collaborative,
|
|
)
|
|
self.assertIsInstance(result, dict)
|
|
self.assertIn("job_function", result)
|
|
self.assertIn("payload", result)
|
|
self.assertEqual(result["job_function"], "post.update")
|
|
self.assertEqual(result["payload"]["postText"], self.post_text)
|
|
self.assertEqual(result["payload"]["postSlug"], "1235-abcv")
|
|
self.assertEqual(result["payload"]["key"]["pk"], post_key["pk"])
|
|
self.assertEqual(result["payload"]["key"]["sk"], post_key["sk"])
|
|
self.assertNotIn("slug", result["payload"]["key"])
|
|
|
|
def test_update_collaborative_post(self):
|
|
collaborative = True
|
|
result = update_post(
|
|
parent_path='/',
|
|
post_path='/post/1235-abcv',
|
|
post_text=self.post_text,
|
|
blur_label=self.blur_label,
|
|
card_url=self.card_url,
|
|
collaborative=collaborative
|
|
)
|
|
self.assertIsInstance(result, dict)
|
|
self.assertIn("job_function", result)
|
|
self.assertIn("payload", result)
|
|
self.assertEqual(result["job_function"], "post.update")
|
|
self.assertEqual(result["payload"]["postText"], self.post_text)
|
|
self.assertEqual(result["payload"]["postSlug"], "1235-abcv")
|
|
self.assertEqual(result["payload"]["key"]["pk"], "maintrunk#maintrunk")
|
|
self.assertEqual(result["payload"]["key"]["sk"], "post#1235-abcv")
|
|
self.assertNotIn("slug", result["payload"]["key"])
|
|
self.assertTrue(result["payload"]["collaborative"])
|
|
|
|
def test_update_blur_label_and_card_url(self):
|
|
blur_label = "Sensitive Content"
|
|
card_url = "https://example.com/card"
|
|
result = update_post(
|
|
parent_path='/',
|
|
post_path='/post/1235-abcv',
|
|
post_text=self.post_text,
|
|
blur_label=blur_label,
|
|
card_url=card_url,
|
|
collaborative=self.collaborative
|
|
)
|
|
self.assertIsInstance(result, dict)
|
|
self.assertIn("job_function", result)
|
|
self.assertIn("payload", result)
|
|
self.assertEqual(result["job_function"], "post.update")
|
|
self.assertEqual(result["payload"]["postText"], self.post_text)
|
|
self.assertEqual(result["payload"]["postSlug"], "1235-abcv")
|
|
self.assertEqual(result["payload"]["key"]["pk"], "maintrunk#maintrunk")
|
|
self.assertEqual(result["payload"]["key"]["sk"], "post#1235-abcv")
|
|
self.assertNotIn("slug", result["payload"]["key"])
|
|
self.assertEqual(result["payload"]["blurLabel"], blur_label)
|
|
self.assertEqual(result["payload"]["cardUrl"], card_url)
|
|
|
|
def test_update_post_with_post_key(self):
|
|
post_key = {
|
|
"pk": "maintrunk#maintrunk",
|
|
"sk": "post#1235-abcv"
|
|
}
|
|
result = update_post(
|
|
post_key=post_key,
|
|
post_text=self.post_text,
|
|
blur_label=self.blur_label,
|
|
card_url=self.card_url,
|
|
collaborative=self.collaborative,
|
|
)
|
|
self.assertIsInstance(result, dict)
|
|
self.assertIn("job_function", result)
|
|
self.assertIn("payload", result)
|
|
self.assertEqual(result["job_function"], "post.update")
|
|
self.assertEqual(result["payload"]["postText"], self.post_text)
|
|
self.assertEqual(result["payload"]["postSlug"], "1235-abcv")
|
|
self.assertEqual(result["payload"]["key"]["pk"], post_key["pk"])
|
|
self.assertEqual(result["payload"]["key"]["sk"], post_key["sk"])
|
|
self.assertNotIn("slug", result["payload"]["key"])
|
|
|
|
def test_update_post_missing_post_text(self):
|
|
with self.assertRaises(ValueError) as context:
|
|
update_post(
|
|
parent_path='/',
|
|
post_path='/post/1235-abcv',
|
|
post_text=None,
|
|
blur_label=self.blur_label,
|
|
card_url=self.card_url,
|
|
collaborative=self.collaborative
|
|
)
|
|
self.assertEqual(str(context.exception), "post_text is required.")
|
|
|
|
def test_update_post_missing_identification(self):
|
|
with self.assertRaises(ValueError) as context:
|
|
update_post(
|
|
post_text=self.post_text,
|
|
blur_label=self.blur_label,
|
|
card_url=self.card_url,
|
|
collaborative=self.collaborative
|
|
)
|
|
self.assertEqual(str(context.exception), "Either post_path and parent_path or post_key must be provided.") |