Skip to content

Add unit tests for GitHubClient to improve coverage from 18% to 80%+ #4

@hillairet

Description

@hillairet

🔭 Task Overview

The GitHubClient class in src/ciftt/github/client.py currently has only 18% test coverage, which is significantly below the project's 80% requirement. This low coverage allowed a bug (incorrect imports in update_issue_project_fields) to slip through testing and only be caught in production.

🎯 Objectives

  • Increase test coverage for src/ciftt/github/client.py from 18% to at least 80%
  • Add unit tests that actually test the real GitHubClient methods, not just mocked versions
  • Ensure critical methods like update_issue_project_fields have comprehensive test coverage
  • Catch import errors and other issues that are currently hidden by mocking

🔬 Steps or Implementation Details

  1. Analyze current coverage gaps: Run pytest --cov=src/ciftt/github/client.py --cov-report=term-missing to identify untested lines
  2. Create unit test file: Add tests/test_github_client.py for direct GitHubClient testing
  3. Mock at the right level: Instead of mocking the entire GitHubClient object, mock the underlying requests library or use VCR.py to record/replay HTTP interactions
  4. Test critical methods:
    • update_issue_project_fields() (lines 257-313)
    • _update_project_fields() (lines 315-368)
    • _find_target_project() (lines 387-447)
    • GraphQL query methods
    • Rate limit handling integration
  5. Test error paths: Ensure error handling and edge cases are covered
  6. Verify imports execute: Tests should actually run the code (not mock it) so lazy imports inside methods are tested

📝 Additional context

Root cause of missed bug:

  • The buggy imports (from github.client_utils import ... on lines 278 and 337) were inside methods
  • Integration tests mocked the entire GitHubClient, so these imports never executed
  • The import error only surfaced when running the actual CLI tool

Current test approach:

# Current integration tests (conftest.py)
mock_github_client = Mock()  # Entire client is mocked
mock_github_client.update_issue_project_fields.return_value = ...

Proposed unit test approach:

# Proposed unit tests
@patch('requests.post')  # Mock at HTTP level, not client level
def test_update_issue_project_fields(mock_post):
    client = GitHubClient(token="test-token")  # Real client instance
    result = client.update_issue_project_fields(...)  # Actually runs the code

Coverage report showing the problem:

src/ciftt/github/client.py              190    155    18%   (missing lines: 38-43, 47-53, 59-79, 83-92, ...)

Related issue: The bug fixed in commit fixing incorrect imports in update_issue_project_fields

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