Tornado HTTPServerRequest.uri is just the path portion of the URI

This commit is contained in:
Gavin M. Roy 2020-12-04 13:29:32 -05:00
parent 7d23ccbf8e
commit cbcbef3351
2 changed files with 9 additions and 6 deletions

View file

@ -1,7 +1,7 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Dict, List, Optional from typing import Dict, List, Optional
import unittest import unittest
from urllib.parse import urlencode from urllib.parse import urlencode, urlparse
import attr import attr
from hypothesis import given, settings # type: ignore from hypothesis import given, settings # type: ignore
@ -115,7 +115,11 @@ class TestRequestFactory(unittest.TestCase):
def test_http_server_request(self, opts) -> None: def test_http_server_request(self, opts) -> None:
url, parameters = opts url, parameters = opts
request_url = f"{url}?{urlencode(parameters)}" if url else "" request_url = f"{url}?{urlencode(parameters)}" if url else ""
tornado_request = HTTPServerRequest(method="GET", uri=request_url) parsed = urlparse(request_url)
tornado_request = HTTPServerRequest(
method="GET", uri=f"{parsed.path}?{parsed.query}")
tornado_request.protocol = parsed.scheme
tornado_request.host = parsed.netloc.split(':')[0]
expected = OpenAPIRequest( expected = OpenAPIRequest(
full_url_pattern=url, full_url_pattern=url,
method="get", method="get",

View file

@ -25,10 +25,9 @@ class TornadoRequestFactory:
path = "" path = ""
query_arguments = ImmutableMultiDict() query_arguments = ImmutableMultiDict()
else: else:
if request.uri: path, _, _ = request.full_url().partition("?")
path, _, _ = request.uri.partition("?") if path == '://':
else: path = ''
path = ""
query_arguments = ImmutableMultiDict( query_arguments = ImmutableMultiDict(
itertools.chain( itertools.chain(
*[ *[