Skip to content

test_empty_dict_body_not_forwarded failure #2362

@frenzymadness

Description

@frenzymadness

Hello.

When running tests during an RPM build in Fedora Linux, we have the following issue:

====================================== FAILURES ======================================
_________________________ test_empty_dict_body_not_forwarded _________________________

mocked_request_method = <MagicMock name='request' id='139828678375616'>

    @patch("requests.Session.request")
    def test_empty_dict_body_not_forwarded(mocked_request_method: Mock):
        # Disable retries for this test.
        session = jira.resilientsession.ResilientSession(max_retries=0)
        # Empty dictionary should not be converted to JSON
        session.get(url="mocked_url", data={})
        kwargs = mocked_request_method.call_args.kwargs
>       assert "data" not in kwargs
E       AssertionError: assert 'data' not in {'timeout': None, 'data': {}, 'allow_redirects': True, 'headers': {'User-Agent': 'python-requests/2.32.4', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json,*/*;q=0.9', 'Connection': 'keep-alive'}, 'verify': True}

tests/test_resilientsession.py:254: AssertionError

I have investigated this function:

def _jira_prepare(self, **original_kwargs) -> dict:
"""Do any pre-processing of our own and return the updated kwargs."""
prepared_kwargs = original_kwargs.copy()
self.headers: CaseInsensitiveDict
request_headers = self.headers.copy()
request_headers.update(original_kwargs.get("headers", {}))
prepared_kwargs["headers"] = request_headers
data = original_kwargs.get("data", None)
if isinstance(data, dict) and data:
# mypy ensures we don't do this,
# but for people subclassing we should preserve old behaviour
prepared_kwargs["data"] = json.dumps(data)
if "verify" not in prepared_kwargs:
prepared_kwargs["verify"] = self.verify
return prepared_kwargs

and when the test runs it, the original_kwargs contains data: {} and there is nothing in this function that should remove it.

Where should the removal happen for an empty data?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions