Test the utils

Comment create wrapper
Test comment wrapper
This commit is contained in:
simonwt 2026-04-01 23:00:42 +01:00
parent 010d54bc87
commit fb1953e953
11 changed files with 107 additions and 6 deletions

View file

@ -0,0 +1,15 @@
import unittest
from utils.get_parent_pksk_from_path import get_parent_pksk_from_path
class TestGetParentPkskFromPath(unittest.TestCase):
def test_root_path(self):
self.assertEqual(get_parent_pksk_from_path('/'), 'maintrunk#maintrunk')
def test_userprofile_path(self):
self.assertEqual(get_parent_pksk_from_path('/user/johndoe'), 'userprofile#johndoe')
def test_subwiki_path(self):
self.assertEqual(get_parent_pksk_from_path('/branch/12345'), 'subwiki#12345')
def test_invalid_entity(self):
with self.assertRaises(ValueError):
get_parent_pksk_from_path('/invalid/12345')

View file

@ -0,0 +1,12 @@
import unittest
from utils.get_post_pksk import get_post_pksk
class TestGetPostPksk(unittest.TestCase):
def test_get_post_pksk(self):
parent_pksk = 'userprofile#johndoe'
post_url = '/post/12345'
expected_result = {
"pk": 'userprofile#johndoe',
"sk": 'post#12345'
}
self.assertEqual(get_post_pksk(parent_pksk, post_url), expected_result)

View file

@ -0,0 +1,22 @@
import unittest
from wrappers.comment.create_comment import create_comment
class TestCreateComment(unittest.TestCase):
def setUp(self):
self.comment_text = "This is a test comment created via the create_comment wrapper function."
self.blur_label = None
def test_create_comment(self):
result = create_comment(
post_slug='1774951384-98fe38df',
comment_text=self.comment_text,
parent_path='/',
blur_label=self.blur_label
)
self.assertIsInstance(result, dict)
self.assertIn("job_function", result)
self.assertIn("payload", result)
self.assertEqual(result["job_function"], "comment.create")
self.assertEqual(result["payload"]["commentText"], self.comment_text)
self.assertEqual(result["payload"]["blurLabel"], self.blur_label)
self.assertEqual(result["payload"]["parent"]["pk"], "maintrunk#maintrunk")
self.assertEqual(result["payload"]["parent"]["sk"], "post#1774951384-98fe38df")

View file

@ -1,6 +1,6 @@
import unittest
from wrappers.post.create_post import create_post
class TestCalculations(unittest.TestCase):
class TestCreatePost(unittest.TestCase):
def setUp(self):
self.post_text = "This is a test post created via the create_post wrapper function."