-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c5fe23
commit 795be1b
Showing
10 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,56 @@ | ||
import pytest | ||
from unittest.mock import Mock | ||
from checkout_sdk.exception import ( | ||
CheckoutException, | ||
CheckoutArgumentException, | ||
CheckoutAuthorizationException, | ||
CheckoutApiException | ||
) | ||
from checkout_sdk.authorization_type import AuthorizationType | ||
|
||
|
||
def test_checkout_exception(): | ||
with pytest.raises(CheckoutException): | ||
raise CheckoutException("Test message") | ||
|
||
|
||
def test_checkout_argument_exception(): | ||
with pytest.raises(CheckoutArgumentException): | ||
raise CheckoutArgumentException("Argument error occurred") | ||
|
||
|
||
def test_checkout_authorization_exception(): | ||
with pytest.raises(CheckoutAuthorizationException): | ||
raise CheckoutAuthorizationException("Authorization error occurred") | ||
|
||
|
||
def test_invalid_authorization(): | ||
auth_type = Mock(spec=AuthorizationType) | ||
auth_type.name = "SECRET_KEY" | ||
with pytest.raises(CheckoutAuthorizationException, match="SECRET_KEY authorization type"): | ||
CheckoutAuthorizationException.invalid_authorization(auth_type) | ||
|
||
|
||
def test_invalid_key(): | ||
key_type = Mock(spec=AuthorizationType) | ||
key_type.name = "PUBLIC_KEY" | ||
with pytest.raises(CheckoutAuthorizationException, match="PUBLIC_KEY is required for this operation"): | ||
CheckoutAuthorizationException.invalid_key(key_type) | ||
|
||
|
||
def test_checkout_api_exception(): | ||
response = Mock() | ||
response.status_code = 400 | ||
response.text = '{"error_type": "request_invalid", "error_codes": ["invalid_field"]}' | ||
response.json.return_value = { | ||
"error_type": "request_invalid", | ||
"error_codes": ["invalid_field"] | ||
} | ||
|
||
with pytest.raises(CheckoutApiException) as exc_info: | ||
raise CheckoutApiException(response) | ||
|
||
exception = exc_info.value | ||
Check warning Code scanning / CodeQL Unreachable code Warning test
This statement is unreachable.
|
||
assert exception.http_metadata.status_code == 400 | ||
assert exception.error_type == "request_invalid" | ||
assert exception.error_details == ["invalid_field"] |
This file contains 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 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 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 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