From 766ff5b69de83790993018ab75a983eb8aad5e1b Mon Sep 17 00:00:00 2001 From: simonwt Date: Tue, 7 Apr 2026 21:54:52 +0100 Subject: [PATCH 1/5] Tested and fixed trust createorupdate --- .../jobs/trust/createorupdate.py | 2 +- src/trustcafeapiwrapper/utils/__init__.py | 4 +++- .../utils/get_user_slug_from_path.py | 21 ++++++++++++++++++ .../utils/get_userprofile_pksk_from_slug.py | 6 +++++ .../wrappers/trust/__init__.py | 1 + .../wrappers/trust/trust.py | 22 +++++++++++++++++++ testing.py | 10 +++++++-- tests/utils/get_user_slug_from_path.py | 8 +++++++ tests/utils/get_userprofile_pksk_from_slug.py | 11 ++++++++++ tests/wrappers/trust.py | 15 +++++++++++++ unittests.py | 4 ++++ 11 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/trustcafeapiwrapper/utils/get_user_slug_from_path.py create mode 100644 src/trustcafeapiwrapper/utils/get_userprofile_pksk_from_slug.py create mode 100644 src/trustcafeapiwrapper/wrappers/trust/__init__.py create mode 100644 src/trustcafeapiwrapper/wrappers/trust/trust.py create mode 100644 tests/utils/get_user_slug_from_path.py create mode 100644 tests/utils/get_userprofile_pksk_from_slug.py create mode 100644 tests/wrappers/trust.py diff --git a/src/trustcafeapiwrapper/jobs/trust/createorupdate.py b/src/trustcafeapiwrapper/jobs/trust/createorupdate.py index 3e1b810..a254103 100644 --- a/src/trustcafeapiwrapper/jobs/trust/createorupdate.py +++ b/src/trustcafeapiwrapper/jobs/trust/createorupdate.py @@ -8,5 +8,5 @@ def createorupdate(API, payload: dict) -> dict: Returns: dict: The trust relationship data. """ - trust_data = API.make_request("POST", "content", "reltrust", data=payload, authenticate=True) + trust_data = API.make_request("PUT", "content", "reltrust", data=payload, authenticate=True) return trust_data \ No newline at end of file diff --git a/src/trustcafeapiwrapper/utils/__init__.py b/src/trustcafeapiwrapper/utils/__init__.py index f0d7955..08e5cba 100644 --- a/src/trustcafeapiwrapper/utils/__init__.py +++ b/src/trustcafeapiwrapper/utils/__init__.py @@ -2,4 +2,6 @@ from .get_parent_pksk_from_path import get_parent_pksk_from_path from .get_post_pksk import get_post_pksk from .make_comment_sk import make_comment_sk from .make_post_sk import make_post_sk -from .get_child_spksk_from_paths import get_child_spksk_from_paths \ No newline at end of file +from .get_child_spksk_from_paths import get_child_spksk_from_paths +from .get_user_slug_from_path import get_user_slug_from_path +from .get_userprofile_pksk_from_slug import get_userprofile_pksk_from_slug \ No newline at end of file diff --git a/src/trustcafeapiwrapper/utils/get_user_slug_from_path.py b/src/trustcafeapiwrapper/utils/get_user_slug_from_path.py new file mode 100644 index 0000000..0bc57e8 --- /dev/null +++ b/src/trustcafeapiwrapper/utils/get_user_slug_from_path.py @@ -0,0 +1,21 @@ +def get_user_slug_from_path(path: str): + """ + Extracts the user slug from a given path. + + Args: + path (str): The path from which to extract the user slug. + + Returns: + str: The extracted user slug. + """ + if not isinstance(path, str): + raise ValueError("Input path must be a string.") + + if '/userprofile/' in path: + return path.split('/userprofile/')[-1] + elif '/user/' in path: + return path.split('/user/')[-1] + elif '/' not in path: + return path + else: + return None \ No newline at end of file diff --git a/src/trustcafeapiwrapper/utils/get_userprofile_pksk_from_slug.py b/src/trustcafeapiwrapper/utils/get_userprofile_pksk_from_slug.py new file mode 100644 index 0000000..150cca0 --- /dev/null +++ b/src/trustcafeapiwrapper/utils/get_userprofile_pksk_from_slug.py @@ -0,0 +1,6 @@ +def get_userprofile_pksk_from_slug(slug: str): + pksk = "userprofile#" + slug + return { + "pk": pksk, + "sk": pksk + } \ No newline at end of file diff --git a/src/trustcafeapiwrapper/wrappers/trust/__init__.py b/src/trustcafeapiwrapper/wrappers/trust/__init__.py new file mode 100644 index 0000000..3da5ff2 --- /dev/null +++ b/src/trustcafeapiwrapper/wrappers/trust/__init__.py @@ -0,0 +1 @@ +from .trust import trust \ No newline at end of file diff --git a/src/trustcafeapiwrapper/wrappers/trust/trust.py b/src/trustcafeapiwrapper/wrappers/trust/trust.py new file mode 100644 index 0000000..3bb5c56 --- /dev/null +++ b/src/trustcafeapiwrapper/wrappers/trust/trust.py @@ -0,0 +1,22 @@ +from trustcafeapiwrapper.utils import get_user_slug_from_path, get_userprofile_pksk_from_slug + +def trust(trustLevel: str, userprofile_path: str): + """ + Creates new or update existing trust entry in the API. + + Args: + + Returns: + dict: A dictionary containing the job name and payload for creating the post + that will be processed by the API client wrapper function. + """ + userProfileSlug = get_user_slug_from_path(userprofile_path) + userPKSK = get_userprofile_pksk_from_slug(userProfileSlug) + return { + "job_function": "trust.createorupdate", + "payload": { + "trustLevel": trustLevel, + "parentSlug": userProfileSlug, + "parent": userPKSK + } + } diff --git a/testing.py b/testing.py index bd8f217..5ede80d 100644 --- a/testing.py +++ b/testing.py @@ -141,7 +141,7 @@ print(feed) # save_response(API.run_job('post.listall')) # save_response(API.run_job('post.listpublic')) -from trustcafeapiwrapper.wrappers.post.create_post import create_post +# from trustcafeapiwrapper.wrappers.post.create_post import create_post # save_response(create_post( # post_text="This is a test post created via the create_post wrapper function.", @@ -181,4 +181,10 @@ from trustcafeapiwrapper.wrappers.post.create_post import create_post # users = API.run_job('trust.listbyuserinit', "simon-little") # print(users) # users = API.run_job('trust.listbyuserhas', "simon-little ") -# print(users) \ No newline at end of file +# print(users) + +from trustcafeapiwrapper.wrappers.trust import trust +save_response(API.wrapped(trust( + 100, + "/user/bossman" +))) \ No newline at end of file diff --git a/tests/utils/get_user_slug_from_path.py b/tests/utils/get_user_slug_from_path.py new file mode 100644 index 0000000..9b59905 --- /dev/null +++ b/tests/utils/get_user_slug_from_path.py @@ -0,0 +1,8 @@ +import unittest +from trustcafeapiwrapper.utils.get_user_slug_from_path import get_user_slug_from_path + +class TestGetUserSlugFromPath(unittest.TestCase): + def test_get_user_slug_from_path(self): + + # Test with a valid user path + self.assertEqual(get_user_slug_from_path('/user/johndoe'), 'johndoe') diff --git a/tests/utils/get_userprofile_pksk_from_slug.py b/tests/utils/get_userprofile_pksk_from_slug.py new file mode 100644 index 0000000..3ce5163 --- /dev/null +++ b/tests/utils/get_userprofile_pksk_from_slug.py @@ -0,0 +1,11 @@ +import unittest +from trustcafeapiwrapper.utils.get_userprofile_pksk_from_slug import get_userprofile_pksk_from_slug + +class TestGetUserprofilePkskFromSlug(unittest.TestCase): + def test_get_userprofile_pksk_from_slug(self): + slug = 'testuser' + expected_result = { + "pk": "userprofile#testuser", + "sk": "userprofile#testuser" + } + self.assertEqual(get_userprofile_pksk_from_slug(slug), expected_result) diff --git a/tests/wrappers/trust.py b/tests/wrappers/trust.py new file mode 100644 index 0000000..fe723f8 --- /dev/null +++ b/tests/wrappers/trust.py @@ -0,0 +1,15 @@ +import unittest +from trustcafeapiwrapper.wrappers.trust.trust import trust + +class TestTrustCreateOrUpdate(unittest.TestCase): + def test_trust(self): + trustLevel = 100 + userprofile_path = '/user/johndoe' + result = trust(trustLevel, userprofile_path) + + self.assertIsInstance(result, dict) + self.assertIn("job_function", result) + self.assertIn("payload", result) + self.assertEqual(result["job_function"], "trust.createorupdate") + self.assertEqual(result["payload"]["trustLevel"], trustLevel) + self.assertEqual(result["payload"]["parentSlug"], "johndoe") \ No newline at end of file diff --git a/unittests.py b/unittests.py index e409dff..f787956 100644 --- a/unittests.py +++ b/unittests.py @@ -7,11 +7,15 @@ from tests.utils.get_parent_pksk_from_path import TestGetParentPkskFromPath from tests.utils.make_comment_sk import TestMakeCommentSk from tests.utils.make_post_sk import TestMakePostSk from tests.utils.get_child_spksk_from_paths import TestGetChildSpkskFromPaths +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.create_comment import TestCreateComment from tests.wrappers.react import TestReact from tests.wrappers.vote import TestVoteCast +from tests.wrappers.trust import TestTrustCreateOrUpdate + from tests.apiclient import TestAPIClient From 0072e40c5ad685b6583d4ea62d09703a1dab14ee Mon Sep 17 00:00:00 2001 From: simonwt Date: Tue, 7 Apr 2026 21:58:47 +0100 Subject: [PATCH 2/5] Version --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f7bae90..f164da6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "trustcafeapiwrapper" -version = "0.1.0.5" -description = "Add your description here" +version = "0.1.0.6" +description = "Wraps the Trust Cafe API" readme = "README.md" requires-python = ">=3.13" dependencies = [ From 590fae14072aaabb1cb02a683f7927c124a02f20 Mon Sep 17 00:00:00 2001 From: simonwt Date: Tue, 7 Apr 2026 22:32:13 +0100 Subject: [PATCH 3/5] changing environment variables --- src/trustcafeapiwrapper/apiclient.py | 32 ++++++++++++++++++++++++++-- tests/apiclient.py | 19 +++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/trustcafeapiwrapper/apiclient.py b/src/trustcafeapiwrapper/apiclient.py index 0fe78ef..6e31fcb 100644 --- a/src/trustcafeapiwrapper/apiclient.py +++ b/src/trustcafeapiwrapper/apiclient.py @@ -11,7 +11,17 @@ endpoints = { "auth": "https://oo0wks9pbi.execute-api.us-east-1.amazonaws.com/alpha/", "content": "https://w1yygdhayc.execute-api.us-east-1.amazonaws.com/alpha/", "megaphone": "https://opdhjaktnl.execute-api.us-east-1.amazonaws.com/alpha/", - } + "moderation": "https://sbb1xrqsf1.execute-api.us-east-1.amazonaws.com/alpha/", + "spider": "https://xuvz1oj1sk.execute-api.us-east-1.amazonaws.com/dev/" + }, + "production": { + "audrey": "https://iiouau5d2k.execute-api.us-east-1.amazonaws.com/production/", + "auth": "https://e2we3nktl4.execute-api.us-east-1.amazonaws.com/production/", + "content": "https://32hho6rvg1.execute-api.us-east-1.amazonaws.com/production/", + "megaphone": "https://yfnamdpnc8.execute-api.us-east-1.amazonaws.com/production/", + "moderation": "https://egfpoo3mw3.execute-api.us-east-1.amazonaws.com/production/", + "spider": "https://coi5kvgypc.execute-api.us-east-1.amazonaws.com/production/" + }, } class APIClient(BaseModel): # Internal State (Not passed in __init__) @@ -26,7 +36,14 @@ class APIClient(BaseModel): _access_token: str = PrivateAttr(default="") _access_token_timeout: int = PrivateAttr(default=0) - + def __init__(self, **data): + super().__init__(**data) + self.validate_environment() + + def validate_environment(self): + if self.environment not in endpoints: + raise ValueError(f"Environment '{self.environment}' is not valid. Must be one of: {list(endpoints.keys())}") + def make_request(self, method: str, endpoint: str, path: str, data: dict = None, authenticate: bool = True, query_params: dict = None) -> dict: # Make sure the endpoint is defined in the endpoints dictionary @@ -112,6 +129,17 @@ class APIClient(BaseModel): self._access_token = token_data.get("access_token", "") self._access_token_timeout = token_data.get("access_token_timeout", 0) + def set_environment(self, environment: str) -> None: + """ + Set the environment for the API client. + + Args: + environment (str): The environment to set (e.g., "alpha", "production"). + """ + + self.validate_environment() + self.environment = environment + def is_token_valid(self) -> bool: """ Checks if the current access token is still valid based on the current time and the token's expiration time. diff --git a/tests/apiclient.py b/tests/apiclient.py index 81f24f0..e34b38a 100644 --- a/tests/apiclient.py +++ b/tests/apiclient.py @@ -46,6 +46,25 @@ class TestAPIClient(unittest.TestCase): result = self.api_client.run_job(mock_job, "value1") self.assertEqual(result, "Job executed with value1") + + + def test_set_production_env(self): + Prod_API = APIClient( + client_id="prod_client_id", + client_secret="prod_client_secret", + debug=False, + environment="production" + ) + self.assertEqual(Prod_API.environment, "production") + + def test_set_bad_env(self): + with self.assertRaises(ValueError): + APIClient( + client_id="test_client_id", + client_secret="test_client_secret", + debug=False, + environment="invalid_env" + ) @patch('trustcafeapiwrapper.apiclient.requests.request') def test_make_request(self, mock_request): From c646e7ddbc7bffdf3c47f6d79e079f11a226191f Mon Sep 17 00:00:00 2001 From: simonwt Date: Tue, 7 Apr 2026 22:38:34 +0100 Subject: [PATCH 4/5] More APIclient testing --- src/trustcafeapiwrapper/apiclient.py | 1 - tests/apiclient.py | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/trustcafeapiwrapper/apiclient.py b/src/trustcafeapiwrapper/apiclient.py index 6e31fcb..492e255 100644 --- a/src/trustcafeapiwrapper/apiclient.py +++ b/src/trustcafeapiwrapper/apiclient.py @@ -31,7 +31,6 @@ class APIClient(BaseModel): client_id: SecretStr client_secret: SecretStr - _access_token: str = PrivateAttr(default="") _access_token_timeout: int = PrivateAttr(default=0) diff --git a/tests/apiclient.py b/tests/apiclient.py index e34b38a..fa7ec3a 100644 --- a/tests/apiclient.py +++ b/tests/apiclient.py @@ -65,11 +65,24 @@ class TestAPIClient(unittest.TestCase): debug=False, environment="invalid_env" ) - + + def test_set_environment_method(self): + self.api_client.set_environment("production") + self.assertEqual(self.api_client.environment, "production") + + def test_make_non_supported_request_type(self): + with self.assertRaises(ValueError): + self.api_client.make_request("PATCH", "content", "test") + + def test_make_request_with_bad_endpoint(self): + with self.assertRaises(ValueError): + self.api_client.make_request("GET", "invalid_endpoint", "test") + + @patch('trustcafeapiwrapper.apiclient.requests.request') def test_make_request(self, mock_request): - # This is a placeholder test. In a real test, you'd mock the HTTP request and response. - - response = self.api_client.make_request("GET", "content", "https://api.example.com/test") + # This test should be expanded + # Or the the functions should be broken up more to be more easily testable + response = self.api_client.make_request("GET", "content", "test") # mock_request.assert_called_once() \ No newline at end of file From a42a3b65d9cd567d7fcb129f0039ff8eeec734b0 Mon Sep 17 00:00:00 2001 From: simonwt Date: Tue, 7 Apr 2026 23:37:55 +0100 Subject: [PATCH 5/5] Post update --- src/trustcafeapiwrapper/jobs/post/__init__.py | 3 +- src/trustcafeapiwrapper/jobs/post/update.py | 12 ++++++ .../wrappers/post/__init__.py | 3 +- .../wrappers/post/update_post.py | 37 +++++++++++++++++++ testing.py | 33 +++++++++++++---- tests/utils/get_child_spksk_from_paths.py | 4 +- tests/wrappers/react.py | 10 ++--- tests/wrappers/update_post.py | 30 +++++++++++++++ unittests.py | 1 + 9 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 src/trustcafeapiwrapper/jobs/post/update.py create mode 100644 src/trustcafeapiwrapper/wrappers/post/update_post.py create mode 100644 tests/wrappers/update_post.py diff --git a/src/trustcafeapiwrapper/jobs/post/__init__.py b/src/trustcafeapiwrapper/jobs/post/__init__.py index 6621076..d72a28d 100644 --- a/src/trustcafeapiwrapper/jobs/post/__init__.py +++ b/src/trustcafeapiwrapper/jobs/post/__init__.py @@ -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 \ No newline at end of file diff --git a/src/trustcafeapiwrapper/jobs/post/update.py b/src/trustcafeapiwrapper/jobs/post/update.py new file mode 100644 index 0000000..80f558d --- /dev/null +++ b/src/trustcafeapiwrapper/jobs/post/update.py @@ -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 \ No newline at end of file diff --git a/src/trustcafeapiwrapper/wrappers/post/__init__.py b/src/trustcafeapiwrapper/wrappers/post/__init__.py index 61a7e0b..eafe74e 100644 --- a/src/trustcafeapiwrapper/wrappers/post/__init__.py +++ b/src/trustcafeapiwrapper/wrappers/post/__init__.py @@ -1 +1,2 @@ -from .create_post import create_post \ No newline at end of file +from .create_post import create_post +from .update_post import update_post \ No newline at end of file diff --git a/src/trustcafeapiwrapper/wrappers/post/update_post.py b/src/trustcafeapiwrapper/wrappers/post/update_post.py new file mode 100644 index 0000000..d302aab --- /dev/null +++ b/src/trustcafeapiwrapper/wrappers/post/update_post.py @@ -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 + } \ No newline at end of file diff --git a/testing.py b/testing.py index 5ede80d..ee63098 100644 --- a/testing.py +++ b/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" -))) \ No newline at end of file +# 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="/", +))) diff --git a/tests/utils/get_child_spksk_from_paths.py b/tests/utils/get_child_spksk_from_paths.py index b639c6d..f45526b 100644 --- a/tests/utils/get_child_spksk_from_paths.py +++ b/tests/utils/get_child_spksk_from_paths.py @@ -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" diff --git a/tests/wrappers/react.py b/tests/wrappers/react.py index 52598f3..641a535 100644 --- a/tests/wrappers/react.py +++ b/tests/wrappers/react.py @@ -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") \ No newline at end of file diff --git a/tests/wrappers/update_post.py b/tests/wrappers/update_post.py new file mode 100644 index 0000000..03c0d36 --- /dev/null +++ b/tests/wrappers/update_post.py @@ -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"]) \ No newline at end of file diff --git a/unittests.py b/unittests.py index f787956..d0dc1b9 100644 --- a/unittests.py +++ b/unittests.py @@ -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