test(python/schemas): add unit tests for hooks dataclasses#2196
Closed
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
Closed
test(python/schemas): add unit tests for hooks dataclasses#21960xAxiom wants to merge 1 commit intox402-foundation:mainfrom
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
Conversation
Add 34 unit tests for python/x402/x402/schemas/hooks.py — the largest schemas source file without dedicated unit-test coverage. Covers all hook result and context dataclasses: - AbortResult / RecoveredPayloadResult / RecoveredVerifyResult / RecoveredSettleResult: field storage and equality - VerifyContext / SettleContext: optional payload_bytes / requirements_bytes default to None and accept explicit bytes - VerifyResultContext / SettleResultContext / PaymentCreatedContext: happy path stores the inherited fields plus the new field, and __post_init__ raises ValueError when the new field is missing or explicitly None - VerifyFailureContext / SettleFailureContext / PaymentCreationFailureContext: same pattern for the error field - PaymentCreationContext: payment_required and selected_requirements storage Tests use unittest.mock.MagicMock for forward-referenced payload / requirements / response types so the unit tests stay free of network or pydantic validation. All 34 tests pass; ruff format + check clean; full unit suite (888 tests) passes.
|
@0xAxiom is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
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
Add 34 unit tests for
python/x402/x402/schemas/hooks.py— the largest source file in theschemas/package without dedicated unit-test coverage. Mirrors the same coverage pattern as recent unit-test PRs (tests/unit/mechanisms/...) into a newtests/unit/schemas/directory.The hooks module defines lifecycle dataclasses used by
x402Client,x402ResourceServer, andx402Facilitator. Several context subclasses use__post_init__validation to enforce that an inherited-with-default field (result,error,payment_payload) is always set explicitly. Those validations had no test coverage; this PR pins them.What's covered
AbortResult,RecoveredPayloadResult,RecoveredVerifyResult,RecoveredSettleResult— field storage and equalityVerifyContext,SettleContext— optionalpayload_bytes/requirements_bytesdefault toNoneand accept explicit bytesVerifyResultContext,SettleResultContext,PaymentCreatedContext— happy path stores inherited fields plus the new field, and__post_init__raisesValueErrorwhen the new field is missing or explicitlyNoneVerifyFailureContext,SettleFailureContext,PaymentCreationFailureContext— same pattern for theerrorfieldPaymentCreationContext—payment_requiredandselected_requirementsstorageTests use
unittest.mock.MagicMockfor the forward-referenced payload / requirements / response types, keeping the suite free of network and pydantic-validation overhead.Test plan
uv run pytest tests/unit/schemas/test_hooks.py -v— 34 passeduv run pytest tests/unit— 888 passed (full unit suite)uvx ruff format tests/unit/schemas/— cleanuvx ruff check tests/unit/schemas/— All checks passedNo source-code changes; tests-only. No changelog fragment per
python/CONTRIBUTING.md(towncrier fragments are for user-facing changes).