Skip to content

Commit

Permalink
Add test coverage for mutating StaticResource._routes
Browse files Browse the repository at this point in the history
#9911 optimized this to only build the set once, however ``aiohttp-cors``
relies on being able to mutate this at runtime
https://github.com/aio-libs/aiohttp-cors/blob/38c6c17bffc805e46baccd7be1b4fd8c69d95dc3/aiohttp_cors/urldispatcher_router_adapter.py#L187
  • Loading branch information
bdraco committed Nov 19, 2024
1 parent 9916d32 commit d99dfa1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,23 @@ async def test_static_not_match(router: web.UrlDispatcher) -> None:
assert (None, set()) == ret


async def test_add_static_mutate_resources(router: web.UrlDispatcher) -> None:
"""Test mutating resource._routes to add an options method.
aiohttp-cors mutates the resource._routes, this test ensures that this
continues to work.
"""
resource = router.add_static(
"/st", pathlib.Path(aiohttp.__file__).parent, name="static"
)
resource._routes[hdrs.METH_OPTIONS] = resource._routes[hdrs.METH_GET]
mapping, allowed_methods = await resource.resolve(
make_mocked_request("OPTIONS", "/st/path")
)
assert mapping is not None
assert allowed_methods == {hdrs.METH_GET, hdrs.METH_OPTIONS, hdrs.METH_HEAD}


def test_dynamic_with_trailing_slash(router: web.UrlDispatcher) -> None:
handler = make_handler()
router.add_route("GET", "/get/{name}/", handler, name="name")
Expand Down

0 comments on commit d99dfa1

Please sign in to comment.