MPT-20733 add mock API route example#190
Conversation
Add authenticated API routes to the mock app so the account-scoped API router flow can be exercised locally. Keep agreement creation support scoped to the mock MPT API service rather than the SDK service layer.
📝 WalkthroughWalkthroughThis PR introduces agreement operations to a mock API application. New schema contracts define agreement fields; mock services implement CRUD and token operations; API routes expose list, get, create, and sync endpoints; and a background sync workflow fetches and processes agreements with distributed tracing. ChangesAgreement API and Sync Flow
🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mock_app/api/api_routes.py (1)
22-22: ⚡ Quick winReplace
type: ignore[attr-defined]with a typed service cast.This keeps strict typing intact and removes suppression comments in the route handlers.
Proposed refactor
+from typing import cast + +from mock_app.mocks.api_service import ExtMPTAPIService from mock_app.api.schemas import AgreementSchema from mock_app.sync.agreements import SyncAdobeAgreements from mpt_extension_sdk import APIRouter from mpt_extension_sdk.api import APIContext, APIResponse, NotFoundError, PaginatedResult @@ async def handle_get_agreements(ctx: APIContext) -> APIResponse: """Return paginated mock agreements.""" - agreements = await ctx.mpt_api_service.agreements.get_all(batch_size=3) # type: ignore[attr-defined] + mpt_api_service = cast(ExtMPTAPIService, ctx.mpt_api_service) + agreements = await mpt_api_service.agreements.get_all(batch_size=3) result = PaginatedResult.from_pagination(ctx.request.pagination, payload=agreements, total=10) return APIResponse.paginated(result) @@ async def handle_create_agreement(body: AgreementSchema, ctx: APIContext) -> APIResponse: """Create one agreement through the mock service facade.""" - new_agreement = await ctx.mpt_api_service.agreements.create(body) # type: ignore[attr-defined] + mpt_api_service = cast(ExtMPTAPIService, ctx.mpt_api_service) + new_agreement = await mpt_api_service.agreements.create(body) return APIResponse.created(payload=new_agreement)As per coding guidelines, new non-test Python code should type-check cleanly under strict mypy settings.
Also applies to: 30-30
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@mock_app/api/api_routes.py` at line 22, Replace the inline type ignore by casting ctx.mpt_api_service to the concrete typed service (e.g., MPTApiService) before calling agreements.get_all so mypy can verify members; import typing.cast (or the service interface type) and use cast(MPTApiService, ctx.mpt_api_service) (or assign to a typed variable) and then call agreements.get_all(batch_size=3) on that typed object to remove the "# type: ignore[attr-defined]" suppression.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@mock_app/api/api_routes.py`:
- Line 22: Replace the inline type ignore by casting ctx.mpt_api_service to the
concrete typed service (e.g., MPTApiService) before calling agreements.get_all
so mypy can verify members; import typing.cast (or the service interface type)
and use cast(MPTApiService, ctx.mpt_api_service) (or assign to a typed variable)
and then call agreements.get_all(batch_size=3) on that typed object to remove
the "# type: ignore[attr-defined]" suppression.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: ba0bc4b6-e6a2-411c-9a41-dc94a07d86f4
📒 Files selected for processing (6)
mock_app/api/api_routes.pymock_app/api/schemas.pymock_app/app.pymock_app/mocks/api_service.pymock_app/sync/__init__.pymock_app/sync/agreements.py



🤖 AI-generated PR — Please review carefully.
Summary
Testing
make checkmake testCloses MPT-20733
Release Notes
MockAgreementServiceproviding agreement creation, retrieval, and batch listing operationsMockInstallationServiceproviding account token creation for account-scoped API flowsAgreementSchemafor validating agreement request payloadsSyncAdobeAgreementsmock use case demonstrating the sync flow with tracing support