Skip to content

Commit

Permalink
Avoid always passing on an empty body even if not given (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
razziel89 committed Aug 23, 2022
1 parent 37467f1 commit 009ec9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jira/resilientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _jira_prepare(self, **original_kwargs) -> dict:
request_headers.update(original_kwargs.get("headers", {}))
prepared_kwargs["headers"] = request_headers

data = original_kwargs.get("data", {})
data = original_kwargs.get("data", None)
if isinstance(data, dict):
# mypy ensures we don't do this,
# but for people subclassing we should preserve old behaviour
Expand Down
19 changes: 19 additions & 0 deletions tests/test_resilientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ def test_passthrough_class():
# WHEN: the dict of request args are prepared
# THEN: The exact same dict is returned
assert passthrough_class.prepare(my_kwargs) is my_kwargs


@patch("requests.Session.request")
def test_unspecified_body_remains_unspecified(mocked_request_method: Mock):
# Disable retries for this test.
session = jira.resilientsession.ResilientSession(max_retries=0)
# Data is not specified here.
session.get(url="mocked_url")
kwargs = mocked_request_method.call_args.kwargs
assert "data" not in kwargs


@patch("requests.Session.request")
def test_nonempty_body_is_forwarded(mocked_request_method: Mock):
# Disable retries for this test.
session = jira.resilientsession.ResilientSession(max_retries=0)
session.get(url="mocked_url", data={"some": "fake-data"})
kwargs = mocked_request_method.call_args.kwargs
assert kwargs["data"] == '{"some": "fake-data"}'

0 comments on commit 009ec9f

Please sign in to comment.