feat(testing): Laravel-style fluent JSON assertions#126
Merged
Conversation
Add AssertableJson and TestResponse to fastapi.testing, giving HTTP tests a chainable, scope-aware assertion API modeled on Laravel's Illuminate\Testing\Fluent\AssertableJson. - AssertableJson: where/where_not/where_all/where_type, has/has_all/ has_any/missing/missing_all/count, first/each, etc(), with a strict interaction model (_verify) that fails on un-asserted object keys. Dotted-key paths and callable predicate matchers supported. Phase-2 methods (where_contains/count_between/where_all_type) are stubbed. - TestResponse: thin httpx.Response wrapper adding assert_status/ assert_ok/assert_created/assert_no_content/assert_json, with __getattr__ passthrough so existing tests stay green. - HttpTestCase.get/post/put/patch/delete now return TestResponse. - Unit tests for happy path, predicate matcher, nested scoping, etc(), strict un-asserted-prop failure, and TestResponse helpers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…paths
- assert_json_structure(structure) on TestResponse with '*' wildcard to
apply a nested structure to every element of a list.
- Promote where_all_type from stub to a working method (asserts each
{key: type} pair via where_type).
- Dotted keys now index into lists (e.g. has('teams.0', ...) and
where('teams.0.name', ...)), enabling nested scoping over array items.
- Tests for structure (simple/wildcard/nested/leaf), where_all_type, and
list-index scoping.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Adds a Laravel
AssertableJson-style fluent assertion API for HTTP tests (TASK #107). HTTP test responses are now chainable and scope-aware.What's included
AssertableJson(fastapi/testing/assertable_json.py)where,where_not,where_all,where_type(incl."string|null"unions;boolis notinteger)has,has_all,has_any,missing,missing_all,counthas(key, callback)/has(key, length, callback)nested scopingfirst,each_verify): un-asserted object keys fail unless.etc()is called — catches unexpected/leaked response keyswhere_contains,count_between,where_all_type) stubbed withNotImplementedErrorTestResponse(fastapi/testing/test_response.py): thinhttpx.Responsewrapper addingassert_status,assert_ok,assert_created,assert_no_content,assert_json(incl.exact=).__getattr__passthrough keeps existing tests green.HttpTestCaseget/post/put/patch/deletenow returnTestResponse.Tests
where_type, nested scoping,first/each,etc(), strict un-asserted-prop failure,TestResponsehelpers (40 tests).🤖 Generated with Claude Code