minor error class and type checking fixes

This commit is contained in:
Lex Berezhny 2019-12-14 20:33:25 -05:00
parent 73613d1583
commit c25d72d911
3 changed files with 9 additions and 4 deletions

View file

@ -72,7 +72,7 @@ class AioHttpManager:
async def get_response_body(self): async def get_response_body(self):
response = await asyncio.wait_for(self._make_request(), self.REQUESTS_TIMEOUT) response = await asyncio.wait_for(self._make_request(), self.REQUESTS_TIMEOUT)
if self.content_type not in response.headers.get('Content-Type'): if self.content_type not in response.headers.get('Content-Type'):
raise InvalidExchangeRateResponse(self.url, f'Received response is not of type {self.content_type}') raise InvalidExchangeRateResponseError(self.url, f'Received response is not of type {self.content_type}')
return response.read().decode() return response.read().decode()

View file

@ -1,5 +1,6 @@
import os import os
import json import json
import typing
import logging import logging
from binascii import unhexlify from binascii import unhexlify
from typing import Optional, List from typing import Optional, List
@ -15,13 +16,16 @@ from lbry.wallet.account import Account
from lbry.wallet.ledger import MainNetLedger from lbry.wallet.ledger import MainNetLedger
from lbry.wallet.transaction import Transaction, Output from lbry.wallet.transaction import Transaction, Output
from lbry.wallet.database import WalletDatabase from lbry.wallet.database import WalletDatabase
from lbry.extras.daemon.exchange_rate_manager import ExchangeRateManager
from lbry.conf import Config from lbry.conf import Config
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
if typing.TYPE_CHECKING:
from lbry.extras.daemon.exchange_rate_manager import ExchangeRateManager
class LbryWalletManager(BaseWalletManager): class LbryWalletManager(BaseWalletManager):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -195,7 +199,8 @@ class LbryWalletManager(BaseWalletManager):
return tx return tx
async def create_purchase_transaction( async def create_purchase_transaction(
self, accounts: List[Account], txo: Output, exchange: ExchangeRateManager, override_max_key_fee=False): self, accounts: List[Account], txo: Output, exchange: 'ExchangeRateManager',
override_max_key_fee=False):
fee = txo.claim.stream.fee fee = txo.claim.stream.fee
fee_amount = exchange.to_dewies(fee.currency, fee.amount) fee_amount = exchange.to_dewies(fee.currency, fee.amount)
if not override_max_key_fee and self.config.max_key_fee: if not override_max_key_fee and self.config.max_key_fee:

View file

@ -310,5 +310,5 @@ class TestAioHttpManager(AsyncioTestCase):
manager = exchange_rate_manager.AioHttpManager('some url', 'some params', 'json') manager = exchange_rate_manager.AioHttpManager('some url', 'some params', 'json')
with unittest.mock.patch.object( with unittest.mock.patch.object(
exchange_rate_manager.AioHttpManager, '_make_request', make_request_mock exchange_rate_manager.AioHttpManager, '_make_request', make_request_mock
), self.assertRaises(InvalidExchangeRateResponse): ), self.assertRaises(InvalidExchangeRateResponseError):
await manager.get_response_body() await manager.get_response_body()