From 106cfe5633498d13a518e7d1db74a5efabe509fc Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Tue, 18 Jun 2024 07:13:58 +0200 Subject: [PATCH] Fix bytes-related test failures with urllib-3 Replace `io.StringIO()` with `io.BytesIO()` in mocked response body, to fix some of the test failures when running with urllib3-2.2.1. This change is backwards compatible — all tests still pass with urllib3-1.26.18. Partial-Bug: 2069684 Change-Id: Ic9036a997d2e1b7c79baf7edca129c165b96aabb --- Index: python-glanceclient/glanceclient/tests/unit/test_http.py =================================================================== --- python-glanceclient.orig/glanceclient/tests/unit/test_http.py +++ python-glanceclient/glanceclient/tests/unit/test_http.py @@ -341,9 +341,9 @@ class TestClient(testtools.TestCase): self.assertEqual(data, json.loads(self.mock.last_request.body)) def test_http_chunked_response(self): - data = "TEST" + data = b"TEST" path = '/v1/images/' - self.mock.get(self.endpoint + path, body=io.StringIO(data), + self.mock.get(self.endpoint + path, body=io.BytesIO(data), headers={"Content-Type": "application/octet-stream"}) resp, body = self.client.get(path) @@ -457,9 +457,9 @@ class TestClient(testtools.TestCase): def test_log_request_id_once(self): logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG)) - data = "TEST" + data = b"TEST" path = '/v1/images/' - self.mock.get(self.endpoint + path, body=io.StringIO(data), + self.mock.get(self.endpoint + path, body=io.BytesIO(data), headers={"Content-Type": "application/octet-stream", 'x-openstack-request-id': "1234"})