Post update
This commit is contained in:
parent
1995e0479f
commit
a42a3b65d9
9 changed files with 116 additions and 17 deletions
|
|
@ -1,7 +1,8 @@
|
|||
from .update import update
|
||||
from .create import create
|
||||
from .get import get
|
||||
from .listbybranch import listbybranch
|
||||
from .listbyuserprofile import listbyuserprofile
|
||||
from .create import create
|
||||
from .listall import listall
|
||||
from .listpublic import listpublic
|
||||
from .listremoved import listremoved
|
||||
12
src/trustcafeapiwrapper/jobs/post/update.py
Normal file
12
src/trustcafeapiwrapper/jobs/post/update.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def update(API, payload: dict) -> dict:
|
||||
"""
|
||||
Updates an existing post in the API.
|
||||
|
||||
Args:
|
||||
payload (dict): The data for the post update.
|
||||
|
||||
Returns:
|
||||
dict: The post data.
|
||||
"""
|
||||
post_data = API.make_request("PUT", "content", "post/update", data=payload, authenticate=True)
|
||||
return post_data
|
||||
|
|
@ -1 +1,2 @@
|
|||
from .create_post import create_post
|
||||
from .update_post import update_post
|
||||
37
src/trustcafeapiwrapper/wrappers/post/update_post.py
Normal file
37
src/trustcafeapiwrapper/wrappers/post/update_post.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from trustcafeapiwrapper.utils import get_post_pksk, get_parent_pksk_from_path
|
||||
|
||||
def update_post(parent_path, post_path, post_text, blur_label=None, card_url=None, collaborative=False):
|
||||
"""
|
||||
Updates an existing post.
|
||||
|
||||
Args:
|
||||
post_slug (str): The slug of the post to update.
|
||||
post_text (str): The new text for the post.
|
||||
parent_path (str, optional): The parent path for the post. Defaults to '/'.
|
||||
blur_label (str, optional): The blur label for the post. Defaults to None.
|
||||
card_url (str, optional): The card URL for the post. Defaults to None.
|
||||
collaborative (bool, optional): Whether the post is collaborative. Defaults to False.
|
||||
|
||||
Returns:
|
||||
dict: The updated post data.
|
||||
"""
|
||||
parent_pksk = get_parent_pksk_from_path(parent_path)
|
||||
post_pksk = get_post_pksk(parent_pksk, post_path)
|
||||
|
||||
payload = {
|
||||
"key": {
|
||||
"pk": post_pksk.get('pk', None),
|
||||
"sk": post_pksk.get('sk', None)
|
||||
},
|
||||
"postSlug": post_path.strip('/post/'),
|
||||
"blurLabel": blur_label,
|
||||
"cardUrl": card_url,
|
||||
"postText": post_text,
|
||||
"collaborative": collaborative,
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
"job_function": "post.update",
|
||||
"payload": payload
|
||||
}
|
||||
31
testing.py
31
testing.py
|
|
@ -61,9 +61,9 @@ def save_response(response):
|
|||
# print("-----------------------------")
|
||||
# feed = API.run_job('post.listbybranch', "music")
|
||||
# print(feed)
|
||||
print("-----------------------------")
|
||||
feed = save_response(API.run_job('post.listremoved'))
|
||||
print(feed)
|
||||
# print("-----------------------------")
|
||||
# feed = save_response(API.run_job('post.listremoved'))
|
||||
# print(feed)
|
||||
# print("----------------------------z
|
||||
# branchlist = API.run_job('branch.listbyname')
|
||||
# print(branchlist)
|
||||
|
|
@ -80,6 +80,16 @@ print(feed)
|
|||
# print(feed)
|
||||
# print("-----------------------------")
|
||||
|
||||
# save_response(API.run_job('post.create', {
|
||||
# "blurLabel": None,
|
||||
# "cardUrl": None,
|
||||
# "postText": "This is a test post created via the API wrapper.",
|
||||
# "collaborative": False,
|
||||
# "parent": {
|
||||
# "pk": "maintrunk#maintrunk",
|
||||
# "sk": "maintrunk#maintrunk"
|
||||
# }
|
||||
# }))
|
||||
# save_response(API.run_job('post.create', {
|
||||
# "blurLabel": None,
|
||||
# "cardUrl": None,
|
||||
|
|
@ -183,8 +193,15 @@ print(feed)
|
|||
# users = API.run_job('trust.listbyuserhas', "simon-little ")
|
||||
# print(users)
|
||||
|
||||
from trustcafeapiwrapper.wrappers.trust import trust
|
||||
save_response(API.wrapped(trust(
|
||||
100,
|
||||
"/user/bossman"
|
||||
# from trustcafeapiwrapper.wrappers.trust import trust
|
||||
# save_response(API.wrapped(trust(
|
||||
# 100,
|
||||
# "/user/bossman"
|
||||
# )))
|
||||
|
||||
from trustcafeapiwrapper.wrappers.post.update_post import update_post
|
||||
save_response(API.wrapped(update_post(
|
||||
post_text="This is an updated version of the test post created via the create_post wrapper function.",
|
||||
post_path="/post/1775143460-ef45186a",
|
||||
parent_path="/",
|
||||
)))
|
||||
|
|
@ -13,10 +13,10 @@ class TestGetChildSpkskFromPaths(unittest.TestCase):
|
|||
self.assertEqual(get_child_spksk_from_paths(parent_path, item_path), expected_output)
|
||||
|
||||
def test_comment_reaction(self):
|
||||
parent_path = '/post/12345'
|
||||
parent_path = '/post/12345-abcv'
|
||||
item_path = '/comment/67890'
|
||||
expected_output = {
|
||||
"pk": "post#12345",
|
||||
"pk": "post#12345-abcv",
|
||||
"sk": "comment#67890",
|
||||
"entity": "comment",
|
||||
"slug": "67890"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class TestReact(unittest.TestCase):
|
|||
def test_react_to_post(self):
|
||||
reaction_type = 'like'
|
||||
parent_path = '/'
|
||||
item_path = '/post/12345'
|
||||
item_path = '/post/12345-abcv'
|
||||
result = react(reaction_type, parent_path, item_path)
|
||||
|
||||
self.assertIsInstance(result, dict)
|
||||
|
|
@ -14,13 +14,13 @@ class TestReact(unittest.TestCase):
|
|||
self.assertEqual(result["job_function"], "reaction.reacttosomething")
|
||||
self.assertEqual(result["payload"]["reaction"], reaction_type)
|
||||
self.assertEqual(result["payload"]["parent"]["pk"], "maintrunk#maintrunk")
|
||||
self.assertEqual(result["payload"]["parent"]["sk"], "post#12345")
|
||||
self.assertEqual(result["payload"]["parent"]["sk"], "post#12345-abcv")
|
||||
self.assertEqual(result["payload"]["parent"]["entity"], "post")
|
||||
self.assertEqual(result["payload"]["parent"]["slug"], "12345")
|
||||
self.assertEqual(result["payload"]["parent"]["slug"], "12345-abcv")
|
||||
|
||||
def test_react_to_comment(self):
|
||||
reaction_type = 'like'
|
||||
parent_path = '/post/12345'
|
||||
parent_path = '/post/12345-abcv'
|
||||
item_path = '/comment/67890'
|
||||
result = react(reaction_type, parent_path, item_path)
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ class TestReact(unittest.TestCase):
|
|||
self.assertIn("payload", result)
|
||||
self.assertEqual(result["job_function"], "reaction.reacttosomething")
|
||||
self.assertEqual(result["payload"]["reaction"], reaction_type)
|
||||
self.assertEqual(result["payload"]["parent"]["pk"], "post#12345")
|
||||
self.assertEqual(result["payload"]["parent"]["pk"], "post#12345-abcv")
|
||||
self.assertEqual(result["payload"]["parent"]["sk"], "comment#67890")
|
||||
self.assertEqual(result["payload"]["parent"]["entity"], "comment")
|
||||
self.assertEqual(result["payload"]["parent"]["slug"], "67890")
|
||||
30
tests/wrappers/update_post.py
Normal file
30
tests/wrappers/update_post.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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"]["blurLabel"], self.blur_label)
|
||||
self.assertEqual(result["payload"]["cardUrl"], self.card_url)
|
||||
self.assertEqual(result["payload"]["collaborative"], self.collaborative)
|
||||
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"])
|
||||
|
|
@ -11,6 +11,7 @@ from tests.utils.get_user_slug_from_path import TestGetUserSlugFromPath
|
|||
from tests.utils.get_userprofile_pksk_from_slug import TestGetUserprofilePkskFromSlug
|
||||
|
||||
from tests.wrappers.create_post import TestCreatePost
|
||||
from tests.wrappers.update_post import TestUpdatePost
|
||||
from tests.wrappers.create_comment import TestCreateComment
|
||||
from tests.wrappers.react import TestReact
|
||||
from tests.wrappers.vote import TestVoteCast
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue