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] e3bd0d1a92

Closes-Bug: #2064011
Change-Id: Iee86fa3eae86102112987b8648ada73d37ac58e8
This commit is contained in:
Takashi Kajinami 2024-04-28 22:19:24 +09:00
parent 769dd2e78d
commit 300b8c8262
1 changed files with 7 additions and 1 deletions

View File

@ -14,6 +14,7 @@
# under the License.
import copy
from email.message import EmailMessage
import io
import json
import testtools
@ -112,7 +113,12 @@ class FakeResponse(object):
self.body = body
self.reason = reason
self.version = version
self.headers = headers
# NOTE(tkajinam): Make the FakeResponse class compatible with
# http.client.HTTPResponse
# https://docs.python.org/3/library/http.client.html
self.headers = EmailMessage()
for header_key in headers:
self.headers[header_key] = headers[header_key]
self.headers['x-openstack-request-id'] = 'req-1234'
self.status_code = status_code
self.raw = RawRequest(headers, body=body, reason=reason,