diff --git a/src/trustcafeapiwrapper/jobs/reaction/__init__.py b/src/trustcafeapiwrapper/jobs/reaction/__init__.py index 9783e26..86a2c04 100644 --- a/src/trustcafeapiwrapper/jobs/reaction/__init__.py +++ b/src/trustcafeapiwrapper/jobs/reaction/__init__.py @@ -1,2 +1,2 @@ -from .react import create +from .reacttosomething import reacttosomething from .listbyparent import listbyparent diff --git a/src/trustcafeapiwrapper/jobs/reaction/react.py b/src/trustcafeapiwrapper/jobs/reaction/reacttosomething.py similarity index 100% rename from src/trustcafeapiwrapper/jobs/reaction/react.py rename to src/trustcafeapiwrapper/jobs/reaction/reacttosomething.py diff --git a/src/trustcafeapiwrapper/wrappers/reaction/__init__.py b/src/trustcafeapiwrapper/wrappers/reaction/__init__.py new file mode 100644 index 0000000..db991a6 --- /dev/null +++ b/src/trustcafeapiwrapper/wrappers/reaction/__init__.py @@ -0,0 +1 @@ +from .react import react \ No newline at end of file diff --git a/src/trustcafeapiwrapper/wrappers/reaction/react.py b/src/trustcafeapiwrapper/wrappers/reaction/react.py index 8419fb2..3c25408 100644 --- a/src/trustcafeapiwrapper/wrappers/reaction/react.py +++ b/src/trustcafeapiwrapper/wrappers/reaction/react.py @@ -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 } } } diff --git a/testing.py b/testing.py index bdaa7d6..dda5955 100644 --- a/testing.py +++ b/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.", -# ))) \ No newline at end of file +# ))) + +save_response(API.wrapped(react( + "thumbs_up", + "/", + "/post/1775075313-63ffb852" +))) \ No newline at end of file diff --git a/tests/wrappers/react.py b/tests/wrappers/react.py index 59d7a6a..52598f3 100644 --- a/tests/wrappers/react.py +++ b/tests/wrappers/react.py @@ -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") \ No newline at end of file + self.assertEqual(result["payload"]["parent"]["sk"], "comment#67890") + self.assertEqual(result["payload"]["parent"]["entity"], "comment") + self.assertEqual(result["payload"]["parent"]["slug"], "67890") \ No newline at end of file