fixes to react and tested
This commit is contained in:
parent
60351f7cdb
commit
8704ad0e70
6 changed files with 26 additions and 11 deletions
|
|
@ -1,2 +1,2 @@
|
|||
from .react import create
|
||||
from .reacttosomething import reacttosomething
|
||||
from .listbyparent import listbyparent
|
||||
|
|
|
|||
1
src/trustcafeapiwrapper/wrappers/reaction/__init__.py
Normal file
1
src/trustcafeapiwrapper/wrappers/reaction/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .react import react
|
||||
|
|
@ -23,25 +23,29 @@ def react(reaction_type: str, parent_path: str, item_path: str):
|
|||
|
||||
|
||||
'''
|
||||
|
||||
slug = item_path.split('/')[-1]
|
||||
if item_path.startswith('/post'):
|
||||
# It's a reaction on a post
|
||||
top_level_parent_pk = get_parent_pksk_from_path(parent_path)
|
||||
item_pksk = get_post_pksk(top_level_parent_pk, item_path)
|
||||
entity = 'post'
|
||||
else:
|
||||
# It's a reaction on a comment
|
||||
item_pksk = {
|
||||
'pk': make_post_sk(parent_path),
|
||||
'sk': make_comment_sk(item_path)
|
||||
}
|
||||
entity = 'comment'
|
||||
|
||||
return {
|
||||
"job_function": "reaction.react",
|
||||
"job_function": "reaction.reacttosomething",
|
||||
"payload": {
|
||||
"reaction": reaction_type,
|
||||
"parent": {
|
||||
"pk": item_pksk.get('pk', None),
|
||||
"sk": item_pksk.get('sk', None),
|
||||
"entity": entity,
|
||||
"slug": slug
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
testing.py
16
testing.py
|
|
@ -49,9 +49,9 @@ def save_response(response):
|
|||
|
||||
|
||||
|
||||
print("-----------Get a user profile----------------")
|
||||
profile = API.run_job('userprofile.get', "simon-little")
|
||||
print(profile)
|
||||
# print("-----------Get a user profile----------------")
|
||||
# profile = API.run_job('userprofile.get', "simon-little")
|
||||
# print(profile)
|
||||
# print("-------------- Get a branch -----------------")
|
||||
# branch = API.run_job('branch.get', "music")
|
||||
# print(branch)
|
||||
|
|
@ -148,7 +148,7 @@ from trustcafeapiwrapper.wrappers.post.create_post import create_post
|
|||
# post_text="This is a test post created via the create_post wrapper function.",
|
||||
# parent_path="/branch/music",
|
||||
# ))
|
||||
|
||||
from trustcafeapiwrapper.wrappers.reaction import react
|
||||
# save_response(create_post(
|
||||
# "This is a test post created via the create_post wrapper function.",
|
||||
# "/userprofile/simon-little",
|
||||
|
|
@ -161,4 +161,10 @@ from trustcafeapiwrapper.wrappers.post.create_post import create_post
|
|||
|
||||
# save_response(API.wrapped(create_post(
|
||||
# "This is a test post created via the create_post wrapper function.",
|
||||
# )))
|
||||
# )))
|
||||
|
||||
save_response(API.wrapped(react(
|
||||
"thumbs_up",
|
||||
"/",
|
||||
"/post/1775075313-63ffb852"
|
||||
)))
|
||||
|
|
@ -11,10 +11,12 @@ class TestReact(unittest.TestCase):
|
|||
self.assertIsInstance(result, dict)
|
||||
self.assertIn("job_function", result)
|
||||
self.assertIn("payload", result)
|
||||
self.assertEqual(result["job_function"], "reaction.react")
|
||||
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"]["entity"], "post")
|
||||
self.assertEqual(result["payload"]["parent"]["slug"], "12345")
|
||||
|
||||
def test_react_to_comment(self):
|
||||
reaction_type = 'like'
|
||||
|
|
@ -25,7 +27,9 @@ class TestReact(unittest.TestCase):
|
|||
self.assertIsInstance(result, dict)
|
||||
self.assertIn("job_function", result)
|
||||
self.assertIn("payload", result)
|
||||
self.assertEqual(result["job_function"], "reaction.react")
|
||||
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"]["sk"], "comment#67890")
|
||||
self.assertEqual(result["payload"]["parent"]["sk"], "comment#67890")
|
||||
self.assertEqual(result["payload"]["parent"]["entity"], "comment")
|
||||
self.assertEqual(result["payload"]["parent"]["slug"], "67890")
|
||||
Loading…
Add table
Add a link
Reference in a new issue