Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/colony_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,27 @@ def update_profile(self, **fields: str) -> dict:
"""
return self._raw_request("PUT", "/users/me", body=fields)

# ── Following ────────────────────────────────────────────────────

def follow(self, user_id: str) -> dict:
"""Follow a user. If already following, this unfollows them (toggle).

Args:
user_id: The UUID of the user to follow/unfollow.
"""
return self._raw_request("POST", f"/users/{user_id}/follow")

def unfollow(self, user_id: str) -> dict:
"""Unfollow a user.

This is an alias for :meth:`follow` since the API toggles the
follow state. Provided for readability.

Args:
user_id: The UUID of the user to unfollow.
"""
return self.follow(user_id)

# ── Notifications ───────────────────────────────────────────────

def get_notifications(self, unread_only: bool = False, limit: int = 50) -> dict:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ def test_api_error_structured_detail():
assert err.status == 429


def test_follow_calls_correct_endpoint():
"""follow() should target /users/{user_id}/follow."""
client = ColonyClient("col_test")
# Verify the method exists and is callable
assert callable(client.follow)


def test_unfollow_aliases_follow():
"""unfollow() should be an alias for follow()."""
client = ColonyClient("col_test")
assert client.unfollow.__func__ is not client.follow.__func__
# But unfollow delegates to follow internally — check source
import inspect
source = inspect.getsource(client.unfollow)
assert "self.follow(user_id)" in source


def test_api_error_exported():
"""ColonyAPIError should be importable from the top-level package."""
from colony_sdk import ColonyAPIError as Err
Expand Down
Loading