PTHMINT-101: Add dev-only custom base URL support#52
Conversation
Allow passing a custom API base_url for local development while preventing custom URLs in non-dev builds. Client now accepts base_url and resolves it via _resolve_base_url (uses MSP_SDK_BUILD_PROFILE, MSP_SDK_ALLOW_CUSTOM_BASE_URL, MSP_SDK_CUSTOM_BASE_URL); _normalize_base_url validates/normalizes the URL. Sdk forwards base_url to Client. Added unit tests covering default test/live URLs, dev-only custom URL acceptance, env-provided URL, and blocking in release/when flag disabled. README updated with usage and guardrails.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #52 +/- ##
==========================================
+ Coverage 90.81% 90.94% +0.13%
==========================================
Files 147 147
Lines 2579 2607 +28
==========================================
+ Hits 2342 2371 +29
+ Misses 237 236 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a development-only mechanism to override the API base URL (via constructor parameter or env var) while enforcing guardrails to block custom URLs outside a “dev” profile.
Changes:
- Extend
ClientandSdkto acceptbase_urland resolve it with environment-based guardrails. - Add unit tests for default URL selection and dev/release allow/block behavior.
- Update README with guidance for enabling the dev-only override.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/multisafepay/client/client.py |
Implements base URL resolution/normalization with dev-only guardrails. |
src/multisafepay/sdk.py |
Forwards base_url from Sdk to Client. |
tests/multisafepay/unit/client/test_unit_client.py |
Adds unit tests for default URLs and guardrail behavior at the Client level. |
tests/multisafepay/unit/test_unit_sdk.py |
Adds unit tests ensuring Sdk propagates URL behavior/guardrails. |
README.md |
Documents dev-only configuration and usage for custom base URL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reject invalid custom base URLs with query strings, fragments, or malformed hosts. Add unit coverage for invalid URL cases and document environment-variable precedence for custom base URLs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Improve Client._normalize_base_url by rejecting URLs that include path parameters (parsed.params) and standardize the error message to "Invalid base URL.". Update unit tests to expect the new message, add a test ensuring an explicit base_url argument takes precedence over environment settings, and add a test that rejects base URLs containing params.
Allow passing a custom API base_url for local development while preventing custom URLs in non-dev builds. Client now accepts base_url and resolves it via _resolve_base_url (uses MSP_SDK_BUILD_PROFILE, MSP_SDK_ALLOW_CUSTOM_BASE_URL, MSP_SDK_CUSTOM_BASE_URL); _normalize_base_url validates/normalizes the URL. Sdk forwards base_url to Client. Added unit tests covering default test/live URLs, dev-only custom URL acceptance, env-provided URL, and blocking in release/when flag disabled. README updated with usage and guardrails.