Skip to content

Commit

Permalink
Non-ASCII ETag tests and doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
greshilov committed Dec 9, 2020
1 parent 74158a9 commit 5f0ca5e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ ETag

Flag indicates that etag is weak (has `W/` prefix).

.. versionadded:: 4.0
.. versionadded:: 3.8

RequestInfo
^^^^^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ and :ref:`aiohttp-web-signals` handlers.
Returns :class:`tuple` of :class:`ETag` or ``None`` if
*If-Match* header is absent.

.. versionadded:: 3.8

.. attribute:: if_none_match

Read-only property that returns :class:`ETag` objects specified
Expand All @@ -334,7 +336,7 @@ and :ref:`aiohttp-web-signals` handlers.
Returns :class:`tuple` of :class:`ETag` or ``None`` if
*If-None-Match* header is absent.

.. versionadded:: 4.0
.. versionadded:: 3.8

.. attribute:: if_range

Expand Down Expand Up @@ -804,6 +806,8 @@ StreamResponse
**Do not** use double quotes ``"`` in the etag value,
they will be added automatically.

.. versionadded:: 3.8

.. comethod:: prepare(request)

:param aiohttp.web.Request request: HTTP request object, that the
Expand Down
4 changes: 4 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ async def invalid_handler_1(request):
ETag(is_weak=False, value="also-valid-tag"),
),
),
pytest.param(
'"ascii", "это точно не ascii", "ascii again"',
(ETag(is_weak=False, value="ascii"),),
),
pytest.param(
"*",
(ETag(is_weak=False, value="*"),),
Expand Down
25 changes: 22 additions & 3 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,31 @@ def test_etag_any() -> None:


@pytest.mark.parametrize(
"invalid", ('"invalid"', ETag(value='"invalid"', is_weak=True))
"invalid_value",
(
'"invalid"',
"повинен бути ascii",
ETag(value='"invalid"', is_weak=True),
ETag(value="bad ©®"),
),
)
def test_etag_invalid_value(invalid) -> None:
def test_etag_invalid_value_set(invalid_value) -> None:
resp = StreamResponse()
with pytest.raises(ValueError):
resp.etag = invalid
resp.etag = invalid_value


@pytest.mark.parametrize(
"header",
(
"forgotten quotes",
'"∀ x ∉ ascii"',
),
)
def test_etag_invalid_value_get(header) -> None:
resp = StreamResponse()
resp.headers["ETag"] = header
assert resp.etag is None


@pytest.mark.parametrize("invalid", (123, ETag(value=123, is_weak=True)))
Expand Down

0 comments on commit 5f0ca5e

Please sign in to comment.