Use oslo_serialization.jsonutils.dump_as_bytes()

In blazar/tests/utils/openstack/test_placement.py, we used
oslo_serialization.jsonutils.dump(), but it is better to use
dump_as_bytes() instead to ensure that the result type is bytes on
Python 2 and Python 3.

This patch updates the file to use dump_as_bytes().

Change-Id: Ie15480ef67d61acdbb88a853433c26fa3eed1988
This commit is contained in:
Tetsuro Nakamura 2019-03-07 04:13:12 +00:00
parent d45a7f741f
commit 4b6190f964
2 changed files with 15 additions and 16 deletions

View File

@ -33,7 +33,6 @@ class FakeResponse(requests.Response):
super(FakeResponse, self).__init__()
self.status_code = status_code
if content:
self._content = content.encode('utf-8')
self.encoding = 'utf-8'
self._content = content
if headers:
self.headers = headers

View File

@ -109,7 +109,7 @@ class TestPlacementClient(tests.TestCase):
}
kss_req.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_json_data))
200, content=jsonutils.dump_as_bytes(mock_json_data))
result = self.client.get_resource_provider(rp_name)
@ -130,7 +130,7 @@ class TestPlacementClient(tests.TestCase):
}
kss_req.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_json_data))
200, content=jsonutils.dump_as_bytes(mock_json_data))
result = self.client.get_resource_provider(rp_name)
@ -159,7 +159,7 @@ class TestPlacementClient(tests.TestCase):
'parent_provider_uuid': parent_uuid}
kss_req.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_json_data))
200, content=jsonutils.dump_as_bytes(mock_json_data))
result = self.client.create_resource_provider(
rp_name, rp_uuid=rp_uuid, parent_uuid=parent_uuid)
@ -221,9 +221,9 @@ class TestPlacementClient(tests.TestCase):
'generation': 0,
'parent_provider_uuid': host_uuid}
mock_call1 = fake_requests.FakeResponse(
200, content=jsonutils.dumps(get_json_mock))
200, content=jsonutils.dump_as_bytes(get_json_mock))
mock_call2 = fake_requests.FakeResponse(
200, content=jsonutils.dumps(post_json_mock))
200, content=jsonutils.dump_as_bytes(post_json_mock))
kss_req.side_effect = [mock_call1, mock_call2]
self.client.create_reservation_provider(host_name)
@ -242,7 +242,7 @@ class TestPlacementClient(tests.TestCase):
host_name = "compute-1"
get_json_mock = {'resource_providers': []}
kss_req.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(get_json_mock))
200, content=jsonutils.dump_as_bytes(get_json_mock))
self.assertRaises(
exceptions.ResourceProviderNotFound,
self.client.create_reservation_provider, host_name)
@ -264,7 +264,7 @@ class TestPlacementClient(tests.TestCase):
]
}
mock_call1 = fake_requests.FakeResponse(
200, content=jsonutils.dumps(get_json_mock))
200, content=jsonutils.dump_as_bytes(get_json_mock))
mock_call2 = fake_requests.FakeResponse(200)
kss_req.side_effect = [mock_call1, mock_call2]
@ -284,7 +284,7 @@ class TestPlacementClient(tests.TestCase):
'resource_providers': []
}
mock_call1 = fake_requests.FakeResponse(
200, content=jsonutils.dumps(get_json_mock))
200, content=jsonutils.dump_as_bytes(get_json_mock))
mock_call2 = fake_requests.FakeResponse(200)
kss_req.side_effect = [mock_call1, mock_call2]
@ -369,7 +369,7 @@ class TestPlacementClient(tests.TestCase):
"resource_provider_generation": curr_gen
}
client_get.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_get_inv_json))
200, content=jsonutils.dump_as_bytes(mock_get_inv_json))
# Build the mock of "updated" inventory for update_inventory()
update_gen = 12
@ -395,7 +395,7 @@ class TestPlacementClient(tests.TestCase):
"resource_provider_generation": update_gen
}
kss_req.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_put_json))
200, content=jsonutils.dump_as_bytes(mock_put_json))
result = self.client.update_reservation_inventory(host_name, 'add', 3)
@ -459,7 +459,7 @@ class TestPlacementClient(tests.TestCase):
"resource_provider_generation": curr_gen
}
client_get.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_get_inv_json))
200, content=jsonutils.dump_as_bytes(mock_get_inv_json))
# Build the mock of "updated" inventory for update_inventory()
update_gen = 12
@ -477,7 +477,7 @@ class TestPlacementClient(tests.TestCase):
"resource_provider_generation": update_gen
}
kss_req.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_put_json))
200, content=jsonutils.dump_as_bytes(mock_put_json))
result = self.client.update_reservation_inventory(
host_name, 'curr', 2, additional=True)
@ -531,7 +531,7 @@ class TestPlacementClient(tests.TestCase):
"resource_provider_generation": curr_gen
}
client_get.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_get_inv_json))
200, content=jsonutils.dump_as_bytes(mock_get_inv_json))
# Build the mock of "updated" inventory for update_inventory()
update_gen = 1
@ -549,7 +549,7 @@ class TestPlacementClient(tests.TestCase):
"resource_provider_generation": update_gen
}
kss_req.return_value = fake_requests.FakeResponse(
200, content=jsonutils.dumps(mock_put_json))
200, content=jsonutils.dump_as_bytes(mock_put_json))
result = self.client.update_reservation_inventory(host_name, 'add', 3)