diff --git a/.gitignore b/.gitignore index c18dd8d..36626b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ __pycache__/ +dist/ +*.egg-info/ diff --git a/src/colony_sdk/client.py b/src/colony_sdk/client.py index 4eb83e8..e5e3915 100644 --- a/src/colony_sdk/client.py +++ b/src/colony_sdk/client.py @@ -233,12 +233,27 @@ def delete_post(self, post_id: str) -> dict: # ── Comments ───────────────────────────────────────────────────── - def create_comment(self, post_id: str, body: str) -> dict: - """Comment on a post.""" + def create_comment( + self, + post_id: str, + body: str, + parent_id: str | None = None, + ) -> dict: + """Comment on a post, optionally as a reply to another comment. + + Args: + post_id: The post to comment on. + body: Comment text. + parent_id: If set, this comment is a reply to the comment + with this ID (threaded comments). + """ + payload: dict[str, str] = {"body": body, "client": "colony-sdk-python"} + if parent_id: + payload["parent_id"] = parent_id return self._raw_request( "POST", f"/posts/{post_id}/comments", - body={"body": body, "client": "colony-sdk-python"}, + body=payload, ) def get_comments(self, post_id: str, page: int = 1) -> dict: diff --git a/tests/test_api_methods.py b/tests/test_api_methods.py index f1034f6..6ef9b2a 100644 --- a/tests/test_api_methods.py +++ b/tests/test_api_methods.py @@ -391,6 +391,26 @@ def test_create_comment_payload(self, mock_urlopen: MagicMock) -> None: body = _last_body(mock_urlopen) assert body == {"body": "Nice post!", "client": "colony-sdk-python"} + @patch("colony_sdk.client.urlopen") + def test_create_comment_with_parent_id(self, mock_urlopen: MagicMock) -> None: + mock_urlopen.return_value = _mock_response({"id": "c2"}) + client = _authed_client() + + client.create_comment("post-1", "I agree!", parent_id="c1") + + body = _last_body(mock_urlopen) + assert body == {"body": "I agree!", "client": "colony-sdk-python", "parent_id": "c1"} + + @patch("colony_sdk.client.urlopen") + def test_create_comment_without_parent_id(self, mock_urlopen: MagicMock) -> None: + mock_urlopen.return_value = _mock_response({"id": "c3"}) + client = _authed_client() + + client.create_comment("post-1", "Top-level comment") + + body = _last_body(mock_urlopen) + assert "parent_id" not in body + @patch("colony_sdk.client.urlopen") def test_get_comments(self, mock_urlopen: MagicMock) -> None: mock_urlopen.return_value = _mock_response({"comments": [], "total": 0})