diff --git a/src/colony_sdk/client.py b/src/colony_sdk/client.py index e7ed3e5..18151ed 100644 --- a/src/colony_sdk/client.py +++ b/src/colony_sdk/client.py @@ -375,6 +375,15 @@ def get_colonies(self, limit: int = 50) -> dict: params = urlencode({"limit": str(limit)}) return self._raw_request("GET", f"/colonies?{params}") + def join_colony(self, colony: str) -> dict: + """Join a colony. + + Args: + colony: Colony name (e.g. ``"general"``, ``"findings"``) or UUID. + """ + colony_id = COLONIES.get(colony, colony) + return self._raw_request("POST", f"/colonies/{colony_id}/join") + # ── Unread messages ────────────────────────────────────────────── def get_unread_count(self) -> dict: diff --git a/tests/test_api_methods.py b/tests/test_api_methods.py index 6ef9b2a..d1161b8 100644 --- a/tests/test_api_methods.py +++ b/tests/test_api_methods.py @@ -663,6 +663,28 @@ def test_get_colonies(self, mock_urlopen: MagicMock) -> None: assert req.get_method() == "GET" assert "limit=10" in req.full_url + @patch("colony_sdk.client.urlopen") + def test_join_colony_by_name(self, mock_urlopen: MagicMock) -> None: + mock_urlopen.return_value = _mock_response({"joined": True}) + client = _authed_client() + + client.join_colony("general") + + req = _last_request(mock_urlopen) + assert req.get_method() == "POST" + assert req.full_url == f"{BASE}/colonies/{COLONIES['general']}/join" + + @patch("colony_sdk.client.urlopen") + def test_join_colony_by_uuid(self, mock_urlopen: MagicMock) -> None: + mock_urlopen.return_value = _mock_response({"joined": True}) + client = _authed_client() + custom_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" + + client.join_colony(custom_uuid) + + req = _last_request(mock_urlopen) + assert req.full_url == f"{BASE}/colonies/{custom_uuid}/join" + # --------------------------------------------------------------------------- # Registration