-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: enabled multi python version support #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
651ade7
feat: enabled multi python version support
andres-pcg 8fc9ff2
chore(tests): linting tweaks
andres-pcg 85540f3
chore(mypy): add type hint for response data
andres-pcg 6d689fc
chore(lint): use only black linter
andres-pcg e21d0a8
chore(lint): fix missing __init__
andres-pcg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| """Helper functions for e2e tests.""" | ||
|
|
||
| import json | ||
| from typing import Any, Dict, Literal, Optional, Tuple | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def assert_3ds_response( | ||
| result: Dict[str, Any], | ||
| expected_type: Literal[ | ||
| "redirect", "wrapped_approval", "direct_approval", "any" | ||
| ] = "any", | ||
| ) -> Tuple[Optional[str], Optional[Dict[str, Any]]]: | ||
| """ | ||
| Validate and extract data from 3DS response. | ||
|
|
||
| Handles three 3DS response types: | ||
| 1. `redirect: true` - 3DS Method/Challenge required | ||
| 2. `value: {...}` - Wrapped approval response | ||
| 3. Top-level `IsoCode: "00"` - Direct frictionless approval | ||
|
|
||
| Args: | ||
| result: Response dict from secure_sale/secure_token_sale | ||
| expected_type: Expected response type. "any" accepts any valid type. | ||
|
|
||
| Returns: | ||
| Tuple of (secure_id, response_data): | ||
| - secure_id: The secure_id if redirect is required, None otherwise | ||
| - response_data: The actual response dict (from value field or top-level) | ||
|
|
||
| Raises: | ||
| pytest.fail: If the response doesn't match expected type or is invalid | ||
| """ | ||
| if not isinstance(result, dict): | ||
| pytest.fail(f"Expected dict response, got: {type(result)}") | ||
|
|
||
| # Case 1: Redirect required (3DS Method/Challenge) | ||
| if result.get("redirect") and result.get("html") and result.get("id"): | ||
| secure_id = result["id"] | ||
| if expected_type not in ("redirect", "any"): | ||
| response_dump = ( | ||
| json.dumps(result, indent=2) | ||
| if isinstance(result, dict) | ||
| else str(result) | ||
| ) | ||
| pytest.fail( | ||
| f"Expected {expected_type}, but got redirect response. " | ||
| f"Response: {response_dump}" | ||
| ) | ||
| return secure_id, None | ||
|
|
||
| # Case 2: Wrapped approval response (value field) | ||
| if result.get("value") and isinstance(result["value"], dict): | ||
| response = result["value"] | ||
| if response.get("IsoCode") == "00": | ||
| if expected_type not in ("wrapped_approval", "direct_approval", "any"): | ||
| response_dump = json.dumps(result, indent=2) | ||
| pytest.fail( | ||
| f"Expected {expected_type}, but got wrapped approval. " | ||
| f"Response: {response_dump}" | ||
| ) | ||
| assert ( | ||
| response.get("ResponseMessage") == "APROBADA" | ||
| ), f"Expected APROBADA, got: {response.get('ResponseMessage')}" | ||
| return None, response | ||
| # If value exists but IsoCode is not "00", it might be an error | ||
| # Let the caller handle it | ||
|
|
||
| # Case 3: Direct approval at top level | ||
| if result.get("IsoCode") == "00": | ||
| if expected_type not in ("direct_approval", "any"): | ||
| response_dump = ( | ||
| json.dumps(result, indent=2) | ||
| if isinstance(result, dict) | ||
| else str(result) | ||
| ) | ||
| pytest.fail( | ||
| f"Expected {expected_type}, but got direct approval (top-level). " | ||
| f"Response: {response_dump}" | ||
| ) | ||
| assert ( | ||
| result.get("ResponseMessage") == "APROBADA" | ||
| ), f"Expected APROBADA, got: {result.get('ResponseMessage')}" | ||
| return None, result | ||
|
|
||
| # If we get here, the response doesn't match any expected pattern | ||
| response_dump = ( | ||
| json.dumps(result, indent=2) if isinstance(result, dict) else str(result) | ||
| ) | ||
| pytest.fail( | ||
| f"Unexpected 3DS response format. Expected one of: redirect, " | ||
| f"wrapped_approval, or direct_approval. Got: {response_dump}" | ||
| ) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.