Skip to content

[Sub] Write API Client Unit Tests #15

Description

@switch180

Parent Issue: #4 Zero Test Coverage

Objective

Create comprehensive unit tests for the RiverLinkApiClient class covering connection management, command execution, and error handling.

Test Coverage Areas

Connection Tests

  • test_connect_success - Successful connection
  • test_connect_failure - Connection errors
  • test_disconnect - Clean disconnection
  • test_reconnect_after_failure - Auto-reconnect logic

Command Tests

  • test_send_command_success - Successful command execution
  • test_send_command_processing - PROCESSING status handling
  • test_poll_request - Async operation polling
  • test_command_timeout - Timeout handling

API Method Tests

  • test_async_get_data - Device data retrieval
  • test_async_join_subscription - Video routing
  • test_async_leave_subscription - Disconnect
  • test_async_set_video_mode - Display mode changes

Error Handling Tests

  • test_connection_error - RiverLinkApiClientConnectionError
  • test_communication_error - RiverLinkApiClientCommunicationError
  • test_invalid_response - Malformed JSON handling
  • test_api_error_response - API error responses

Mock Strategy

# Mock asyncio.open_connection
@pytest.fixture
def mock_connection():
    reader = AsyncMock(spec=asyncio.StreamReader)
    writer = AsyncMock(spec=asyncio.StreamWriter)
    return reader, writer

Target Coverage

  • Goal: 90%+ line coverage for api.py
  • Focus: Critical paths and error scenarios

References

Priority

🔴 High - Core functionality

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions