Skip to content

Add comprehensive unit tests for all API methods#5

Merged
ColonistOne merged 1 commit intomainfrom
add-unit-tests
Apr 7, 2026
Merged

Add comprehensive unit tests for all API methods#5
ColonistOne merged 1 commit intomainfrom
add-unit-tests

Conversation

@arch-colony
Copy link
Copy Markdown
Collaborator

Summary

  • Adds 45 new unit tests in tests/test_api_methods.py (56 total with existing 11)
  • Mocks urllib.urlopen to verify correct HTTP method, URL, headers, and JSON payload for every public method
  • Zero new dependencies — uses only unittest.mock from the standard library

Coverage

Area Tests
Auth Token fetch on first request, token caching, Bearer header, no-auth requests
Retry 401 re-auth with fresh token, 429 backoff (exponential + Retry-After header), max retry limit
Errors Structured detail, string detail, non-JSON response body, empty response
Posts create (payload + UUID colony fallback), get, list (defaults + all filters), update (full + partial), delete
Comments create (payload + client field), get, get_all (single page, pagination, empty)
Voting Post upvote/downvote, comment vote
Messaging send_message, get_conversation, get_unread_count
Search Query + limit params
Users get_me, get_user, update_profile
Notifications List (defaults + unread_only), count, mark_read
Colonies get_colonies
Registration Success, with capabilities, failure (409), custom base_url

Test plan

  • All 56 tests pass (pytest -v)
  • No new dependencies required

🤖 Generated with Claude Code

45 new tests covering every public method on ColonyClient by mocking
urllib. Tests verify correct HTTP method, URL, headers, and JSON payload
for: auth/token flow, posts CRUD, comments (including pagination),
voting, messaging, search, users, notifications, colonies, and
registration. Also covers retry logic (401 re-auth, 429 backoff) and
error handling (structured detail, string detail, non-JSON bodies).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ColonistOne ColonistOne merged commit 19db6ed into main Apr 7, 2026
6 checks passed
@ColonistOne ColonistOne deleted the add-unit-tests branch April 7, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants