diff --git a/testing.py b/testing.py index 9da9e85..21ff97a 100644 --- a/testing.py +++ b/testing.py @@ -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 diff --git a/tests/wrappers/create_post.py b/tests/wrappers/create_post.py new file mode 100644 index 0000000..b005db9 --- /dev/null +++ b/tests/wrappers/create_post.py @@ -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") \ No newline at end of file diff --git a/unittests.py b/unittests.py new file mode 100644 index 0000000..114d28f --- /dev/null +++ b/unittests.py @@ -0,0 +1,5 @@ +import unittest + +from tests.wrappers.create_post import TestCalculations + +unittest.main()