Skip to content

Commit

Permalink
move additional modules into utils package
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Dec 10, 2019
1 parent 43aa9d5 commit aee7525
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions aries_cloudagent/config/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from prompt_toolkit.formatted_text import HTML

from ..ledger.base import BaseLedger
from ..transport.util import http_fetch, TransportFetchError
from ..utils.http import fetch, FetchError

from .base import ConfigError
from .injection_context import InjectionContext
Expand All @@ -25,8 +25,8 @@ async def fetch_genesis_transactions(genesis_url: str) -> str:
headers["Content-Type"] = "application/json"
LOGGER.info("Fetching genesis transactions from: %s", genesis_url)
try:
return await http_fetch(genesis_url, headers=headers)
except TransportFetchError as e:
return await fetch(genesis_url, headers=headers)
except FetchError as e:
raise ConfigError("Error retrieving ledger genesis transactions") from e


Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Transport utility methods."""
"""HTTP utility methods."""

import asyncio

from aiohttp import BaseConnector, ClientError, ClientResponse, ClientSession

from ..messaging.repeat import RepeatSequence
from ..core.error import BaseError

from .error import TransportError
from .repeat import RepeatSequence


class TransportFetchError(TransportError):
class FetchError(BaseError):
"""Error raised when an HTTP fetch fails."""


async def http_fetch(
async def fetch(
url: str,
*,
headers: dict = None,
Expand Down Expand Up @@ -56,4 +56,4 @@ async def http_fetch(
return await (response.json() if json else response.text())
except (ClientError, asyncio.TimeoutError) as e:
if attempt.final:
raise TransportFetchError("Exceeded maximum fetch attempts") from e
raise FetchError("Exceeded maximum fetch attempts") from e
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from aiohttp import web
from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop

from ..util import http_fetch, TransportFetchError
from ..http import fetch, FetchError


class TestTransportUtils(AioHTTPTestCase):
Expand All @@ -26,19 +26,19 @@ async def succeed_route(self, request):
return ret

@unittest_run_loop
async def test_http_fetch(self):
async def test_fetch(self):
server_addr = f"http://localhost:{self.server.port}"
result = await http_fetch(
result = await fetch(
f"{server_addr}/succeed", session=self.client.session, json=True
)
assert result == [1]
assert self.succeed_calls == 1

@unittest_run_loop
async def test_http_fetch_fail(self):
async def test_fetch_fail(self):
server_addr = f"http://localhost:{self.server.port}"
with self.assertRaises(TransportFetchError):
result = await http_fetch(
with self.assertRaises(FetchError):
result = await fetch(
f"{server_addr}/fail",
max_attempts=2,
interval=0,
Expand Down
File renamed without changes.

0 comments on commit aee7525

Please sign in to comment.