From 835f37e7d451d08ee8d3bfad86d8361b785d2333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Chmela=C5=99?= Date: Tue, 12 Oct 2021 15:14:48 +0200 Subject: [PATCH] fix routing method #188 (#191) --- faust/app/router.py | 2 +- tests/unit/app/test_router.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/faust/app/router.py b/faust/app/router.py index a77c1b0e7..5bf0a7c60 100644 --- a/faust/app/router.py +++ b/faust/app/router.py @@ -70,7 +70,7 @@ async def route_req( if dest_ident == self._urlident(app.conf.canonical_url): raise SameNode() routed_url = request.url.with_host(host).with_port(int(port)) - async with app.http_client.get(routed_url) as response: + async with app.http_client.request(request.method, routed_url) as response: return web.text( await response.text(), content_type=response.content_type, diff --git a/tests/unit/app/test_router.py b/tests/unit/app/test_router.py index fe3da4fee..8175d6a36 100644 --- a/tests/unit/app/test_router.py +++ b/tests/unit/app/test_router.py @@ -84,3 +84,20 @@ async def test_route_req(self, *, router, app, mock_http_client): response = await router.route_req("foo", "k", web, request) assert response is web.text.return_value web.text.assert_called_once_with(b"foobar", content_type=ANY, status=ANY) + + @pytest.mark.asyncio + @pytest.mark.http_session(text=b"foobar") + async def test_route_req_method(self, *, router, app, mock_http_client): + app.conf.canonical_url = URL("http://ge.example.com:8181") + web = Mock(name="web") + request = Mock(name="request") + request_method = "POST" + routed_url = "http://el.example.com" + routed_port = 8181 + request.method = request_method + app.router.key_store = Mock() + app.router.key_store.return_value = URL(f"{routed_url}:{routed_port}") + await router.route_req("foo", "k", web, request) + mock_http_client.request.assert_called_once_with( + request_method, request.url.with_host(routed_url).with_port(routed_port) + )