Skip to content
Snippets Groups Projects
Commit b504070c authored by Krzysztof Mochocki's avatar Krzysztof Mochocki
Browse files

Replace RequestError for ErrorInResponseError

parent 41dfb1ec
No related branches found
No related tags found
1 merge request!73Clive integration related fixes
Showing
with 71 additions and 80 deletions
...@@ -6,7 +6,7 @@ from datetime import datetime, timedelta, timezone ...@@ -6,7 +6,7 @@ from datetime import datetime, timedelta, timezone
from typing import TYPE_CHECKING, Final from typing import TYPE_CHECKING, Final
from helpy import ContextAsync, ContextSync from helpy import ContextAsync, ContextSync
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from types import TracebackType from types import TracebackType
...@@ -24,7 +24,7 @@ class DelayGuardBase: ...@@ -24,7 +24,7 @@ class DelayGuardBase:
return self._next_time_unlock is not None and self.__now() < self._next_time_unlock return self._next_time_unlock is not None and self.__now() < self._next_time_unlock
def _handle_exception_impl(self, ex: BaseException, _: TracebackType | None) -> bool: def _handle_exception_impl(self, ex: BaseException, _: TracebackType | None) -> bool:
self._exception_occured = isinstance(ex, RequestError) self._exception_occured = isinstance(ex, ErrorInResponseError)
self._next_time_unlock = self.__now() + self.BEEKEEPER_DELAY_TIME self._next_time_unlock = self.__now() + self.BEEKEEPER_DELAY_TIME
return False return False
......
from __future__ import annotations from __future__ import annotations
from beekeepy.exceptions.base import DetectableError, SchemaDetectableError from beekeepy.exceptions.base import DetectableError, SchemaDetectableError
from helpy.exceptions import RequestError from helpy import exceptions as helpy_errors
class NoWalletWithSuchNameError(DetectableError): class NoWalletWithSuchNameError(DetectableError):
...@@ -18,7 +18,7 @@ class NoWalletWithSuchNameError(DetectableError): ...@@ -18,7 +18,7 @@ class NoWalletWithSuchNameError(DetectableError):
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return ( return (
isinstance(ex, RequestError) isinstance(ex, helpy_errors.ErrorInResponseError)
and "Assert Exception:_new_item->load_wallet_file(): Unable to open file: " in ex.error and "Assert Exception:_new_item->load_wallet_file(): Unable to open file: " in ex.error
and f"{self.wallet_name}.wallet" in ex.error and f"{self.wallet_name}.wallet" in ex.error
) )
...@@ -38,7 +38,7 @@ class WalletWithSuchNameAlreadyExistsError(DetectableError): ...@@ -38,7 +38,7 @@ class WalletWithSuchNameAlreadyExistsError(DetectableError):
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return ( return (
isinstance(ex, RequestError) isinstance(ex, helpy_errors.ErrorInResponseError)
and f"Assert Exception:!bfs::exists(wallet_filename): Wallet with name: '{self.wallet_name}' already exists" and f"Assert Exception:!bfs::exists(wallet_filename): Wallet with name: '{self.wallet_name}' already exists"
in ex.error in ex.error
) )
...@@ -56,7 +56,10 @@ class InvalidPrivateKeyError(DetectableError): ...@@ -56,7 +56,10 @@ class InvalidPrivateKeyError(DetectableError):
super().__init__(f"given private key or keys are invalid: `{wifs}`") super().__init__(f"given private key or keys are invalid: `{wifs}`")
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return isinstance(ex, RequestError) and "Assert Exception:false: Key can't be constructed" in ex.error return (
isinstance(ex, helpy_errors.ErrorInResponseError)
and "Assert Exception:false: Key can't be constructed" in ex.error
)
class NotExistingKeyError(DetectableError): class NotExistingKeyError(DetectableError):
...@@ -73,7 +76,7 @@ class NotExistingKeyError(DetectableError): ...@@ -73,7 +76,7 @@ class NotExistingKeyError(DetectableError):
super().__init__(f"cannot use key that does not exist: `{public_key}`") super().__init__(f"cannot use key that does not exist: `{public_key}`")
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return isinstance(ex, RequestError) and any( return isinstance(ex, helpy_errors.ErrorInResponseError) and any(
error_message in ex.error error_message in ex.error
for error_message in [ for error_message in [
"Assert Exception:false: Key not in wallet", "Assert Exception:false: Key not in wallet",
...@@ -96,7 +99,7 @@ class MissingSTMPrefixError(DetectableError): ...@@ -96,7 +99,7 @@ class MissingSTMPrefixError(DetectableError):
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return ( return (
isinstance(ex, RequestError) isinstance(ex, helpy_errors.ErrorInResponseError)
and ( and (
"Assert Exception:source.substr( 0, prefix.size() ) == prefix: " "Assert Exception:source.substr( 0, prefix.size() ) == prefix: "
"public key requires STM prefix, but was given " "public key requires STM prefix, but was given "
...@@ -118,7 +121,7 @@ class InvalidPublicKeyError(DetectableError): ...@@ -118,7 +121,7 @@ class InvalidPublicKeyError(DetectableError):
super().__init__(f"Given public key or keys are invalid: `{public_keys}`") super().__init__(f"Given public key or keys are invalid: `{public_keys}`")
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return isinstance(ex, RequestError) and "Assert Exception:s == sizeof(data):" in ex.error return isinstance(ex, helpy_errors.ErrorInResponseError) and "Assert Exception:s == sizeof(data):" in ex.error
class InvalidWalletError(DetectableError): class InvalidWalletError(DetectableError):
...@@ -136,7 +139,7 @@ class InvalidWalletError(DetectableError): ...@@ -136,7 +139,7 @@ class InvalidWalletError(DetectableError):
) )
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return isinstance(ex, RequestError) and any( return isinstance(ex, helpy_errors.ErrorInResponseError) and any(
error_message in ex.error error_message in ex.error
for error_message in [ for error_message in [
"Name of wallet is incorrect. Is empty." "Name of wallet is incorrect. Is empty."
...@@ -160,7 +163,7 @@ class InvalidPasswordError(DetectableError): ...@@ -160,7 +163,7 @@ class InvalidPasswordError(DetectableError):
def _is_exception_handled(self, ex: BaseException) -> bool: def _is_exception_handled(self, ex: BaseException) -> bool:
return ( return (
isinstance(ex, RequestError) isinstance(ex, helpy_errors.ErrorInResponseError)
and "Assert Exception:false: Invalid password for wallet:" in ex.error and "Assert Exception:false: Invalid password for wallet:" in ex.error
and f"{self.wallet_name}.walletrethrow" in ex.error and f"{self.wallet_name}.walletrethrow" in ex.error
) )
......
...@@ -51,34 +51,6 @@ class BlockWaitTimeoutError(HelpyError): ...@@ -51,34 +51,6 @@ class BlockWaitTimeoutError(HelpyError):
) )
class RequestError(HelpyError):
"""Raised if error field is in the response."""
def __init__(self, send: str, error: str | JsonT) -> None:
"""
Initialize a RequestError.
Parameters:
- send (str): The request sent.
- error (str | JsonT): The error received in response.
Returns:
None
"""
self.send = send
self.error = self.__try_extract_exception_message(error)
super().__init__(f"{send=} | {self.error=}")
def __try_extract_exception_message(self, error: str | JsonT) -> str | JsonT:
try:
parsed_error = json.loads(error) if isinstance(error, str) else error
if not isinstance(error, dict):
return error
return parsed_error.get("message", error) # type: ignore[no-any-return]
except json.JSONDecodeError:
return error
class BatchRequestError(HelpyError): class BatchRequestError(HelpyError):
"""Base class for batch related errors.""" """Base class for batch related errors."""
...@@ -289,9 +261,9 @@ class ErrorInResponseError(OverseerError): ...@@ -289,9 +261,9 @@ class ErrorInResponseError(OverseerError):
request_id: int | None, request_id: int | None,
) -> None: ) -> None:
super().__init__( super().__init__(
url, url=url,
request, request=request,
response, response=response,
message=message, message=message,
request_id=request_id, request_id=request_id,
whole_response=whole_response, whole_response=whole_response,
...@@ -301,6 +273,23 @@ class ErrorInResponseError(OverseerError): ...@@ -301,6 +273,23 @@ class ErrorInResponseError(OverseerError):
def retry(self) -> bool: def retry(self) -> bool:
return False return False
@property
def error(self) -> str:
if self.__error is None:
result = self._extract_error_messages(response=self.__get_suitable_response())
self.__error = (result or [""])[0]
return self.__error
def __get_suitable_response(self) -> Json | str | None:
if isinstance(self.response, list):
if self.request_id is None:
return None
for item in self.response:
if item.get("id", {}) == self.request_id:
return item
return None
return self.response
class GroupedErrorsError(HelpyError): class GroupedErrorsError(HelpyError):
def __init__(self, exceptions: Sequence[Exception]) -> None: def __init__(self, exceptions: Sequence[Exception]) -> None:
......
...@@ -6,7 +6,7 @@ import pytest ...@@ -6,7 +6,7 @@ import pytest
from local_tools.beekeepy.generators import generate_wallet_name, generate_wallet_password from local_tools.beekeepy.generators import generate_wallet_name, generate_wallet_password
from local_tools.beekeepy.models import WalletInfo from local_tools.beekeepy.models import WalletInfo
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from beekeepy._handle import Beekeeper from beekeepy._handle import Beekeeper
...@@ -35,7 +35,7 @@ def test_api_close_import_key_to_closed_wallet( ...@@ -35,7 +35,7 @@ def test_api_close_import_key_to_closed_wallet(
beekeeper.api.close(wallet_name=wallet.name) beekeeper.api.close(wallet_name=wallet.name)
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(RequestError, match=f"Wallet not found: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet not found: {wallet.name}"):
beekeeper.api.import_key(wif_key=keys_to_import[0].private_key, wallet_name=wallet.name) beekeeper.api.import_key(wif_key=keys_to_import[0].private_key, wallet_name=wallet.name)
...@@ -50,7 +50,7 @@ def test_api_close_double_close( ...@@ -50,7 +50,7 @@ def test_api_close_double_close(
beekeeper.api.close(wallet_name=wallet.name) beekeeper.api.close(wallet_name=wallet.name)
# ASSERT # ASSERT
with pytest.raises(RequestError, match=f"Wallet not found: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet not found: {wallet.name}"):
beekeeper.api.close(wallet_name=wallet.name) beekeeper.api.close(wallet_name=wallet.name)
...@@ -60,5 +60,5 @@ def test_api_close_not_existing_wallet(beekeeper: Beekeeper) -> None: ...@@ -60,5 +60,5 @@ def test_api_close_not_existing_wallet(beekeeper: Beekeeper) -> None:
wallet = WalletInfo(password=generate_wallet_password(), name=generate_wallet_name()) wallet = WalletInfo(password=generate_wallet_password(), name=generate_wallet_name())
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(RequestError, match=f"Wallet not found: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet not found: {wallet.name}"):
beekeeper.api.close(wallet_name=wallet.name) beekeeper.api.close(wallet_name=wallet.name)
...@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Final ...@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Final
import pytest import pytest
from local_tools.beekeepy import checkers, waiters from local_tools.beekeepy import checkers, waiters
from helpy.exceptions import CommunicationError, RequestError from helpy.exceptions import CommunicationError, ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from beekeepy._handle import Beekeeper from beekeepy._handle import Beekeeper
...@@ -24,7 +24,7 @@ def test_api_close_session(beekeeper: Beekeeper) -> None: ...@@ -24,7 +24,7 @@ def test_api_close_session(beekeeper: Beekeeper) -> None:
f'"params":{{"token":"{beekeeper.session.token}"}}' f'"params":{{"token":"{beekeeper.session.token}"}}'
) )
with pytest.raises( with pytest.raises(
RequestError, ErrorInResponseError,
match=f"A session attached to {beekeeper.session.token} doesn't exist", match=f"A session attached to {beekeeper.session.token} doesn't exist",
): ):
beekeeper.api.close_session() beekeeper.api.close_session()
...@@ -58,7 +58,7 @@ def test_api_close_session_double(beekeeper: Beekeeper) -> None: ...@@ -58,7 +58,7 @@ def test_api_close_session_double(beekeeper: Beekeeper) -> None:
# ASSERT # ASSERT
with pytest.raises( with pytest.raises(
RequestError, ErrorInResponseError,
match=f"A session attached to {beekeeper.session.token} doesn't exist", match=f"A session attached to {beekeeper.session.token} doesn't exist",
): ):
beekeeper.api.close_session() beekeeper.api.close_session()
...@@ -77,5 +77,5 @@ def test_api_close_session_not_existing(create_session: bool, beekeeper: Beekeep ...@@ -77,5 +77,5 @@ def test_api_close_session_not_existing(create_session: bool, beekeeper: Beekeep
# ACT & ASSERT # ACT & ASSERT
beekeeper.set_session_token(WRONG_TOKEN) beekeeper.set_session_token(WRONG_TOKEN)
with pytest.raises(RequestError, match=f"A session attached to {WRONG_TOKEN} doesn't exist"): with pytest.raises(ErrorInResponseError, match=f"A session attached to {WRONG_TOKEN} doesn't exist"):
beekeeper.api.close_session() beekeeper.api.close_session()
...@@ -6,7 +6,7 @@ import pytest ...@@ -6,7 +6,7 @@ import pytest
from local_tools.beekeepy.generators import generate_wallet_name, generate_wallet_password from local_tools.beekeepy.generators import generate_wallet_name, generate_wallet_password
from local_tools.beekeepy.models import WalletInfo from local_tools.beekeepy.models import WalletInfo
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from beekeepy._handle import Beekeeper from beekeepy._handle import Beekeeper
...@@ -42,7 +42,7 @@ def test_api_create_double_same_wallet(beekeeper: Beekeeper) -> None: ...@@ -42,7 +42,7 @@ def test_api_create_double_same_wallet(beekeeper: Beekeeper) -> None:
# ACT & ASSERT # ACT & ASSERT
beekeeper.api.create(wallet_name=wallet.name, password=wallet.password) beekeeper.api.create(wallet_name=wallet.name, password=wallet.password)
with pytest.raises(RequestError, match=f"Wallet with name: '{wallet.name}' already exists"): with pytest.raises(ErrorInResponseError, match=f"Wallet with name: '{wallet.name}' already exists"):
beekeeper.api.create(wallet_name=wallet.name, password=wallet.password) beekeeper.api.create(wallet_name=wallet.name, password=wallet.password)
# ASSERT # ASSERT
...@@ -80,7 +80,7 @@ def test_api_create_correct_wallet_name(beekeeper: Beekeeper, name: str) -> None ...@@ -80,7 +80,7 @@ def test_api_create_correct_wallet_name(beekeeper: Beekeeper, name: str) -> None
def test_api_create_verify_not_allowed_chars(beekeeper: Beekeeper, name: str) -> None: def test_api_create_verify_not_allowed_chars(beekeeper: Beekeeper, name: str) -> None:
"""Test test_api_create will test beekeeper_api.create will check all not allowed wallet name chars.""" """Test test_api_create will test beekeeper_api.create will check all not allowed wallet name chars."""
# ARRANGE & ACT & ASSERT # ARRANGE & ACT & ASSERT
with pytest.raises(RequestError, match="Name of wallet is incorrect."): with pytest.raises(ErrorInResponseError, match="Name of wallet is incorrect."):
beekeeper.api.create(wallet_name=name) beekeeper.api.create(wallet_name=name)
# ASSERT # ASSERT
...@@ -95,7 +95,7 @@ def test_api_create_verify_not_allowed_chars(beekeeper: Beekeeper, name: str) -> ...@@ -95,7 +95,7 @@ def test_api_create_verify_not_allowed_chars(beekeeper: Beekeeper, name: str) ->
def test_api_create_not_correct_wallet_name(beekeeper: Beekeeper, name: str) -> None: def test_api_create_not_correct_wallet_name(beekeeper: Beekeeper, name: str) -> None:
"""Test test_api_create will test beekeeper_api.create will try to create wallet with wrong name.""" """Test test_api_create will test beekeeper_api.create will try to create wallet with wrong name."""
# ARRANGE & ACT & ASSERT # ARRANGE & ACT & ASSERT
with pytest.raises(RequestError, match="Name of wallet is incorrect."): with pytest.raises(ErrorInResponseError, match="Name of wallet is incorrect."):
beekeeper.api.create(wallet_name=name) beekeeper.api.create(wallet_name=name)
# ASSERT # ASSERT
......
...@@ -6,7 +6,7 @@ import pytest ...@@ -6,7 +6,7 @@ import pytest
from local_tools.beekeepy import checkers from local_tools.beekeepy import checkers
from local_tools.beekeepy.constants import MAX_BEEKEEPER_SESSION_AMOUNT from local_tools.beekeepy.constants import MAX_BEEKEEPER_SESSION_AMOUNT
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from beekeepy._handle import Beekeeper from beekeepy._handle import Beekeeper
...@@ -53,7 +53,7 @@ def test_api_create_session_max_sessions(beekeeper: Beekeeper) -> None: ...@@ -53,7 +53,7 @@ def test_api_create_session_max_sessions(beekeeper: Beekeeper) -> None:
# ASSERT # ASSERT
with pytest.raises( with pytest.raises(
RequestError, ErrorInResponseError,
match=f"Number of concurrent sessions reached a limit ==`{MAX_BEEKEEPER_SESSION_AMOUNT}`", match=f"Number of concurrent sessions reached a limit ==`{MAX_BEEKEEPER_SESSION_AMOUNT}`",
): ):
create_session(beekeeper, salt) create_session(beekeeper, salt)
...@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING ...@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
import pytest import pytest
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT
...@@ -44,7 +44,7 @@ def test_api_get_public_keys_with_different_wallet_name(beekeeper: Beekeeper, wa ...@@ -44,7 +44,7 @@ def test_api_get_public_keys_with_different_wallet_name(beekeeper: Beekeeper, wa
not_existing_wallet_name = "not-existing" not_existing_wallet_name = "not-existing"
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(RequestError, match=f"Wallet {not_existing_wallet_name} is locked"): with pytest.raises(ErrorInResponseError, match=f"Wallet {not_existing_wallet_name} is locked"):
beekeeper.api.get_public_keys(wallet_name=not_existing_wallet_name) beekeeper.api.get_public_keys(wallet_name=not_existing_wallet_name)
...@@ -80,7 +80,7 @@ def test_api_get_public_keys_with_many_wallets(beekeeper: Beekeeper, setup_walle ...@@ -80,7 +80,7 @@ def test_api_get_public_keys_with_many_wallets(beekeeper: Beekeeper, setup_walle
# Lock wallet 1 # Lock wallet 1
beekeeper.api.lock(wallet_name=wallet_1.name) beekeeper.api.lock(wallet_name=wallet_1.name)
# Now all wallet are closed, so that no key should be available # Now all wallet are closed, so that no key should be available
with pytest.raises(RequestError, match="You don't have any unlocked wallet"): with pytest.raises(ErrorInResponseError, match="You don't have any unlocked wallet"):
beekeeper.api.get_public_keys() beekeeper.api.get_public_keys()
...@@ -116,5 +116,5 @@ def test_api_get_public_keys_with_many_wallets_closed(beekeeper: Beekeeper, setu ...@@ -116,5 +116,5 @@ def test_api_get_public_keys_with_many_wallets_closed(beekeeper: Beekeeper, setu
# Close wallet 1, # Close wallet 1,
beekeeper.api.close(wallet_name=wallet_1.name) beekeeper.api.close(wallet_name=wallet_1.name)
# There is no wallet # There is no wallet
with pytest.raises(RequestError, match="You don't have any wallet"): with pytest.raises(ErrorInResponseError, match="You don't have any wallet"):
beekeeper.api.get_public_keys() beekeeper.api.get_public_keys()
...@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING ...@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
import pytest import pytest
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT
...@@ -34,7 +34,7 @@ def test_api_import_key_to_locked( ...@@ -34,7 +34,7 @@ def test_api_import_key_to_locked(
beekeeper.api.lock(wallet_name=wallet.name) beekeeper.api.lock(wallet_name=wallet.name)
# ASSERT # ASSERT
with pytest.raises(RequestError, match=f"Wallet is locked: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet is locked: {wallet.name}"):
beekeeper.api.import_key(wallet_name=wallet.name, wif_key=keys_to_import[0].private_key) beekeeper.api.import_key(wallet_name=wallet.name, wif_key=keys_to_import[0].private_key)
...@@ -46,5 +46,5 @@ def test_api_import_key_to_closed( ...@@ -46,5 +46,5 @@ def test_api_import_key_to_closed(
beekeeper.api.close(wallet_name=wallet.name) beekeeper.api.close(wallet_name=wallet.name)
# ASSERT # ASSERT
with pytest.raises(RequestError, match=f"Wallet not found: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet not found: {wallet.name}"):
beekeeper.api.import_key(wallet_name=wallet.name, wif_key=keys_to_import[0].private_key) beekeeper.api.import_key(wallet_name=wallet.name, wif_key=keys_to_import[0].private_key)
...@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING ...@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
import pytest import pytest
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT
...@@ -36,14 +36,14 @@ def test_api_lock_locked_wallet(beekeeper: Beekeeper, wallet: WalletInfo) -> Non ...@@ -36,14 +36,14 @@ def test_api_lock_locked_wallet(beekeeper: Beekeeper, wallet: WalletInfo) -> Non
beekeeper.api.lock(wallet_name=wallet.name) beekeeper.api.lock(wallet_name=wallet.name)
# ASSERT # ASSERT
with pytest.raises(RequestError, match="Unable to lock a locked wallet"): with pytest.raises(ErrorInResponseError, match="Unable to lock a locked wallet"):
beekeeper.api.lock(wallet_name=wallet.name) beekeeper.api.lock(wallet_name=wallet.name)
def test_api_lock_unknown_wallet(beekeeper: Beekeeper) -> None: def test_api_lock_unknown_wallet(beekeeper: Beekeeper) -> None:
"""Test test_api_lock_unknown_wallet will try to lock unknown wallet.""" """Test test_api_lock_unknown_wallet will try to lock unknown wallet."""
# ARRANGE & ACT & ASSERT # ARRANGE & ACT & ASSERT
with pytest.raises(RequestError, match="Wallet not found"): with pytest.raises(ErrorInResponseError, match="Wallet not found"):
beekeeper.api.lock(wallet_name="name") beekeeper.api.lock(wallet_name="name")
......
...@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING ...@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING
import pytest import pytest
from helpy import AccountCredentials from helpy import AccountCredentials
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
from schemas.fields.basic import PublicKey from schemas.fields.basic import PublicKey
if TYPE_CHECKING: if TYPE_CHECKING:
...@@ -39,7 +39,7 @@ def test_api_remove_key_from_locked(beekeeper: Beekeeper, wallet: WalletInfo, ac ...@@ -39,7 +39,7 @@ def test_api_remove_key_from_locked(beekeeper: Beekeeper, wallet: WalletInfo, ac
beekeeper.api.lock(wallet_name=wallet.name) beekeeper.api.lock(wallet_name=wallet.name)
# ASSERT # ASSERT
with pytest.raises(RequestError, match=f"Wallet is locked: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet is locked: {wallet.name}"):
beekeeper.api.remove_key( beekeeper.api.remove_key(
wallet_name=wallet.name, wallet_name=wallet.name,
public_key=account.public_key, public_key=account.public_key,
...@@ -52,7 +52,7 @@ def test_api_remove_key_from_closed(beekeeper: Beekeeper, wallet: WalletInfo, ac ...@@ -52,7 +52,7 @@ def test_api_remove_key_from_closed(beekeeper: Beekeeper, wallet: WalletInfo, ac
beekeeper.api.close(wallet_name=wallet.name) beekeeper.api.close(wallet_name=wallet.name)
# ASSERT # ASSERT
with pytest.raises(RequestError, match=f"Wallet not found: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet not found: {wallet.name}"):
beekeeper.api.remove_key( beekeeper.api.remove_key(
wallet_name=wallet.name, wallet_name=wallet.name,
public_key=account.public_key, public_key=account.public_key,
......
...@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Final ...@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Final
import pytest import pytest
from local_tools.beekeepy.constants import DIGEST_TO_SIGN from local_tools.beekeepy.constants import DIGEST_TO_SIGN
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.models import WalletInfo from local_tools.beekeepy.models import WalletInfo
...@@ -46,7 +46,7 @@ def test_api_sign_digest_with_different_wallet_name(beekeeper: Beekeeper, wallet ...@@ -46,7 +46,7 @@ def test_api_sign_digest_with_different_wallet_name(beekeeper: Beekeeper, wallet
# ACT & ASSERT # ACT & ASSERT
with pytest.raises( with pytest.raises(
RequestError, ErrorInResponseError,
match=f"Public key {PUBLIC_KEY} not found in {not_existing_wallet_name} wallet", match=f"Public key {PUBLIC_KEY} not found in {not_existing_wallet_name} wallet",
): ):
beekeeper.api.sign_digest( beekeeper.api.sign_digest(
...@@ -73,7 +73,7 @@ def test_api_sign_digest_with_deleted_key(beekeeper: Beekeeper, wallet: WalletIn ...@@ -73,7 +73,7 @@ def test_api_sign_digest_with_deleted_key(beekeeper: Beekeeper, wallet: WalletIn
) )
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(RequestError, match=f"Public key {PUBLIC_KEY} not found in unlocked wallets"): with pytest.raises(ErrorInResponseError, match=f"Public key {PUBLIC_KEY} not found in unlocked wallets"):
beekeeper.api.sign_digest(sig_digest=DIGEST_TO_SIGN, public_key=PUBLIC_KEY) beekeeper.api.sign_digest(sig_digest=DIGEST_TO_SIGN, public_key=PUBLIC_KEY)
...@@ -91,7 +91,7 @@ def test_api_sign_digest_with_closed_wallet(beekeeper: Beekeeper, wallet: Wallet ...@@ -91,7 +91,7 @@ def test_api_sign_digest_with_closed_wallet(beekeeper: Beekeeper, wallet: Wallet
beekeeper.api.close(wallet_name=wallet.name) beekeeper.api.close(wallet_name=wallet.name)
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(RequestError, match=f"Public key {PUBLIC_KEY} not found in unlocked wallets"): with pytest.raises(ErrorInResponseError, match=f"Public key {PUBLIC_KEY} not found in unlocked wallets"):
beekeeper.api.sign_digest(sig_digest=DIGEST_TO_SIGN, public_key=PUBLIC_KEY) beekeeper.api.sign_digest(sig_digest=DIGEST_TO_SIGN, public_key=PUBLIC_KEY)
...@@ -131,5 +131,5 @@ def test_api_sign_digest_with_locked_wallet(beekeeper: Beekeeper, wallet: Wallet ...@@ -131,5 +131,5 @@ def test_api_sign_digest_with_locked_wallet(beekeeper: Beekeeper, wallet: Wallet
beekeeper.api.lock(wallet_name=wallet.name) beekeeper.api.lock(wallet_name=wallet.name)
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(RequestError, match=f"Public key {PUBLIC_KEY} not found in unlocked wallets"): with pytest.raises(ErrorInResponseError, match=f"Public key {PUBLIC_KEY} not found in unlocked wallets"):
beekeeper.api.sign_digest(sig_digest=DIGEST_TO_SIGN, public_key=PUBLIC_KEY) beekeeper.api.sign_digest(sig_digest=DIGEST_TO_SIGN, public_key=PUBLIC_KEY)
...@@ -5,8 +5,7 @@ from typing import TYPE_CHECKING ...@@ -5,8 +5,7 @@ from typing import TYPE_CHECKING
import pytest import pytest
from local_tools.beekeepy.generators import generate_wallet_name, generate_wallet_password from local_tools.beekeepy.generators import generate_wallet_name, generate_wallet_password
from helpy.exceptions import RequestError from helpy.exceptions import InvalidPasswordError, ErrorInResponseError
from helpy.exceptions import InvalidPasswordError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT from local_tools.beekeepy.models import WalletInfo, WalletsGeneratorT
...@@ -37,7 +36,7 @@ def test_api_unlock_already_unclocked_wallet(beekeeper: Beekeeper, wallet: Walle ...@@ -37,7 +36,7 @@ def test_api_unlock_already_unclocked_wallet(beekeeper: Beekeeper, wallet: Walle
assert bk_wallet.unlocked is True, "Wallet should be unlocked." assert bk_wallet.unlocked is True, "Wallet should be unlocked."
# ACT & ASSERT # ACT & ASSERT
with pytest.raises(RequestError, match=f"Wallet is already unlocked: {wallet.name}"): with pytest.raises(ErrorInResponseError, match=f"Wallet is already unlocked: {wallet.name}"):
beekeeper.api.unlock(wallet_name=wallet.name, password=wallet.password) beekeeper.api.unlock(wallet_name=wallet.name, password=wallet.password)
...@@ -58,7 +57,7 @@ def test_api_unlock_created_but_closed_wallet(beekeeper: Beekeeper, wallet: Wall ...@@ -58,7 +57,7 @@ def test_api_unlock_created_but_closed_wallet(beekeeper: Beekeeper, wallet: Wall
def test_api_unlock_unknown_wallet(beekeeper: Beekeeper) -> None: def test_api_unlock_unknown_wallet(beekeeper: Beekeeper) -> None:
"""Test test_api_unlock_unknown_wallet will try to unlock unknown wallet.""" """Test test_api_unlock_unknown_wallet will try to unlock unknown wallet."""
# ARRANGE & ACT & ASSERT # ARRANGE & ACT & ASSERT
with pytest.raises(RequestError, match="Unable to open file"): with pytest.raises(ErrorInResponseError, match="Unable to open file"):
beekeeper.api.unlock(password=generate_wallet_password(99), wallet_name=generate_wallet_name(99)) beekeeper.api.unlock(password=generate_wallet_password(99), wallet_name=generate_wallet_name(99))
......
...@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Final ...@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Final
import pytest import pytest
from helpy.exceptions import RequestError from helpy.exceptions import ErrorInResponseError
if TYPE_CHECKING: if TYPE_CHECKING:
from local_tools.beekeepy.models import WalletInfo from local_tools.beekeepy.models import WalletInfo
...@@ -37,7 +37,7 @@ def test_create_wallet(beekeeper: Beekeeper, wallet_name: str) -> None: ...@@ -37,7 +37,7 @@ def test_create_wallet(beekeeper: Beekeeper, wallet_name: str) -> None:
) )
def test_invalid_wallet_names(beekeeper: Beekeeper, invalid_wallet_name: str) -> None: def test_invalid_wallet_names(beekeeper: Beekeeper, invalid_wallet_name: str) -> None:
# ARRANGE, ACT & ASSERT # ARRANGE, ACT & ASSERT
with pytest.raises(RequestError): with pytest.raises(ErrorInResponseError):
beekeeper.api.create(wallet_name=invalid_wallet_name) beekeeper.api.create(wallet_name=invalid_wallet_name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment