Tested and fixed trust createorupdate
This commit is contained in:
parent
255d6ef37b
commit
766ff5b69d
11 changed files with 100 additions and 4 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
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
|
||||
21
src/trustcafeapiwrapper/utils/get_user_slug_from_path.py
Normal file
21
src/trustcafeapiwrapper/utils/get_user_slug_from_path.py
Normal file
|
|
@ -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
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
def get_userprofile_pksk_from_slug(slug: str):
|
||||
pksk = "userprofile#" + slug
|
||||
return {
|
||||
"pk": pksk,
|
||||
"sk": pksk
|
||||
}
|
||||
1
src/trustcafeapiwrapper/wrappers/trust/__init__.py
Normal file
1
src/trustcafeapiwrapper/wrappers/trust/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .trust import trust
|
||||
22
src/trustcafeapiwrapper/wrappers/trust/trust.py
Normal file
22
src/trustcafeapiwrapper/wrappers/trust/trust.py
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
10
testing.py
10
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)
|
||||
# print(users)
|
||||
|
||||
from trustcafeapiwrapper.wrappers.trust import trust
|
||||
save_response(API.wrapped(trust(
|
||||
100,
|
||||
"/user/bossman"
|
||||
)))
|
||||
8
tests/utils/get_user_slug_from_path.py
Normal file
8
tests/utils/get_user_slug_from_path.py
Normal file
|
|
@ -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')
|
||||
11
tests/utils/get_userprofile_pksk_from_slug.py
Normal file
11
tests/utils/get_userprofile_pksk_from_slug.py
Normal file
|
|
@ -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)
|
||||
15
tests/wrappers/trust.py
Normal file
15
tests/wrappers/trust.py
Normal file
|
|
@ -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")
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue