Skip to content
46 changes: 3 additions & 43 deletions falcon/testing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from falcon.asgi_spec import ScopeType
from falcon.constants import COMBINED_METHODS
from falcon.constants import MEDIA_JSON
from falcon.errors import CompatibilityError
from falcon.testing import helpers
from falcon.testing.srmock import StartResponseMock
Expand All @@ -38,7 +37,6 @@
from falcon.util import code_to_http_status
from falcon.util import http_cookies
from falcon.util import http_date_to_dt
from falcon.util import to_query_str

warnings.filterwarnings(
'error',
Expand Down Expand Up @@ -593,7 +591,7 @@
cookies=cookies,
)

path, query_string, headers, body, extras = _prepare_sim_args(
path, query_string, headers, body, extras = helpers._prepare_sim_args(

Check warning on line 594 in falcon/testing/client.py

View check run for this annotation

Codecov / codecov/patch

falcon/testing/client.py#L594

Added line #L594 was not covered by tests
path,
query_string,
params,
Expand All @@ -609,7 +607,7 @@
method=method,
scheme=protocol,
path=path,
query_string=(query_string or ''),
query_string=query_string,
headers=headers,
body=body,
file_wrapper=file_wrapper,
Expand Down Expand Up @@ -768,7 +766,7 @@
:py:class:`~.Result`: The result of the request
"""

path, query_string, headers, body, extras = _prepare_sim_args(
path, query_string, headers, body, extras = helpers._prepare_sim_args(

Check warning on line 769 in falcon/testing/client.py

View check run for this annotation

Codecov / codecov/patch

falcon/testing/client.py#L769

Added line #L769 was not covered by tests
path,
query_string,
params,
Expand Down Expand Up @@ -2143,44 +2141,6 @@
await self._task_req


def _prepare_sim_args(
path, query_string, params, params_csv, content_type, headers, body, json, extras
):
if not path.startswith('/'):
raise ValueError("path must start with '/'")

if '?' in path:
if query_string or params:
raise ValueError(
'path may not contain a query string in combination with '
'the query_string or params parameters. Please use only one '
'way of specifying the query string.'
)
path, query_string = path.split('?', 1)
elif query_string and query_string.startswith('?'):
raise ValueError("query_string should not start with '?'")

extras = extras or {}

if query_string is None:
query_string = to_query_str(
params,
comma_delimited_lists=params_csv,
prefix=False,
)

if content_type is not None:
headers = headers or {}
headers['Content-Type'] = content_type

if json is not None:
body = json_module.dumps(json, ensure_ascii=False)
headers = headers or {}
headers['Content-Type'] = MEDIA_JSON

return path, query_string, headers, body, extras


def _is_asgi_app(app):
app_args = inspect.getfullargspec(app).args
num_app_args = len(app_args)
Expand Down
Loading