From 0fb4f9912213dbbdeba3a98e562d4c423ff20d24 Mon Sep 17 00:00:00 2001 From: Thiago Paiva Date: Mon, 8 Aug 2016 18:08:01 -0300 Subject: [PATCH] Passing SUPPORTED_ONEVIEW_VERSION as string + transient error fix requests==2.11.0 is now checking header parameters for string or buffer types. We were passing SUPPORTED_ONEVIEW_VERSION as int, but now it's not allowed. This patch str's SUPPORTED_ONEVIEW_VERSION before passing it to requests. This patch also fixes a transient error occuring due to simultaneous access to constants in 'fixtures.py'. Change-Id: I188914c0f1c6a1c8496da59857e99ff03a2b83e6 --- oneview_client/client.py | 2 +- .../tests/functional/test_oneview_client.py | 18 ++++++++++++------ .../tests/unit/test_oneview_client.py | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/oneview_client/client.py b/oneview_client/client.py index 90569d0..97a5408 100644 --- a/oneview_client/client.py +++ b/oneview_client/client.py @@ -149,7 +149,7 @@ class BaseClient(object): headers = { 'content-type': 'application/json', - 'X-Api-Version': SUPPORTED_ONEVIEW_VERSION, + 'X-Api-Version': str(SUPPORTED_ONEVIEW_VERSION), 'Auth': self.session_id } url = '%s%s' % (self.manager_url, uri) diff --git a/oneview_client/tests/functional/test_oneview_client.py b/oneview_client/tests/functional/test_oneview_client.py index b1af2a6..6a4750a 100644 --- a/oneview_client/tests/functional/test_oneview_client.py +++ b/oneview_client/tests/functional/test_oneview_client.py @@ -15,6 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import copy import mock import requests import six.moves.http_client as http_client @@ -140,8 +141,9 @@ class OneViewClientTestCase(unittest.TestCase): ) profile = mock.MagicMock() profile.status_code = http_client.OK + profile_fixture = copy.deepcopy(fixtures.SERVER_PROFILE_JSON) profile.json = mock.MagicMock( - return_value=fixtures.SERVER_PROFILE_JSON + return_value=profile_fixture ) mock_get.side_effect = [hardware, profile] @@ -179,8 +181,9 @@ class OneViewClientTestCase(unittest.TestCase): ) profile = mock.MagicMock() profile.status_code = http_client.OK + profile_fixture = copy.deepcopy(fixtures.SERVER_PROFILE_JSON) profile.json = mock.MagicMock( - return_value=fixtures.SERVER_PROFILE_JSON + return_value=profile_fixture ) mock_get.side_effect = [hardware, profile] @@ -307,8 +310,9 @@ class OneViewClientTestCase(unittest.TestCase): ) profile = mock.MagicMock() profile.status_code = http_client.OK + profile_fixture = copy.deepcopy(fixtures.SERVER_PROFILE_JSON) profile.json = mock.MagicMock( - return_value=fixtures.SERVER_PROFILE_JSON + return_value=profile_fixture ) mock_get.side_effect = [hardware, profile, hardware, profile] oneview_client._wait_for_task_to_complete = mock__wait_for_task @@ -320,7 +324,7 @@ class OneViewClientTestCase(unittest.TestCase): oneview_client.set_boot_device(node_info, 'PXE') mock_put.assert_called_once_with( - self.manager_url + fixtures.SERVER_PROFILE_JSON.get('uri'), + self.manager_url + profile_fixture.get('uri'), data=mock.ANY, headers=mock.ANY, verify=True @@ -347,8 +351,9 @@ class OneViewClientTestCase(unittest.TestCase): ) profile = mock.MagicMock() profile.status_code = http_client.OK + profile_fixture = copy.deepcopy(fixtures.SERVER_PROFILE_JSON) profile.json = mock.MagicMock( - return_value=fixtures.SERVER_PROFILE_JSON + return_value=profile_fixture ) ilo_system = mock.MagicMock() ilo_system.status_code = http_client.OK @@ -651,8 +656,9 @@ class OneViewClientV2TestCase(unittest.TestCase): self.password) response = mock_get.return_value response.status_code = http_client.OK + profile_fixture = copy.deepcopy(fixtures.SERVER_PROFILE_JSON) response.json = mock.MagicMock( - return_value=fixtures.SERVER_PROFILE_JSON + return_value=profile_fixture ) mock_get.return_value = response diff --git a/oneview_client/tests/unit/test_oneview_client.py b/oneview_client/tests/unit/test_oneview_client.py index e61b34d..b879117 100644 --- a/oneview_client/tests/unit/test_oneview_client.py +++ b/oneview_client/tests/unit/test_oneview_client.py @@ -303,8 +303,9 @@ class OneViewClientTestCase(unittest.TestCase): models.ServerHardware.from_json(fixtures.SERVER_HARDWARE_JSON) ) mock_get_server_hardware.return_value = server_hardware + profile = copy.deepcopy(fixtures.SERVER_PROFILE_JSON) mock_get_server_profile.return_value = ( - models.ServerProfile.from_json(fixtures.SERVER_PROFILE_JSON) + models.ServerProfile.from_json(profile) ) expected_profile = copy.deepcopy(fixtures.SERVER_PROFILE_JSON) expected_profile['boot'] = {