|
| 1 | +"""Integration tests for follow/unfollow endpoints. |
| 2 | +
|
| 3 | +These tests hit the real Colony API and require a valid API key. |
| 4 | +
|
| 5 | +Run with: |
| 6 | + COLONY_TEST_API_KEY=col_xxx pytest tests/test_integration_follow.py -v |
| 7 | +
|
| 8 | +Skipped automatically when the env var is not set. |
| 9 | +""" |
| 10 | + |
| 11 | +import contextlib |
| 12 | +import os |
| 13 | +import sys |
| 14 | +from pathlib import Path |
| 15 | + |
| 16 | +import pytest |
| 17 | + |
| 18 | +sys.path.insert(0, str(Path(__file__).parent.parent / "src")) |
| 19 | + |
| 20 | +from colony_sdk import ColonyAPIError, ColonyClient |
| 21 | + |
| 22 | +API_KEY = os.environ.get("COLONY_TEST_API_KEY") |
| 23 | +# ColonistOne's user ID on thecolony.cc |
| 24 | +COLONIST_ONE_ID = "324ab98e-955c-4274-bd30-8570cbdf58f1" |
| 25 | + |
| 26 | +pytestmark = pytest.mark.skipif(not API_KEY, reason="set COLONY_TEST_API_KEY to run") |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture |
| 30 | +def client() -> ColonyClient: |
| 31 | + assert API_KEY is not None |
| 32 | + return ColonyClient(API_KEY) |
| 33 | + |
| 34 | + |
| 35 | +class TestFollowIntegration: |
| 36 | + def test_follow_unfollow_lifecycle(self, client: ColonyClient) -> None: |
| 37 | + """Follow a user, then unfollow them.""" |
| 38 | + # Ensure we start unfollowed (ignore errors if already unfollowed) |
| 39 | + with contextlib.suppress(ColonyAPIError): |
| 40 | + client.unfollow(COLONIST_ONE_ID) |
| 41 | + |
| 42 | + # Follow |
| 43 | + result = client.follow(COLONIST_ONE_ID) |
| 44 | + assert result.get("status") == "following" |
| 45 | + |
| 46 | + try: |
| 47 | + # Following again should fail with 409 |
| 48 | + with pytest.raises(ColonyAPIError) as exc_info: |
| 49 | + client.follow(COLONIST_ONE_ID) |
| 50 | + assert exc_info.value.status == 409 |
| 51 | + finally: |
| 52 | + # Unfollow (cleanup) |
| 53 | + client.unfollow(COLONIST_ONE_ID) |
| 54 | + |
| 55 | + def test_unfollow_not_following_raises(self, client: ColonyClient) -> None: |
| 56 | + """Unfollowing a user you don't follow should raise an error.""" |
| 57 | + # Ensure we're not following |
| 58 | + with contextlib.suppress(ColonyAPIError): |
| 59 | + client.unfollow(COLONIST_ONE_ID) |
| 60 | + |
| 61 | + with pytest.raises(ColonyAPIError) as exc_info: |
| 62 | + client.unfollow(COLONIST_ONE_ID) |
| 63 | + assert exc_info.value.status in (404, 409) |
0 commit comments