Skip to content

[Testing]: Unit tests for gcode/setup.py key validation and env loading #59

Description

@shauryagangrade

Problem

setup.py handles first-run key setup, but its validation logic (200 vs 401
vs 403 vs network error) and .env loading are untested — exactly the paths
new users hit first.

Proposed approach

  • Mock requests.get to cover: 200 → valid, 401 → invalid-key message,
    403 → forbidden message, ConnectionError/timeout → network message.
  • Test load_env (reads ~/.gcode/.env when present, no-op otherwise),
    get_api_key precedence, and save_api_key round-trip.

Where to look

  • gcode/setup.py:27-60 (get_api_key, load_env, validate_api_key),
    :80-89 (save_api_key)
  • Pattern: tests/test_models.py mock-based tests.

Acceptance criteria

  • New tests/test_setup.py covering the matrix above; all pass.

Difficulty

Low — good first issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerstestingTests and test infrastructure

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions