Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2.8.0 #81

Merged
merged 4 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ async def main():
params_list=[
RequestParams(
method='GET',
path='https://ya.ru',
url='https://ya.ru',
),
RequestParams(
method='GET',
path='https://ya.ru',
url='https://ya.ru',
headers={'some_header': 'some_value'},
),
]
Expand Down Expand Up @@ -193,7 +193,7 @@ for more info see [aiohttp doc](https://docs.aiohttp.org/en/stable/client_advanc
@dataclass
class RequestParams:
method: str
path: _RAW_URL_TYPE
url: _RAW_URL_TYPE
trace_request_ctx: Optional[Dict[str, Any]] = None
kwargs: Optional[Dict[str, Any]] = None
```
Expand All @@ -209,7 +209,7 @@ def requests(

You can find an example of usage above or in tests.
But basically `RequestParams` is a structure to define params for `ClientSession.request` func.
`method`, `path`, `headers` `trace_request_ctx` defined outside kwargs, because they are popular.
`method`, `url`, `headers` `trace_request_ctx` defined outside kwargs, because they are popular.

There is also an old way to change URL between retries by specifying ```url``` as list of urls. Example:
```python
Expand Down
11 changes: 6 additions & 5 deletions aiohttp_retry/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def exception(self, msg: str, *args: Any, **kwargs: Any) -> None: pass
@dataclass
class RequestParams:
method: str
path: _RAW_URL_TYPE
url: _RAW_URL_TYPE
headers: Optional[Dict[str, Any]] = None
trace_request_ctx: Optional[Dict[str, Any]] = None
kwargs: Optional[Dict[str, Any]] = None
Expand Down Expand Up @@ -98,8 +98,8 @@ async def _do_request(self) -> ClientResponse:
params = self._params_list[-1]

response: ClientResponse = await self._request_func(
method=params.method,
path=params.path,
params.method,
params.url,
headers=params.headers,
trace_request_ctx={
'current_attempt': current_attempt,
Expand Down Expand Up @@ -351,10 +351,11 @@ def _make_request(
url_list = _url_to_urls(url)
params_list = [RequestParams(
method=method,
path=path,
url=url,
headers=kwargs.pop('headers', {}),
trace_request_ctx=kwargs.pop('trace_request_ctx', None),
kwargs=kwargs,
) for path in url_list]
) for url in url_list]

return self._make_requests(
params_list=params_list,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='aiohttp_retry',
version='2.8.1',
version='2.8.2',
description='Simple retry client for aiohttp',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
26 changes: 19 additions & 7 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,17 @@ async def evaluate_response(response: ClientResponse) -> bool:
assert test_app.counter == 3


async def test_multiply_paths_by_requests(aiohttp_client):
async def test_multiply_urls_by_requests(aiohttp_client):
retry_client, test_app = await get_retry_client_and_test_app_for_test(aiohttp_client)
async with retry_client.requests(
params_list=[
RequestParams(
method='GET',
path='/internal_error',
url='/internal_error',
),
RequestParams(
method='GET',
path='/ping',
url='/ping',
),
]
) as response:
Expand All @@ -398,11 +398,11 @@ async def test_multiply_methods_by_requests(aiohttp_client):
params_list=[
RequestParams(
method='POST',
path='/ping',
url='/ping',
),
RequestParams(
method='GET',
path='/ping',
url='/ping',
),
]
) as response:
Expand All @@ -420,11 +420,11 @@ async def test_change_headers(aiohttp_client):
params_list=[
RequestParams(
method='GET',
path='/check_headers',
url='/check_headers',
),
RequestParams(
method='GET',
path='/check_headers',
url='/check_headers',
headers={'correct_headers': 'True'},
),
]
Expand All @@ -448,3 +448,15 @@ async def test_additional_params(aiohttp_client):
assert text == 'Ok!'

await retry_client.close()


async def test_request_headers(aiohttp_client):
retry_client, test_app = await get_retry_client_and_test_app_for_test(aiohttp_client)
async with retry_client.get(url='/check_headers', headers={'correct_headers': 'True'}) as response:
text = await response.text()
assert response.status == 200
assert text == 'Ok!'

assert test_app.counter == 1

await retry_client.close()