Some unit test cases are broken with requests-mock >= 1.12.0

Bug #2064011 reported by Takashi Kajinami
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Fix Released
Undecided
Unassigned

Bug Description

The following unit tests are failing with similar tracebacks since requests-mock was bumped to 1.12.1 .

 - glanceclient.tests.unit.test_shell.ShellTestRequests.test_download_has_no_stray_output_to_stdout
 - glanceclient.tests.unit.test_shell.ShellTestRequests.test_v2_download_has_no_stray_output_to_stdout
 - glanceclient.tests.unit.test_shell.ShellTestRequests.test_v1_download_has_no_stray_output_to_stdout

```
glanceclient.tests.unit.test_shell.ShellTestRequests.test_download_has_no_stray_output_to_stdout
------------------------------------------------------------------------------------------------

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):
      File "/home/tkajinam/git/openstack/python-glanceclient/glanceclient/tests/unit/test_shell.py", line 912, in test_download_has_no_stray_output_to_stdout
    shell.main(argstr.split())
      File "/home/tkajinam/git/openstack/python-glanceclient/glanceclient/shell.py", line 588, in main
    args.func(client, args)
      File "/home/tkajinam/git/openstack/python-glanceclient/glanceclient/v1/shell.py", line 163, in do_image_download
    body = image.data()
           ^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/glanceclient/v1/images.py", line 55, in data
    return self.manager.data(self, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/glanceclient/v1/images.py", line 146, in data
    resp, body = self.client.get('/v1/images/%s'
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/glanceclient/common/http.py", line 318, in get
    return self._request('GET', url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/glanceclient/common/http.py", line 272, in _request
    resp = self.session.request(method,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests_mock/mocker.py", line 185, in _fake_send
    return _original_send(session, request, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests_mock/adapter.py", line 248, in send
    resp = matcher(request)
           ^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests_mock/adapter.py", line 228, in __call__
    return response_matcher.get_response(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests_mock/response.py", line 268, in get_response
    return create_response(request,
           ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests_mock/response.py", line 205, in create_response
    _extract_cookies(request, response, kwargs.get('cookies'))
      File "/home/tkajinam/git/openstack/python-glanceclient/.tox/py3/lib/python3.11/site-packages/requests_mock/response.py", line 103, in _extract_cookies
    response.cookies.extract_cookies(MockResponse(response.raw.headers),
      File "/usr/lib64/python3.11/http/cookiejar.py", line 1685, in extract_cookies
    for cookie in self.make_cookies(response, request):
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/python3.11/http/cookiejar.py", line 1603, in make_cookies
    rfc2965_hdrs = headers.get_all("Set-Cookie2", [])
                   ^^^^^^^^^^^^^^^
    AttributeError: 'dict' object has no attribute 'get_all'

```

The failure is not reporoduced when requests-mock is pinned to 1.11.0, and I suspect the issue is caused by the following change in requests-mock.

https://github.com/jamielennox/requests-mock/commit/e3bd0d1a92e40fa9cb1d587c59157020a45de620

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-glanceclient (master)
Changed in python-glanceclient:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-glanceclient (master)

Reviewed: https://review.opendev.org/c/openstack/python-glanceclient/+/917275
Committed: https://opendev.org/openstack/python-glanceclient/commit/300b8c8262d8dcdca7a8d753c3fb8a22cae02d40
Submitter: "Zuul (22348)"
Branch: master

commit 300b8c8262d8dcdca7a8d753c3fb8a22cae02d40
Author: Takashi Kajinami <email address hidden>
Date: Sun Apr 28 22:19:24 2024 +0900

    Fix unit tests broken by requests-mock >= 1.12.0

    requests-mock removed the old compatibility code in 1.12.0[1] and now
    usage of a bare dict for response header causes AttributeError.

    [1] https://github.com/jamielennox/requests-mock/commit/e3bd0d1a92e40fa9cb1d587c59157020a45de620

    Closes-Bug: #2064011
    Change-Id: Iee86fa3eae86102112987b8648ada73d37ac58e8

Changed in python-glanceclient:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-glanceclient 4.6.0

This issue was fixed in the openstack/python-glanceclient 4.6.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.