Skip to content

Commit

Permalink
Merge pull request #2 from inyutin/add-tests-on-exceptions-and-context
Browse files Browse the repository at this point in the history
add tests on exceptions and context
  • Loading branch information
inyutin authored Jul 18, 2020
2 parents e507508 + dd58a0a commit 608d321
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,3 @@ retry_exceptions: Optional[Set[Type]] = None, # On which exceptions we should r

### Development
Before creating PR please run mypy: `mypy -m aiohttp_retry`

### ToDo:

- Add more tests
40 changes: 40 additions & 0 deletions tests/test.py → tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from aiohttp import ClientResponseError

from aiohttp_retry import RetryClient
from tests.app import TestApp

Expand All @@ -21,6 +23,24 @@ async def test_hello(aiohttp_client, loop):
await client.close()


async def test_hello_with_context(aiohttp_client, loop):
test_app = TestApp()
app = test_app.get_app()

client = await aiohttp_client(app)

async with RetryClient() as retry_client:
retry_client._client = client
async with retry_client.get('/ping') as response:
text = await response.text()
assert response.status == 200
assert text == 'Ok!'

assert test_app.counter == 1

await client.close()


async def test_internal_error(aiohttp_client, loop):
test_app = TestApp()
app = test_app.get_app()
Expand Down Expand Up @@ -70,3 +90,23 @@ async def test_sometimes_error(aiohttp_client, loop):

await retry_client.close()
await client.close()


async def test_sometimes_error_with_raise_for_status(aiohttp_client, loop):
test_app = TestApp()
app = test_app.get_app()

client = await aiohttp_client(app, raise_for_status=True)
retry_client = RetryClient()
retry_client._client = client

async with retry_client.get('/sometimes_error', retry_attempts=5, retry_exceptions={ClientResponseError}) \
as response:
text = await response.text()
assert response.status == 200
assert text == 'Ok!'

assert test_app.counter == 3

await retry_client.close()
await client.close()

0 comments on commit 608d321

Please sign in to comment.