Unit testing weyhay

This commit is contained in:
simonwt 2026-04-01 21:42:11 +01:00
parent c27a89b8f9
commit b47f651323
3 changed files with 45 additions and 0 deletions

View file

@ -11,6 +11,9 @@ if not os.getenv("client_id") or not os.getenv("client_secret"):
raise Exception("Please set client_id and client_secret in your environment variables.")
# Initialize API client with credentials from environment variables
'''
THIS IS THE IMPORTANT BIT
'''
API = APIClient(
client_id=os.getenv("client_id"),
client_secret=os.getenv("client_secret"),
@ -31,10 +34,18 @@ if not API.is_token_valid():
with open("token_data.json", "w") as f:
json.dump(tokendata, f, indent=2)
'''
END IMPORTANT BIT
'''
# This is just to stop bunging up the console with output whilst
# doing these tests below
def save_response(response):
with open("test_output.json", "w") as f:
json.dump(response, f, indent=2)
# print("-----------Get a user profile----------------")
# profile = API.run_job('userprofile.get', "simon-little")
# print(profile)
@ -111,6 +122,7 @@ def save_response(response):
# }))
# save_response(API.run_job('post.listall'))
# save_response(API.run_job('post.listpublic'))
from wrappers.post.create_post import create_post

View file

@ -0,0 +1,28 @@
import unittest
from wrappers.post.create_post import create_post
class TestCalculations(unittest.TestCase):
def setUp(self):
self.post_text = "This is a test post created via the create_post wrapper function."
self.blur_label = None
self.card_url = None
self.collaborative = False
def test_create_post(self):
result = create_post(
post_text=self.post_text,
parent_path='/',
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.create")
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"]["parent"]["pk"], "maintrunk#maintrunk")
self.assertEqual(result["payload"]["parent"]["sk"], "maintrunk#maintrunk")

5
unittests.py Normal file
View file

@ -0,0 +1,5 @@
import unittest
from tests.wrappers.create_post import TestCalculations
unittest.main()