Skip to content

Commit

Permalink
fix routing method #188 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Chmelař committed Oct 12, 2021
1 parent c1a6b0e commit 835f37e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion faust/app/router.py
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/app/test_router.py
Expand Up @@ -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)
)

0 comments on commit 835f37e

Please sign in to comment.