test(cli): add 13 integration tests for CLI → API contract#21
Open
govindkavaturi-art wants to merge 1 commit intomainfrom
Open
test(cli): add 13 integration tests for CLI → API contract#21govindkavaturi-art wants to merge 1 commit intomainfrom
govindkavaturi-art wants to merge 1 commit intomainfrom
Conversation
Before this, tests/test_cli.py was exclusively help-text and
argument-parsing assertions via Click's CliRunner — zero tests
exercised the HTTP call the CLI makes. A breaking change in
cueapi-core or the httpx client code path could land with full
green CI.
Approach: patch cueapi.cli.CueAPIClient with a MagicMock that
mimics the context-manager protocol, assert on the resulting
.post/.get/.patch.call_args. Preserves full CLI code path
(flag parsing, body/schedule construction, error handling) and
only mocks the network boundary.
Coverage added:
- create: recurring cron → POST /cues body, one-time `--at` →
"once" schedule, --worker omits callback, --payload JSON
parsed into body, --on-failure JSON parsed, invalid --payload
JSON rejected before any HTTP call, HTTP 403 surfaces the
"cueapi upgrade" hint
- list: default params, filters (--status/--limit/--offset)
- pause/resume: PATCH /cues/{id} with correct {"status": "..."}
- update: patches correct path + body, "no fields" errors before
calling the API
Tests: 32/32 pass (was 19/19).
Why inline --api-key instead of monkey-patching credentials:
using the existing --api-key flag is already the supported
"bypass config file" path; tests stay close to how a user or
CI script would run the command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Before this, `tests/test_cli.py` was exclusively help-text and argument-parsing assertions via Click's `CliRunner` — zero tests exercised the HTTP call the CLI makes. A breaking change in cueapi-core or the httpx client code path could land with fully green CI.
Approach
Patch `cueapi.cli.CueAPIClient` with a `MagicMock` that mimics the context-manager protocol, then assert on the resulting `.post` / `.get` / `.patch.call_args`. This preserves the full CLI code path (flag parsing, body construction, error handling) and only mocks the network boundary.
Coverage added (13 tests)
`create`
`list`
`pause` / `resume`
`update`
Verification
```
32 passed in 0.21s
```
Was 19/19 before this PR; now 32/32.
Why inline `--api-key` vs monkey-patching credentials
Using the existing `--api-key` flag is the supported "bypass config file" path — keeps tests close to how a user or CI script would actually run the command.
Test plan