# -*- coding: utf-8 -*-
###
# (C) Copyright [2019] Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
import io
import unittest
import mock
from mock import call

from tests.test_utils import mock_builtin
from hpOneView.connection import connection
from hpOneView import exceptions
from hpOneView.resources.resource import (ResourceClient, ResourceHelper, ResourceFileHandlerMixin,
                                          ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin,
                                          ResourceSchemaMixin, Resource,
                                          RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor,
                                          RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED,
                                          transform_list_to_dict, extract_id_from_uri, merge_resources,
                                          merge_default_values, unavailable_method)


class StubResourceFileHandler(ResourceFileHandlerMixin, Resource):
    """Stub class to test resource file operations"""


class StubResourceZeroBody(ResourceZeroBodyMixin, Resource):
    """Stub class to test resoruce zero body methods"""


class StubResourcePatch(ResourcePatchMixin, Resource):
    """Stub class to test resource patch operations"""


class StubResourceUtilization(ResourceUtilizationMixin, Resource):
    """Stub class to test resource utilization methods"""


class StubResourceSchema(ResourceSchemaMixin, Resource):
    """Stub class to test resource schema methods"""


class StubResource(Resource):
    """Stub class to test resource common methods"""
    URI = "/rest/testuri"


class BaseTest(unittest.TestCase):

    URI = "/rest/testuri"
    TYPE_V200 = "typeV200"
    TYPE_V300 = "typeV300"

    DEFAULT_VALUES = {
        "200": {"type": TYPE_V200},
        "300": {"type": TYPE_V300}
    }

    def setUp(self, resource_client=None):
        self.resource_client = resource_client
        self.resource_client.URI = self.URI
        self.resource_client.DEFAULT_VALUES = self.DEFAULT_VALUES
        self.resource_client.data = {"uri": "/rest/testuri"}
        self.resource_client._merge_default_values()
        self.task = {"task": "task", "taskState": "Finished"}
        self.response_body = {"body": "body"}
        self.custom_headers = {"Accept-Language": "en_US"}


class ResourceFileHandlerMixinTest(BaseTest):

    def setUp(self):
        self.connection = connection('127.0.0.1', 300)
        self.resource_client = StubResourceFileHandler(self.connection)
        super(ResourceFileHandlerMixinTest, self).setUp(self.resource_client)

    @mock.patch.object(connection, "post_multipart_with_response_handling")
    def test_upload_should_call_post_multipart(self, mock_post_multipart):
        uri = "/rest/testuri/"
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, mock.Mock()

        self.resource_client.upload(filepath, uri)

        mock_post_multipart.assert_called_once_with(uri, filepath, "SPPgen9snap6.2015_0405.81.iso")

    @mock.patch.object(connection, "post_multipart_with_response_handling")
    def test_upload_should_call_post_multipart_with_resource_uri_when_not_uri_provided(self, mock_post_multipart):
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, mock.Mock()

        self.resource_client.upload(filepath)

        mock_post_multipart.assert_called_once_with("/rest/testuri", mock.ANY, mock.ANY)

    @mock.patch.object(connection, "post_multipart_with_response_handling")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    @mock.patch.object(connection, "get")
    def test_upload_should_wait_for_task_when_response_is_task(self, mock_get, mock_wait4task, mock_post_multipart):
        uri = "/rest/testuri/"
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = self.task, mock.Mock()

        self.resource_client.upload(filepath, uri)

        mock_wait4task.assert_called_once_with(self.task, -1)

    @mock.patch.object(connection, "post_multipart_with_response_handling")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_upload_should_not_wait_for_task_when_response_is_not_task(self, mock_wait4task, mock_post_multipart):
        uri = "/rest/testuri/"
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, mock.Mock()

        self.resource_client.upload(filepath, uri)

        mock_wait4task.not_been_called()

    @mock.patch.object(connection, "post_multipart_with_response_handling")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    @mock.patch.object(connection, "get")
    def test_upload_should_return_associated_resource_when_response_is_task(self, mock_get, mock_wait4task,
                                                                            mock_post_multipart):
        fake_associated_resurce = mock.Mock()
        uri = "/rest/testuri/"
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = self.task, mock.Mock()
        mock_wait4task.return_value = fake_associated_resurce

        result = self.resource_client.upload(filepath, uri)

        self.assertEqual(result, fake_associated_resurce)

    @mock.patch.object(connection, "post_multipart_with_response_handling")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_upload_should_return_resource_when_response_is_not_task(self, mock_wait4task, mock_post_multipart):
        fake_response_body = mock.Mock()
        uri = "/rest/testuri/"
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, fake_response_body

        result = self.resource_client.upload(filepath, uri)

        self.assertEqual(result, fake_response_body)

    @mock.patch.object(connection, "download_to_stream")
    @mock.patch(mock_builtin("open"))
    def test_download_should_call_download_to_stream_with_given_uri(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = "/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315"
        mock_open.return_value = io.StringIO()

        self.resource_client.download(uri, file_path)

        mock_download_to_stream.assert_called_once_with(mock.ANY, uri)

    @mock.patch.object(connection, "download_to_stream")
    @mock.patch(mock_builtin("open"))
    def test_download_should_call_download_to_stream_with_open_file(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = "/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315"
        fake_file = io.StringIO()
        mock_open.return_value = fake_file

        self.resource_client.download(uri, file_path)

        mock_open.assert_called_once_with(file_path, 'wb')
        mock_download_to_stream.assert_called_once_with(fake_file, mock.ANY)

    @mock.patch.object(connection, "download_to_stream")
    @mock.patch(mock_builtin("open"))
    def test_download_should_return_true_when_success(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = "/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315"
        mock_download_to_stream.return_value = True
        mock_open.return_value = io.StringIO()

        result = self.resource_client.download(uri, file_path)

        self.assertTrue(result)

    @mock.patch.object(connection, "download_to_stream")
    @mock.patch(mock_builtin("open"))
    def test_download_should_return_false_when_error(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = "/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315"
        mock_download_to_stream.return_value = False
        mock_open.return_value = io.StringIO()

        result = self.resource_client.download(uri, file_path)

        self.assertFalse(result)


class ResourceZeroBodyMixinTest(BaseTest):

    def setUp(self):
        self.connection = connection('127.0.0.1', 300)
        self.resource_client = StubResourceZeroBody(self.connection)
        super(ResourceZeroBodyMixinTest, self).setUp(self.resource_client)

    @mock.patch.object(connection, "post")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_create_with_zero_body_called_once(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.create_with_zero_body()

        mock_post.assert_called_once_with(
            "/rest/testuri", {}, custom_headers=None)

    @mock.patch.object(connection, "post")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_create_with_zero_body_called_once_without_uri(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.create_with_zero_body(timeout=-1)

        mock_post.assert_called_once_with(
            "/rest/testuri", {}, custom_headers=None)

    @mock.patch.object(connection, "post")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_create_with_zero_body_and_custom_headers(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.create_with_zero_body(custom_headers=self.custom_headers)

        mock_post.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={"Accept-Language": "en_US"})

    @mock.patch.object(connection, "post")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_create_with_zero_body_return_entity(self, mock_wait4task, mock_post):
        response_body = {"resource_name": "name"}

        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = response_body

        new_resource = self.resource_client.create_with_zero_body(timeout=-1)

        self.assertNotEqual(new_resource, self.resource_client)

    @mock.patch.object(connection, "post")
    def test_create_with_zero_body_without_task(self, mock_post):
        mock_post.return_value = None, self.response_body

        new_resource = self.resource_client.create_with_zero_body()

        self.assertNotEqual(new_resource, self.resource_client)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_update_with_zero_body_called_once(self, mock_wait4task, mock_update, mock_ensure_resource):
        mock_update.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.URI = "/rest/enclosures"

        self.resource_client.update_with_zero_body("/rest/enclosures/09USE133E5H4/configuration",
                                                   timeout=-1)

        mock_update.assert_called_once_with(
            "/rest/enclosures/09USE133E5H4/configuration", None, custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_update_with_zero_body_and_custom_headers(self, mock_wait4task, mock_update, mock_ensure_resource):
        mock_update.return_value = self.task, self.task
        mock_wait4task.return_value = self.task

        self.resource_client.update_with_zero_body(uri="/rest/testuri", custom_headers=self.custom_headers)

        mock_update.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={"Accept-Language": "en_US"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_update_with_zero_body_return_entity(self, mock_wait4task, mock_put, mock_ensure_resource):
        response_body = {"resource_name": "name"}
        self.resource_client.URI = "/rest/enclosures"

        mock_put.return_value = self.task, self.task
        mock_wait4task.return_value = response_body

        result = self.resource_client.update_with_zero_body(
            "/rest/enclosures/09USE133E5H4/configuration", timeout=-1)

        self.assertEqual(result, response_body)

    @mock.patch.object(connection, "put")
    def test_update_with_zero_body_without_task(self, mock_put):
        mock_put.return_value = None, self.response_body
        self.resource_client.URI = "/rest/enclosures"
        result = self.resource_client.update_with_zero_body(
            "/rest/enclosures/09USE133E5H4/configuration", timeout=-1)

        self.assertEqual(result, self.response_body)


class ResourcePatchMixinTest(BaseTest):

    def setUp(self):
        self.connection = connection('127.0.0.1', 300)
        self.resource_client = StubResourcePatch(self.connection)
        super(ResourcePatchMixinTest, self).setUp(self.resource_client)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    def test_patch_request_when_id_is_provided_v200(self, mock_patch, mock_ensure_resource):
        uri = "/rest/testuri"
        request_body = [{
            "op": "replace",
            "path": "/name",
            "value": "new_name",
        }]
        mock_patch.return_value = {}, {}
        self.connection._apiVersion = 200

        self.resource_client.patch("replace", "/name", "new_name")

        mock_patch.assert_called_once_with(uri, request_body, custom_headers={})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    def test_patch_request_when_id_is_provided_v300(self, mock_patch, mock_ensure_resource):
        request_body = [{
            "op": "replace",
            "path": "/name",
            "value": "new_name",
        }]
        mock_patch.return_value = {}, {}
        self.resource_client.patch("replace", "/name", "new_name")

        mock_patch.assert_called_once_with(
            "/rest/testuri", request_body, custom_headers={"Content-Type": "application/json-patch+json"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    def test_patch_request_when_uri_is_provided(self, mock_patch, mock_ensure_resource):
        request_body = [{
            "op": "replace",
            "path": "/name",
            "value": "new_name",
        }]
        mock_patch.return_value = {}, {}
        self.resource_client.patch("replace", "/name", "new_name")

        mock_patch.assert_called_once_with(
            "/rest/testuri", request_body, custom_headers={"Content-Type": "application/json-patch+json"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    def test_patch_with_custom_headers_v200(self, mock_patch, mock_ensure_resource):
        mock_patch.return_value = {}, {}
        self.connection._apiVersion = 200

        self.resource_client.patch("operation", "/field", "value",
                                   custom_headers=self.custom_headers)

        mock_patch.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={"Accept-Language": "en_US"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    def test_patch_with_custom_headers_v300(self, mock_patch, mock_ensure_resource):
        mock_patch.return_value = {}, {}
        self.resource_client.patch("operation", "/field", "value",
                                   custom_headers=self.custom_headers)

        mock_patch.assert_called_once_with(mock.ANY,
                                           mock.ANY,
                                           custom_headers={"Accept-Language": "en_US",
                                                           "Content-Type": "application/json-patch+json"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_patch_return_entity(self, mock_wait4task, mock_patch, mock_ensure_resource):
        entity = {"resource_id": "123a53cz"}
        mock_patch.return_value = self.task, self.task
        mock_wait4task.return_value = entity
        self.resource_client.patch("replace", "/name", "new_name")

        self.assertEqual(self.resource_client.data, entity)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    @mock.patch.object(TaskMonitor, "get_completed_task")
    def test_patch_request_custom_headers_with_content_type(self, mock_task, mock_patch, mock_ensure_resource):
        uri = "/rest/testuri"
        dict_info = {"resource_name": "a name"}
        mock_patch.return_value = {}, {}
        headers = {"Content-Type": "application/json",
                   "Extra": "extra"}
        self.connection._apiVersion = 300

        self.resource_client.patch_request(uri, body=dict_info, custom_headers=headers)

        mock_patch.assert_called_once_with(uri, dict_info, custom_headers=headers)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    @mock.patch.object(TaskMonitor, "get_completed_task")
    def test_patch_request_custom_headers(self, mock_task, mock_patch, mock_ensure_resource):
        uri = "/rest/testuri"
        dict_info = {"resource_name": "a name"}
        mock_patch.return_value = {}, {}
        headers = {"Extra": "extra"}
        self.connection._apiVersion = 300

        self.resource_client.patch_request(uri, body=dict_info, custom_headers=headers)

        mock_patch.assert_called_once_with(
            uri,
            dict_info,
            custom_headers={"Extra": "extra",
                            "Content-Type": "application/json-patch+json"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "patch")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_wait_for_activity_on_patch(self, mock_wait4task, mock_patch, mock_ensure_resource):
        entity = {"resource_id": "123a53cz"}
        mock_patch.return_value = self.task, self.task
        mock_wait4task.return_value = entity
        self.resource_client.patch("replace", "/name", "new_name")

        mock_wait4task.assert_called_once_with(self.task, mock.ANY)


class ResourceUtilizationMixinTest(BaseTest):

    def setUp(self):
        self.connection = connection('127.0.0.1', 300)
        self.resource_client = StubResourceUtilization(self.connection)
        super(ResourceUtilizationMixinTest, self).setUp(self.resource_client)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "get")
    def test_get_utilization_with_args(self, mock_get, mock_ensure_resource):
        self.resource_client.get_utilization(fields="AmbientTemperature,AveragePower,PeakPower",
                                             filter="startDate=2016-05-30T03:29:42.361Z",
                                             refresh=True, view="day")

        expected_uri = "/rest/testuri/utilization" \
                       "?filter=startDate%3D2016-05-30T03%3A29%3A42.361Z" \
                       "&fields=AmbientTemperature%2CAveragePower%2CPeakPower" \
                       "&refresh=true" \
                       "&view=day"

        mock_get.assert_called_once_with(expected_uri)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "get")
    def test_get_utilization_with_multiple_filters(self, mock_get, mock_ensure_resource):
        self.resource_client.get_utilization(
            fields="AmbientTemperature,AveragePower,PeakPower",
            filter=["startDate=2016-05-30T03:29:42.361Z",
                    "endDate=2016-05-31T03:29:42.361Z"],
            refresh=True,
            view="day")
        expected_uri = "/rest/testuri/utilization" \
                       "?filter=startDate%3D2016-05-30T03%3A29%3A42.361Z" \
                       "&filter=endDate%3D2016-05-31T03%3A29%3A42.361Z" \
                       "&fields=AmbientTemperature%2CAveragePower%2CPeakPower" \
                       "&refresh=true" \
                       "&view=day"

        mock_get.assert_called_once_with(expected_uri)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "get")
    def test_get_utilization_by_id_with_defaults(self, mock_get, mock_ensure_resource):
        self.resource_client.get_utilization()

        expected_uri = "/rest/testuri/utilization"

        mock_get.assert_called_once_with(expected_uri)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "get")
    def test_get_utilization_by_uri_with_defaults(self, mock_get, mock_ensure_resource):
        self.resource_client.get_utilization()

        expected_uri = "/rest/testuri/utilization"

        mock_get.assert_called_once_with(expected_uri)


class ResourceSchemaMixinTest(BaseTest):

    def setUp(self):
        self.connection = connection('127.0.0.1', 300)
        self.resource_client = StubResourceSchema(self.connection)
        super(ResourceSchemaMixinTest, self).setUp(self.resource_client)

    @mock.patch.object(connection, "get")
    def test_get_schema_uri(self, mock_get):
        self.resource_client.get_schema()
        mock_get.assert_called_once_with(self.URI + "/schema")


class ResourceTest(BaseTest):

    def setUp(self):
        self.connection = connection('127.0.0.1', 300)
        self.resource_client = StubResource(self.connection)
        super(ResourceTest, self).setUp(self.resource_client)
        self.resource_helper = ResourceHelper(self.URI, self.connection, None)

    @mock.patch.object(ResourceHelper, "do_put")
    @mock.patch.object(Resource, "ensure_resource_data")
    def test_ensure_resource_should_call_once(self, mock_do_put, mock_ensure_resource):
        self.resource_client.data = {"uri": "/rest/test"}
        self.resource_client.update(data={"name": "test"})
        mock_do_put.assert_called_once()
        mock_ensure_resource.assert_called_once()

    def test_ensure_resource_raise_unique_identifier_exception(self):
        self.resource_client.data = []
        self.assertRaises(exceptions.HPOneViewMissingUniqueIdentifiers,
                          self.resource_client.ensure_resource_data)

    @mock.patch.object(ResourceHelper, "do_get")
    def test_ensure_resource_raise_resource_not_found_exception_with_uri(self, mock_do_get):
        self.resource_client.data = {"uri": "/uri/test"}
        mock_do_get.return_value = []
        with self.assertRaises(exceptions.HPOneViewResourceNotFound):
            self.resource_client.ensure_resource_data(update_data=True)

    @mock.patch.object(Resource, "get_by")
    def test_ensure_resource_raise_resource_not_found_exception_without_uri(self, mock_get_by):
        self.resource_client.data = {"name": "testname"}
        mock_get_by.return_value = []
        with self.assertRaises(exceptions.HPOneViewResourceNotFound):
            self.resource_client.ensure_resource_data(update_data=True)

    @mock.patch.object(ResourceHelper, "do_get")
    @mock.patch.object(Resource, "get_by")
    def test_ensure_resource_should_update_resource_data(self, mock_do_get, mock_get_by):
        get_by_return_value = [{"name": "testname", "uri": "/rest/testuri"}]
        self.resource_client.data = {"name": "testname"}
        mock_do_get.return_value = get_by_return_value
        self.resource_client.ensure_resource_data(update_data=True)

        self.assertEqual(self.resource_client.data, get_by_return_value[0])

    @mock.patch.object(Resource, "get_by")
    def test_ensure_resource_without_data_update(self, mock_get_by):
        mock_get_by.return_value = []
        actual_result = self.resource_client.ensure_resource_data(update_data=False)
        expected_result = None
        self.assertEqual(actual_result, expected_result)

    @mock.patch.object(connection, "get")
    def test_get_all_called_once(self, mock_get):
        filter = "'name'='OneViewSDK \"Test FC Network'"
        sort = "name:ascending"
        query = "name NE 'WrongName'"

        mock_get.return_value = {"members": [{"member": "member"}]}

        result = self.resource_helper.get_all(
            1, 500, filter, query, sort)

        uri = "{resource_uri}?start=1" \
              "&count=500" \
              "&filter=%27name%27%3D%27OneViewSDK%20%22Test%20FC%20Network%27" \
              "&query=name%20NE%20%27WrongName%27" \
              "&sort=name%3Aascending".format(resource_uri=self.URI)

        self.assertEqual([{"member": "member"}], result)
        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, "get")
    def test_get_all_with_defaults(self, mock_get):
        self.resource_client.get_all()
        uri = "{resource_uri}?start=0&count=-1".format(resource_uri=self.URI)

        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, "get")
    def test_get_all_with_custom_uri(self, mock_get):
        self.resource_helper.get_all(uri="/rest/testuri/12467836/subresources")
        uri = "/rest/testuri/12467836/subresources?start=0&count=-1"

        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, "get")
    def test_get_all_with_custom_uri_and_query_string(self, mock_get):
        self.resource_helper.get_all(uri="/rest/testuri/12467836/subresources?param=value")

        uri = "/rest/testuri/12467836/subresources?param=value&start=0&count=-1"
        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, "get")
    def test_get_all_with_different_resource_uri_should_fail(self, mock_get):
        try:
            self.resource_helper.get_all(uri="/rest/other/resource/12467836/subresources")
        except exceptions.HPOneViewUnknownType as e:
            self.assertEqual(UNRECOGNIZED_URI, e.args[0])
        else:
            self.fail("Expected Exception was not raised")

    @mock.patch.object(connection, "get")
    def test_get_all_should_do_multi_requests_when_response_paginated(self, mock_get):
        uri_list = ["/rest/testuri?start=0&count=-1",
                    "/rest/testuri?start=3&count=3",
                    "/rest/testuri?start=6&count=3"]

        results = [{"nextPageUri": uri_list[1], "members": [{"id": "1"}, {"id": "2"}, {"id": "3"}]},
                   {"nextPageUri": uri_list[2], "members": [{"id": "4"}, {"id": "5"}, {"id": "6"}]},
                   {"nextPageUri": None, "members": [{"id": "7"}, {"id": "8"}]}]

        mock_get.side_effect = results

        self.resource_client.get_all()

        expected_calls = [call(uri_list[0]), call(uri_list[1]), call(uri_list[2])]
        self.assertEqual(mock_get.call_args_list, expected_calls)

    @mock.patch.object(connection, "get")
    def test_get_all_with_count_should_do_multi_requests_when_response_paginated(self, mock_get):
        uri_list = ["/rest/testuri?start=0&count=15",
                    "/rest/testuri?start=3&count=3",
                    "/rest/testuri?start=6&count=3"]

        results = [{"nextPageUri": uri_list[1], "members": [{"id": "1"}, {"id": "2"}, {"id": "3"}]},
                   {"nextPageUri": uri_list[2], "members": [{"id": "4"}, {"id": "5"}, {"id": "6"}]},
                   {'nextPageUri': None, "members": [{"id": "7"}, {"id": "8"}]}]

        mock_get.side_effect = results

        self.resource_client.get_all(count=15)

        expected_calls = [call(uri_list[0]), call(uri_list[1]), call(uri_list[2])]
        self.assertEqual(mock_get.call_args_list, expected_calls)

    @mock.patch.object(connection, "get")
    def test_get_all_should_return_all_items_when_response_paginated(self, mock_get):
        uri_list = ["/rest/testuri?start=0&count=-1",
                    "/rest/testuri?start=3&count=3",
                    "/rest/testuri?start=6&count=1"]

        results = [{"nextPageUri": uri_list[1], "members": [{"id": "1"}, {"id": "2"}, {"id": "3"}]},
                   {"nextPageUri": uri_list[2], "members": [{"id": "4"}, {"id": "5"}, {"id": "6"}]},
                   {"nextPageUri": None, "members": [{"id": "7"}]}]

        mock_get.side_effect = results

        result = self.resource_client.get_all()

        expected_items = [{'id': '1'}, {'id': '2'}, {'id': '3'}, {'id': '4'}, {'id': '5'}, {'id': '6'}, {'id': '7'}]
        self.assertSequenceEqual(result, expected_items)

    @mock.patch.object(connection, 'get')
    def test_get_all_should_limit_results_to_requested_count_when_response_is_paginated(self, mock_get):
        uri_list = ['/rest/testuri?start=0&count=15',
                    '/rest/testuri?start=3&count=3',
                    '/rest/testuri?start=6&count=1']

        results = [{"nextPageUri": uri_list[1], "members": [{"id": "1"}, {"id": "2"}, {"id": "3"}]},
                   {"nextPageUri": uri_list[2], "members": [{"id": "4"}, {"id": "5"}, {"id": "6"}]},
                   {"nextPageUri": None, "members": [{"id": "7"}]}]

        mock_get.side_effect = results

        result = self.resource_client.get_all(count=15)

        expected_items = [{"id": "1"}, {"id": "2"}, {"id": "3"}, {"id": "4"}, {"id": "5"}, {"id": "6"}, {"id": "7"}]
        self.assertSequenceEqual(result, expected_items)

    @mock.patch.object(connection, "get")
    def test_get_all_should_stop_requests_when_requested_count_reached(self, mock_get):
        """
        In this case, the user provides a maximum number of results to be returned but for pagination purposes, a
        nextPageUri is returned by OneView.
        """
        uri_list = ["/rest/testuri?start=0&count=3",
                    "/rest/testuri?start=3&count=3",
                    "/rest/testuri?start=6&count=3"]

        results = [{"nextPageUri": uri_list[1], "members": [{"id": "1"}, {"id": "2"}, {"id": "3"}]},
                   {"nextPageUri": uri_list[2], "members": [{"id": "4"}, {"id": "5"}, {"id": "6"}]},
                   {"nextPageUri": None, "members": [{"id": "7"}, {"id": "8"}]}]

        mock_get.side_effect = results

        self.resource_client.get_all(count=3)

        mock_get.assert_called_once_with(uri_list[0])

    @mock.patch.object(connection, "get")
    def test_get_all_should_stop_requests_when_next_page_is_equal_to_current_page(self, mock_get):
        uri = "/rest/testuri?start=0&count=-1"
        members = [{"id": "1"}, {"id": "2"}, {"id": "3"}]

        mock_get.return_value = {
            "nextPageUri": uri,
            "members": members,
            "uri": uri
        }

        result = self.resource_client.get_all()

        self.assertSequenceEqual(result, members)
        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, "get")
    def test_get_all_should_return_empty_list_when_response_has_no_items(self, mock_get):
        mock_get.return_value = {"nextPageUri": None, "members": []}

        result = self.resource_client.get_all()

        self.assertEqual(result, [])

    @mock.patch.object(connection, "get")
    def test_get_all_should_return_empty_list_when_no_members(self, mock_get):
        mock_get.return_value = {"nextPageUri": None, "members": None}

        result = self.resource_client.get_all()

        self.assertEqual(result, [])

    @mock.patch.object(ResourceHelper, "do_get")
    def test_refresh(self, mock_do_get):
        updated_data = {"resource_name": "updated name"}
        mock_do_get.return_value = updated_data
        self.resource_client.refresh()
        self.assertEqual(self.resource_client.data, updated_data)

    @mock.patch.object(connection, "post")
    def test_create_uri(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}
        expected_dict = {"resource_name": "a name", "type": self.TYPE_V300}

        self.resource_client.create(dict_to_create, timeout=-1)
        mock_post.assert_called_once_with(self.URI, expected_dict, custom_headers=None)

    @mock.patch.object(connection, "post")
    def test_create_with_api_version_200(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        self.connection._apiVersion = 200
        self.resource_client._merge_default_values()
        expected_dict = {"resource_name": "a name", "type": self.TYPE_V200}

        self.resource_client.create(dict_to_create, timeout=-1)
        mock_post.assert_called_once_with(self.URI, expected_dict, custom_headers=None)

    @mock.patch.object(connection, "post")
    def test_create_with_default_api_version_300(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        expected_dict = {"resource_name": "a name", "type": self.TYPE_V300}
        self.resource_client.create(dict_to_create, timeout=-1)
        mock_post.assert_called_once_with(self.URI, expected_dict, custom_headers=None)

    @mock.patch.object(connection, "post")
    def test_create_should_not_override_resource_properties(self, mock_post):
        dict_to_create = {"resource_name": "a name", "type": "anotherType"}
        mock_post.return_value = {}, {}
        expected = {"resource_name": "a name", "type": "anotherType"}
        self.resource_client.create(dict_to_create)

        mock_post.assert_called_once_with(self.URI, expected, custom_headers=None)

    @mock.patch.object(connection, "post")
    def test_create_without_default_values(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.create(dict_to_create, timeout=-1)

        mock_post.assert_called_once_with(self.URI, dict_to_create, custom_headers=None)

    @mock.patch.object(connection, "post")
    def test_create_with_custom_headers(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        self.resource_client.create(dict_to_create, custom_headers=self.custom_headers)

        mock_post.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={"Accept-Language": "en_US"})

    @mock.patch.object(connection, "post")
    def test_create_should_return_new_resource_instance(self, mock_post):
        mock_post.return_value = {}, {}
        new_instance = self.resource_client.create({})
        self.assertNotEqual(self.resource_client, new_instance)

    @mock.patch.object(connection, "post")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_wait_for_activity_on_create(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, {}
        mock_wait4task.return_value = self.task

        self.resource_client.create({"test": "test"}, timeout=60)

        mock_wait4task.assert_called_once_with(self.task, 60)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "delete")
    def test_delete_should_return_true(self, mock_delete, mock_ensure_resource):
        mock_delete.return_value = None, self.response_body
        self.resource_client.data = {"uri": "/rest/testuri"}
        result = self.resource_client.delete()
        self.assertTrue(result)

    @mock.patch.object(connection, 'delete')
    def test_helper_delete_all_should_return_true(self, mock_delete):
        mock_delete.return_value = None, self.response_body

        filter = "name='Exchange Server'"
        result = self.resource_helper.delete_all(filter=filter, force=True, timeout=-1)
        self.assertTrue(result)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "delete")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_delete_with_force(self, mock_ensure_resource, mock_delete, mock_wait4task):
        mock_delete.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task
        self.resource_client.data = {"uri": "/rest/testuri"}
        self.resource_client.delete(force=True)

        mock_delete.assert_called_once_with("/rest/testuri?force=True", custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "delete")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_delete_with_custom_headers(self, mock_ensure_resource, mock_delete, mock_wait4task):
        mock_delete.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task
        self.resource_client.data = {"uri": "/rest/testuri"}
        self.resource_client.delete(custom_headers=self.custom_headers)

        mock_delete.assert_called_once_with(mock.ANY, custom_headers={"Accept-Language": "en_US"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    def test_update_with_uri_called_once(self, mock_put, mock_ensure_resource):
        uri = "/rest/testuri"
        dict_to_update = {"name": "test", "type": "typeV300"}
        self.resource_client.data = {'uri': uri}
        expected = {"name": "test", "type": "typeV300", "uri": uri}

        mock_put.return_value = None, self.response_body
        self.resource_client.update(dict_to_update)

        self.assertEqual(self.response_body, self.resource_client.data)
        mock_put.assert_called_once_with(uri, expected, custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    def test_update_with_custom_headers(self, mock_put, mock_ensure_resource):
        dict_to_update = {"name": "test"}
        mock_put.return_value = None, self.response_body
        self.resource_client.update(dict_to_update, custom_headers=self.custom_headers)

        mock_put.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={"Accept-Language": "en_US"})

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    def test_update_with_force(self, mock_put, mock_laod_resource):
        dict_to_update = {"name": "test"}
        uri = "/rest/testuri"
        expected = {"name": "test", "uri": uri, "type": "typeV300"}
        mock_put.return_value = None, self.response_body

        self.resource_client.update(dict_to_update)

        expected_uri = "/rest/testuri"
        mock_put.assert_called_once_with(expected_uri, expected, custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    def test_update_with_default_api_version_300(self, mock_put, mock_ensure_resource):
        dict_to_update = {"name": "test"}
        uri = "/rest/testuri"
        mock_put.return_value = None, self.response_body
        expected_dict = {"name": "test", "type": self.TYPE_V300, "uri": uri}
        self.resource_client._merge_default_values()
        self.resource_client.update(dict_to_update)
        mock_put.assert_called_once_with(uri, expected_dict, custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    def test_update_should_not_override_resource_properties(self, mock_put, mock_ensure_resource):
        dict_to_update = {"name": "test", "type": "anotherType"}
        uri = "/rest/testuri"
        mock_put.return_value = None, self.response_body
        expected = {"name": "test", "type": "anotherType", "uri": uri}

        self.resource_client.update(dict_to_update)
        mock_put.assert_called_once_with(uri, expected, custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    def test_update_without_default_values(self, mock_put, mock_ensure_resource):
        uri = "/rest/testuri"
        dict_to_update = {"name": "test"}
        expected = {"name": "test", "uri": uri, "type": "typeV300"}
        mock_put.return_value = None, self.response_body

        self.resource_client.update(dict_to_update)
        mock_put.assert_called_once_with(uri, expected, custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_update_uri(self, mock_wait4task, mock_update, mock_ensure_resource):
        uri = "/rest/testuri"
        dict_to_update = {"resource_data": "resource_data", "uri": uri}
        expected = {"resource_data": "resource_data", "uri": uri, "type": "typeV300"}
        mock_update.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task
        self.resource_client.update(dict_to_update, False)

        self.assertEqual(self.task, self.resource_client.data)
        mock_update.assert_called_once_with(uri, expected, custom_headers=None)

    @mock.patch.object(Resource, "ensure_resource_data")
    @mock.patch.object(connection, "put")
    @mock.patch.object(TaskMonitor, "wait_for_task")
    def test_update_return_entity(self, mock_wait4task, mock_put, mock_ensure_resource):
        uri = "/rest/testuri"
        dict_to_update = {"resource_name": "a name", "uri": uri}
        mock_put.return_value = self.task, {}
        mock_wait4task.return_value = dict_to_update

        self.resource_client.update(dict_to_update, timeout=-1)

        self.assertEqual(self.resource_client.data, dict_to_update)

    @mock.patch.object(Resource, "get_by")
    def test_get_by_name_with_result(self, mock_get_by):
        self.resource_client.get_by_name("Resource Name,")
        mock_get_by.assert_called_once_with("name", "Resource Name,")

    @mock.patch.object(Resource, "get_by")
    def test_get_by_name_without_result(self, mock_get_by):
        mock_get_by.return_value = []
        response = self.resource_client.get_by_name("Resource Name,")
        self.assertIsNone(response)
        mock_get_by.assert_called_once_with("name", "Resource Name,")

    @mock.patch.object(connection, "get")
    def test_get_by_uri(self, mock_get):
        self.resource_client.get_by_uri("/rest/testuri")
        mock_get.assert_called_once_with('/rest/testuri')

    @mock.patch.object(connection, "get")
    def test_get_by_id_with_result(self, mock_get):
        self.resource_client.get_by_id("123")
        mock_get.assert_called_once_with("/rest/testuri/123")

    @mock.patch.object(connection, "get")
    def test_get_by_id_without_result(self, mock_get):
        mock_get.return_value = []
        response = self.resource_client.get_by_id("123")
        self.assertIsNone(response)
        mock_get.assert_called_once_with("/rest/testuri/123")

    @mock.patch.object(connection, "get")
    def test_get_collection_uri(self, mock_get):
        mock_get.return_value = {"members": [{"key": "value"}, {"key": "value"}]}

        self.resource_helper.get_collection()

        mock_get.assert_called_once_with(self.URI)

    @mock.patch.object(connection, "get")
    def test_get_collection_with_filter(self, mock_get):
        mock_get.return_value = {}

        self.resource_helper.get_collection(filter="name=name")

        mock_get.assert_called_once_with(self.URI + "?filter=name%3Dname")

    @mock.patch.object(connection, "get")
    def test_get_collection_with_path(self, mock_get):
        mock_get.return_value = {}

        self.resource_helper.get_collection(path="/test")

        mock_get.assert_called_once_with(self.URI + "/test")

    @mock.patch.object(connection, "get")
    def test_get_collection_with_multiple_filters(self, mock_get):
        mock_get.return_value = {}

        self.resource_helper.get_collection(filter=["name1=one", "name2=two", "name=three"])

        mock_get.assert_called_once_with(self.URI + "?filter=name1%3Done&filter=name2%3Dtwo&filter=name%3Dthree")

    @mock.patch.object(connection, "get")
    def test_get_collection_should_return_list(self, mock_get):
        mock_get.return_value = {"members": [{"key": "value"}, {"key": "value"}]}

        collection = self.resource_helper.get_collection()

        self.assertEqual(len(collection), 2)

    def test_build_uri_with_id_should_work(self):
        input = "09USE7335NW35"
        expected_output = "/rest/testuri/09USE7335NW35"
        result = self.resource_client._helper.build_uri(input)
        self.assertEqual(expected_output, result)

    def test_build_uri_with_uri_should_work(self):
        input = "/rest/testuri/09USE7335NW3"
        expected_output = "/rest/testuri/09USE7335NW3"
        result = self.resource_client._helper.build_uri(input)
        self.assertEqual(expected_output, result)

    def test_build_uri_with_none_should_raise_exception(self):
        try:
            self.resource_client._helper.build_uri(None)
        except ValueError as exception:
            self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_uri_with_empty_str_should_raise_exception(self):
        try:
            self.resource_client._helper.build_uri('')
        except ValueError as exception:
            self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_uri_with_different_resource_uri_should_raise_exception(self):
        try:
            self.resource_client._helper.build_uri(
                "/rest/test/another/resource/uri/09USE7335NW3")
        except exceptions.HPOneViewUnknownType as exception:
            self.assertEqual(UNRECOGNIZED_URI, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_uri_with_incomplete_uri_should_raise_exception(self):
        try:
            self.resource_client._helper.build_uri("/rest/")
        except exceptions.HPOneViewUnknownType as exception:
            self.assertEqual(UNRECOGNIZED_URI, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_subresource_uri(self):
        options = [
            dict(
                resource="1",
                subresource="2",
                path="sub",
                uri="/rest/testuri/1/sub/2"),
            dict(
                resource="/rest/testuri/3",
                subresource="4",
                path="sub",
                uri="/rest/testuri/3/sub/4"),
            dict(
                resource="5",
                subresource="/rest/testuri/5/sub/6",
                path="sub",
                uri="/rest/testuri/5/sub/6"),
            dict(
                resource="/rest/testuri/7",
                subresource="/rest/testuri/7/sub/8",
                path="sub",
                uri="/rest/testuri/7/sub/8"),
            dict(
                resource=None,
                subresource="/rest/testuri/9/sub/10",
                path="sub",
                uri="/rest/testuri/9/sub/10"),
            dict(
                resource="/rest/testuri/11",
                subresource="12",
                path="/sub/",
                uri="/rest/testuri/11/sub/12"),
            dict(
                resource="/rest/testuri/13",
                subresource=None,
                path="/sub/",
                uri="/rest/testuri/13/sub"),
        ]

        for option in options:
            uri = self.resource_client._helper.build_subresource_uri(option["resource"], option["subresource"], option["path"])
            self.assertEqual(uri, option["uri"])

    def test_build_subresource_uri_with_subresourceid_and_without_resource_should_fail(self):
        try:
            self.resource_client._helper.build_subresource_uri(None, "123456", "sub-path")
        except exceptions.HPOneViewValueError as exception:
            self.assertEqual(RESOURCE_ID_OR_URI_REQUIRED, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_merge_resources(self):
        resource1 = {"name": "resource1", "type": "resource"}
        resource2 = {"name": "resource2", "port": "1"}

        expected_resource = {"name": "resource2", "type": "resource", "port": "1"}

        merged_resource = merge_resources(resource1, resource2)
        self.assertEqual(merged_resource, expected_resource)

    def test_merge_default_values(self):
        default_type = {"type": "type1"}
        resource1 = {"name": "resource1"}
        resource2 = {"name": "resource2"}

        result_list = merge_default_values([resource1, resource2], default_type)

        expected_list = [
            {"name": "resource1", "type": "type1"},
            {"name": "resource2", "type": "type1"}
        ]

        self.assertEqual(result_list, expected_list)

    def test_raise_unavailable_method_exception(self):
        self.assertRaises(exceptions.HPOneViewUnavailableMethod,
                          unavailable_method)


class FakeResource(object):
    def __init__(self, con):
        self._connection = con
        self._client = ResourceClient(con, "/rest/fake/resource")

    def get_fake(self, uri):
        return self._client.get(uri)


class ResourceClientTest(unittest.TestCase):
    URI = "/rest/testuri"

    TYPE_V200 = 'typeV200'
    TYPE_V300 = 'typeV300'

    DEFAULT_VALUES = {
        '200': {'type': TYPE_V200},
        '300': {'type': TYPE_V300}
    }

    def setUp(self):
        super(ResourceClientTest, self).setUp()
        self.host = '127.0.0.1'
        self.connection = connection(self.host, 300)
        self.resource_client = ResourceClient(self.connection, self.URI)
        self.task = {"task": "task", "taskState": "Finished"}
        self.response_body = {"body": "body"}
        self.custom_headers = {'Accept-Language': 'en_US'}

    @mock.patch.object(connection, 'get')
    def test_get_all_called_once(self, mock_get):
        filter = "'name'='OneViewSDK \"Test FC Network'"
        sort = 'name:ascending'
        query = "name NE 'WrongName'"
        view = '"{view-name}"'
        scope_uris = '/rest/scopes/cd237b60-09e2-45c4-829e-082e318a6d2a'

        mock_get.return_value = {"members": [{"member": "member"}]}

        result = self.resource_client.get_all(
            1, 500, filter, query, sort, view, 'name,owner,modified', scope_uris=scope_uris)

        uri = '{resource_uri}?start=1' \
              '&count=500' \
              '&filter=%27name%27%3D%27OneViewSDK%20%22Test%20FC%20Network%27' \
              '&query=name%20NE%20%27WrongName%27' \
              '&sort=name%3Aascending' \
              '&view=%22%7Bview-name%7D%22' \
              '&fields=name%2Cowner%2Cmodified' \
              '&scopeUris=/rest/scopes/cd237b60-09e2-45c4-829e-082e318a6d2a'.format(resource_uri=self.URI)

        self.assertEqual([{'member': 'member'}], result)
        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, 'get')
    def test_get_all_with_defaults(self, mock_get):
        self.resource_client.get_all()
        uri = "{resource_uri}?start=0&count=-1".format(resource_uri=self.URI)

        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, 'get')
    def test_get_all_with_custom_uri(self, mock_get):
        self.resource_client.get_all(uri='/rest/testuri/12467836/subresources')
        uri = "/rest/testuri/12467836/subresources?start=0&count=-1"

        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, 'get')
    def test_get_all_with_custom_uri_and_query_string(self, mock_get):
        self.resource_client.get_all(uri='/rest/testuri/12467836/subresources?param=value')

        uri = "/rest/testuri/12467836/subresources?param=value&start=0&count=-1"
        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, 'get')
    def test_get_all_with_different_resource_uri_should_fail(self, mock_get):
        try:
            self.resource_client.get_all(uri='/rest/other/resource/12467836/subresources')
        except exceptions.HPOneViewUnknownType as e:
            self.assertEqual(UNRECOGNIZED_URI, e.args[0])
        else:
            self.fail('Expected Exception was not raised')

    @mock.patch.object(connection, 'get')
    def test_get_all_should_do_multi_requests_when_response_paginated(self, mock_get):
        uri_list = ['/rest/testuri?start=0&count=-1',
                    '/rest/testuri?start=3&count=3',
                    '/rest/testuri?start=6&count=3']

        results = [{'nextPageUri': uri_list[1], 'members': [{'id': '1'}, {'id': '2'}, {'id': '3'}]},
                   {'nextPageUri': uri_list[2], 'members': [{'id': '4'}, {'id': '5'}, {'id': '6'}]},
                   {'nextPageUri': None, 'members': [{'id': '7'}, {'id': '8'}]}]

        mock_get.side_effect = results

        self.resource_client.get_all()

        expected_calls = [call(uri_list[0]), call(uri_list[1]), call(uri_list[2])]
        self.assertEqual(mock_get.call_args_list, expected_calls)

    @mock.patch.object(connection, 'get')
    def test_get_all_with_count_should_do_multi_requests_when_response_paginated(self, mock_get):
        uri_list = ['/rest/testuri?start=0&count=15',
                    '/rest/testuri?start=3&count=3',
                    '/rest/testuri?start=6&count=3']

        results = [{'nextPageUri': uri_list[1], 'members': [{'id': '1'}, {'id': '2'}, {'id': '3'}]},
                   {'nextPageUri': uri_list[2], 'members': [{'id': '4'}, {'id': '5'}, {'id': '6'}]},
                   {'nextPageUri': None, 'members': [{'id': '7'}, {'id': '8'}]}]

        mock_get.side_effect = results

        self.resource_client.get_all(count=15)

        expected_calls = [call(uri_list[0]), call(uri_list[1]), call(uri_list[2])]
        self.assertEqual(mock_get.call_args_list, expected_calls)

    @mock.patch.object(connection, 'get')
    def test_get_all_should_return_all_items_when_response_paginated(self, mock_get):
        uri_list = ['/rest/testuri?start=0&count=-1',
                    '/rest/testuri?start=3&count=3',
                    '/rest/testuri?start=6&count=1']

        results = [{'nextPageUri': uri_list[1], 'members': [{'id': '1'}, {'id': '2'}, {'id': '3'}]},
                   {'nextPageUri': uri_list[2], 'members': [{'id': '4'}, {'id': '5'}, {'id': '6'}]},
                   {'nextPageUri': None, 'members': [{'id': '7'}]}]

        mock_get.side_effect = results

        result = self.resource_client.get_all()

        expected_items = [{'id': '1'}, {'id': '2'}, {'id': '3'}, {'id': '4'}, {'id': '5'}, {'id': '6'}, {'id': '7'}]
        self.assertSequenceEqual(result, expected_items)

    @mock.patch.object(connection, 'get')
    def test_get_all_should_limit_results_to_requested_count_when_response_is_paginated(self, mock_get):
        uri_list = ['/rest/testuri?start=0&count=15',
                    '/rest/testuri?start=3&count=3',
                    '/rest/testuri?start=6&count=1']

        results = [{'nextPageUri': uri_list[1], 'members': [{'id': '1'}, {'id': '2'}, {'id': '3'}]},
                   {'nextPageUri': uri_list[2], 'members': [{'id': '4'}, {'id': '5'}, {'id': '6'}]},
                   {'nextPageUri': None, 'members': [{'id': '7'}]}]

        mock_get.side_effect = results

        result = self.resource_client.get_all(count=15)

        expected_items = [{'id': '1'}, {'id': '2'}, {'id': '3'}, {'id': '4'}, {'id': '5'}, {'id': '6'}, {'id': '7'}]
        self.assertSequenceEqual(result, expected_items)

    @mock.patch.object(connection, 'get')
    def test_get_all_should_stop_requests_when_requested_count_reached(self, mock_get):
        """
        In this case, the user provides a maximum number of results to be returned but for pagination purposes, a
        nextPageUri is returned by OneView.
        """
        uri_list = ['/rest/testuri?start=0&count=3',
                    '/rest/testuri?start=3&count=3',
                    '/rest/testuri?start=6&count=3']

        results = [{'nextPageUri': uri_list[1], 'members': [{'id': '1'}, {'id': '2'}, {'id': '3'}]},
                   {'nextPageUri': uri_list[2], 'members': [{'id': '4'}, {'id': '5'}, {'id': '6'}]},
                   {'nextPageUri': None, 'members': [{'id': '7'}, {'id': '8'}]}]

        mock_get.side_effect = results

        self.resource_client.get_all(count=3)

        mock_get.assert_called_once_with(uri_list[0])

    @mock.patch.object(connection, 'get')
    def test_get_all_should_stop_requests_when_next_page_is_equal_to_current_page(self, mock_get):
        uri = '/rest/testuri?start=0&count=-1'
        members = [{'id': '1'}, {'id': '2'}, {'id': '3'}]

        mock_get.return_value = {
            'nextPageUri': uri,
            'members': members,
            'uri': uri
        }

        result = self.resource_client.get_all()

        self.assertSequenceEqual(result, members)
        mock_get.assert_called_once_with(uri)

    @mock.patch.object(connection, 'get')
    def test_get_all_should_return_empty_list_when_response_has_no_items(self, mock_get):
        mock_get.return_value = {'nextPageUri': None, 'members': []}

        result = self.resource_client.get_all()

        self.assertEqual(result, [])

    @mock.patch.object(connection, 'get')
    def test_get_all_should_return_empty_list_when_no_members(self, mock_get):
        mock_get.return_value = {'nextPageUri': None, 'members': None}

        result = self.resource_client.get_all()

        self.assertEqual(result, [])

    @mock.patch.object(connection, 'delete')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_delete_all_called_once(self, mock_wait4task, mock_delete):
        mock_delete.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task

        filter = "name='Exchange Server'"
        uri = "/rest/testuri?filter=name%3D%27Exchange%20Server%27&force=True"
        self.resource_client.delete_all(filter=filter, force=True, timeout=-1)

        mock_delete.assert_called_once_with(uri)

    @mock.patch.object(connection, 'delete')
    def test_delete_all_should_return_true(self, mock_delete):
        mock_delete.return_value = None, self.response_body

        filter = "name='Exchange Server'"
        result = self.resource_client.delete_all(filter=filter, force=True, timeout=-1)

        self.assertTrue(result)

    @mock.patch.object(connection, 'delete')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_delete_all_should_wait_for_task(self, mock_wait4task, mock_delete):
        mock_delete.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task

        filter = "name='Exchange Server'"
        delete_task = self.resource_client.delete_all(filter=filter, force=True, timeout=-1)

        mock_wait4task.assert_called_with(self.task, timeout=-1)
        self.assertEqual(self.task, delete_task)

    @mock.patch.object(connection, 'delete')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_delete_by_id_called_once(self, mock_wait4task, mock_delete):
        mock_delete.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task

        delete_task = self.resource_client.delete('1', force=True, timeout=-1)

        self.assertEqual(self.task, delete_task)
        mock_delete.assert_called_once_with(self.URI + "/1?force=True", custom_headers=None)

    @mock.patch.object(connection, 'delete')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_delete_with_custom_headers(self, mock_wait4task, mock_delete):
        mock_delete.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task

        self.resource_client.delete('1', custom_headers=self.custom_headers)

        mock_delete.assert_called_once_with(mock.ANY, custom_headers={'Accept-Language': 'en_US'})

    def test_delete_dict_invalid_uri(self):
        dict_to_delete = {"task": "task",
                          "uri": ""}
        try:
            self.resource_client.delete(dict_to_delete, False, -1)
        except exceptions.HPOneViewUnknownType as e:
            self.assertEqual("Unknown object type", e.args[0])
        else:
            self.fail()

    @mock.patch.object(connection, 'get')
    def test_get_schema_uri(self, mock_get):
        self.resource_client.get_schema()
        mock_get.assert_called_once_with(self.URI + "/schema")

    @mock.patch.object(connection, 'get')
    def test_get_by_id_uri(self, mock_get):
        self.resource_client.get('12345')
        mock_get.assert_called_once_with(self.URI + "/12345")

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_name_with_result(self, mock_get_by):
        mock_get_by.return_value = [{"name": "value"}]
        response = self.resource_client.get_by_name('Resource Name,')
        self.assertEqual(response, {"name": "value"})
        mock_get_by.assert_called_once_with("name", 'Resource Name,')

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_name_without_result(self, mock_get_by):
        mock_get_by.return_value = []
        response = self.resource_client.get_by_name('Resource Name,')
        self.assertIsNone(response)
        mock_get_by.assert_called_once_with("name", 'Resource Name,')

    @mock.patch.object(connection, 'get')
    def test_get_collection_uri(self, mock_get):
        mock_get.return_value = {"members": [{"key": "value"}, {"key": "value"}]}

        self.resource_client.get_collection('12345')

        mock_get.assert_called_once_with(self.URI + "/12345")

    @mock.patch.object(connection, 'get')
    def test_get_collection_with_filter(self, mock_get):
        mock_get.return_value = {}

        self.resource_client.get_collection('12345', 'name=name')

        mock_get.assert_called_once_with(self.URI + "/12345?filter=name%3Dname")

    @mock.patch.object(connection, 'get')
    def test_get_collection_with_multiple_filters(self, mock_get):
        mock_get.return_value = {}

        self.resource_client.get_collection('12345', ['name1=one', 'name2=two', 'name=three'])

        mock_get.assert_called_once_with(self.URI + "/12345?filter=name1%3Done&filter=name2%3Dtwo&filter=name%3Dthree")

    @mock.patch.object(connection, 'get')
    def test_get_collection_should_return_list(self, mock_get):
        mock_get.return_value = {"members": [{"key": "value"}, {"key": "value"}]}

        collection = self.resource_client.get_collection('12345')

        self.assertEqual(len(collection), 2)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_by_property(self, mock_get_all):
        self.resource_client.get_by('name', 'MyFibreNetwork')
        mock_get_all.assert_called_once_with(filter="\"name='MyFibreNetwork'\"", uri='/rest/testuri')

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_by_with_incorrect_result_autofix(self, mock_get_all):

        mock_get_all.return_value = [{"name": "EXpected"},
                                     {"name": "not expected"}]

        response = self.resource_client.get_by('name', 'exPEcted')
        self.assertEqual(response, [{"name": "EXpected"}])
        mock_get_all.assert_called_once_with(filter="\"name='exPEcted'\"", uri='/rest/testuri')

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_by_with_incorrect_result_skip_autofix(self, mock_get_all):

        mock_get_all.return_value = [{"name": "expected"},
                                     {"name": "not expected"}]

        response = self.resource_client.get_by('connection.name', 'expected')
        self.assertEqual(response, [{'name': 'expected'}, {'name': 'not expected'}])
        mock_get_all.assert_called_once_with(filter="\"connection.name='expected'\"", uri='/rest/testuri')

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_by_property_with_uri(self, mock_get_all):
        self.resource_client.get_by('name', 'MyFibreNetwork', uri='/rest/testuri/5435534/sub')
        mock_get_all.assert_called_once_with(filter="\"name='MyFibreNetwork'\"", uri='/rest/testuri/5435534/sub')

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_by_property_with__invalid_uri(self, mock_get_all):
        try:
            self.resource_client.get_by('name', 'MyFibreNetwork', uri='/rest/other/5435534/sub')
        except exceptions.HPOneViewUnknownType as e:
            self.assertEqual('Unrecognized URI for this resource', e.args[0])
        else:
            self.fail()

    @mock.patch.object(connection, 'put')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_update_with_zero_body_called_once(self, mock_wait4task, mock_update):
        mock_update.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.update_with_zero_body('/rest/enclosures/09USE133E5H4/configuration',
                                                   timeout=-1)

        mock_update.assert_called_once_with(
            "/rest/enclosures/09USE133E5H4/configuration", None, custom_headers=None)

    @mock.patch.object(connection, 'put')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_update_with_zero_body_and_custom_headers(self, mock_wait4task, mock_update):
        mock_update.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.update_with_zero_body('1', custom_headers=self.custom_headers)

        mock_update.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={'Accept-Language': 'en_US'})

    @mock.patch.object(connection, 'put')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_update_with_zero_body_return_entity(self, mock_wait4task, mock_put):
        response_body = {"resource_name": "name"}

        mock_put.return_value = self.task, self.task
        mock_wait4task.return_value = response_body

        result = self.resource_client.update_with_zero_body(
            '/rest/enclosures/09USE133E5H4/configuration', timeout=-1)

        self.assertEqual(result, response_body)

    @mock.patch.object(connection, 'put')
    def test_update_with_zero_body_without_task(self, mock_put):
        mock_put.return_value = None, self.response_body

        result = self.resource_client.update_with_zero_body(
            '/rest/enclosures/09USE133E5H4/configuration', timeout=-1)

        self.assertEqual(result, self.response_body)

    @mock.patch.object(connection, 'put')
    def test_update_with_uri_called_once(self, mock_put):
        dict_to_update = {"name": "test"}
        uri = "/rest/resource/test"

        mock_put.return_value = None, self.response_body
        response = self.resource_client.update(dict_to_update, uri=uri)

        self.assertEqual(self.response_body, response)
        mock_put.assert_called_once_with(uri, dict_to_update, custom_headers=None)

    @mock.patch.object(connection, 'put')
    def test_update_with_custom_headers(self, mock_put):
        dict_to_update = {"name": "test"}
        mock_put.return_value = None, self.response_body

        self.resource_client.update(dict_to_update, uri="/path", custom_headers=self.custom_headers)

        mock_put.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={'Accept-Language': 'en_US'})

    @mock.patch.object(connection, 'put')
    def test_update_with_force(self, mock_put):
        dict_to_update = {"name": "test"}
        uri = "/rest/resource/test"
        mock_put.return_value = None, self.response_body

        self.resource_client.update(dict_to_update, uri=uri, force=True)

        expected_uri = "/rest/resource/test?force=True"
        mock_put.assert_called_once_with(expected_uri, dict_to_update, custom_headers=None)

    @mock.patch.object(connection, 'put')
    def test_update_with_api_version_200(self, mock_put):
        dict_to_update = {"name": "test"}
        uri = "/rest/resource/test"

        mock_put.return_value = None, self.response_body
        self.connection._apiVersion = 200

        expected_dict = {"name": "test", "type": self.TYPE_V200}

        self.resource_client.update(dict_to_update, uri=uri, default_values=self.DEFAULT_VALUES)
        mock_put.assert_called_once_with(uri, expected_dict, custom_headers=None)

    @mock.patch.object(connection, 'put')
    def test_update_with_default_api_version_300(self, mock_put):
        dict_to_update = {"name": "test"}
        uri = "/rest/resource/test"

        mock_put.return_value = None, self.response_body

        expected_dict = {"name": "test", "type": self.TYPE_V300}

        self.resource_client.update(dict_to_update, uri=uri, default_values=self.DEFAULT_VALUES)
        mock_put.assert_called_once_with(uri, expected_dict, custom_headers=None)

    @mock.patch.object(connection, 'put')
    def test_update_should_not_override_resource_properties(self, mock_put):
        dict_to_update = {"name": "test", "type": "anotherType"}
        uri = "/rest/resource/test"

        mock_put.return_value = None, self.response_body

        self.resource_client.update(dict_to_update, uri=uri, default_values=self.DEFAULT_VALUES)
        mock_put.assert_called_once_with(uri, dict_to_update, custom_headers=None)

    @mock.patch.object(connection, 'put')
    def test_update_without_default_values(self, mock_put):
        dict_to_update = {"name": "test"}
        uri = "/rest/resource/test"

        mock_put.return_value = None, self.response_body

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.update(dict_to_update, uri=uri)

        mock_put.assert_called_once_with(uri, dict_to_update, custom_headers=None)

    @mock.patch.object(connection, 'put')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_update_uri(self, mock_wait4task, mock_update):
        dict_to_update = {"resource_data": "resource_data",
                          "uri": "a_uri"}

        mock_update.return_value = self.task, self.response_body
        mock_wait4task.return_value = self.task
        update_task = self.resource_client.update(dict_to_update, False)

        self.assertEqual(self.task, update_task)
        mock_update.assert_called_once_with("a_uri", dict_to_update, custom_headers=None)

    @mock.patch.object(connection, 'put')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_update_return_entity(self, mock_wait4task, mock_put):
        dict_to_update = {
            "resource_name": "a name",
            "uri": "a_uri",
        }
        mock_put.return_value = self.task, {}
        mock_wait4task.return_value = dict_to_update

        result = self.resource_client.update(dict_to_update, timeout=-1)

        self.assertEqual(result, dict_to_update)

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_create_with_zero_body_called_once(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.create_with_zero_body('/rest/enclosures/09USE133E5H4/configuration',
                                                   timeout=-1)

        mock_post.assert_called_once_with(
            "/rest/enclosures/09USE133E5H4/configuration", {}, custom_headers=None)

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_create_with_zero_body_called_once_without_uri(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.create_with_zero_body(timeout=-1)

        mock_post.assert_called_once_with(
            '/rest/testuri', {}, custom_headers=None)

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_create_with_zero_body_and_custom_headers(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = self.task
        self.resource_client.create_with_zero_body('1', custom_headers=self.custom_headers)

        mock_post.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={'Accept-Language': 'en_US'})

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_create_with_zero_body_return_entity(self, mock_wait4task, mock_post):
        response_body = {"resource_name": "name"}

        mock_post.return_value = self.task, self.task
        mock_wait4task.return_value = response_body

        result = self.resource_client.create_with_zero_body(
            '/rest/enclosures/09USE133E5H4/configuration', timeout=-1)

        self.assertEqual(result, response_body)

    @mock.patch.object(connection, 'post')
    def test_create_with_zero_body_without_task(self, mock_post):
        mock_post.return_value = None, self.response_body

        result = self.resource_client.create_with_zero_body(
            '/rest/enclosures/09USE133E5H4/configuration', timeout=-1)

        self.assertEqual(result, self.response_body)

    @mock.patch.object(connection, 'post')
    def test_create_uri(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        self.resource_client.create(dict_to_create, timeout=-1)
        mock_post.assert_called_once_with(self.URI, dict_to_create, custom_headers=None)

    @mock.patch.object(connection, 'post')
    def test_create_uri_with_force(self, mock_post):
        dict_to_create = {"resource_name": "a name", "force": "yes"}
        mock_post.return_value = {}, {}

        self.resource_client.create(dict_to_create, timeout=-1)
        expected_uri = "/rest/testuri"
        mock_post.assert_called_once_with(expected_uri, dict_to_create, custom_headers=None)

    @mock.patch.object(connection, 'post')
    def test_create_with_api_version_200(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        self.connection._apiVersion = 200
        expected_dict = {"resource_name": "a name", "type": self.TYPE_V200}

        self.resource_client.create(dict_to_create, timeout=-1, default_values=self.DEFAULT_VALUES)
        mock_post.assert_called_once_with(self.URI, expected_dict, custom_headers=None)

    @mock.patch.object(connection, 'post')
    def test_create_with_default_api_version_300(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        expected_dict = {"resource_name": "a name", "type": self.TYPE_V300}

        self.resource_client.create(dict_to_create, timeout=-1, default_values=self.DEFAULT_VALUES)
        mock_post.assert_called_once_with(self.URI, expected_dict, custom_headers=None)

    @mock.patch.object(connection, 'post')
    def test_create_should_not_override_resource_properties(self, mock_post):
        dict_to_create = {"resource_name": "a name", "type": "anotherType"}
        mock_post.return_value = {}, {}

        self.resource_client.create(dict_to_create, default_values=self.DEFAULT_VALUES)

        mock_post.assert_called_once_with(self.URI, dict_to_create, custom_headers=None)

    @mock.patch.object(connection, 'post')
    def test_create_without_default_values(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.create(dict_to_create, timeout=-1)

        mock_post.assert_called_once_with(self.URI, dict_to_create, custom_headers=None)

    @mock.patch.object(connection, 'post')
    def test_create_with_custom_headers(self, mock_post):
        dict_to_create = {"resource_name": "a name"}
        mock_post.return_value = {}, {}

        self.resource_client.create(dict_to_create, custom_headers=self.custom_headers)

        mock_post.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={'Accept-Language': 'en_US'})

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_create_return_entity(self, mock_wait4task, mock_post):
        dict_to_create = {
            "resource_name": "a name",
        }
        created_resource = {
            "resource_id": "123",
            "resource_name": "a name",
        }

        mock_post.return_value = self.task, {}
        mock_wait4task.return_value = created_resource

        result = self.resource_client.create(dict_to_create, -1)

        self.assertEqual(result, created_resource)

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_wait_for_activity_on_create(self, mock_wait4task, mock_post):
        mock_post.return_value = self.task, {}
        mock_wait4task.return_value = self.task

        self.resource_client.create({"test": "test"}, timeout=60)

        mock_wait4task.assert_called_once_with(self.task, 60)

    @mock.patch.object(connection, 'patch')
    def test_patch_request_when_id_is_provided_v200(self, mock_patch):
        request_body = [{
            'op': 'replace',
            'path': '/name',
            'value': 'new_name',
        }]
        mock_patch.return_value = {}, {}

        self.connection._apiVersion = 200

        self.resource_client.patch(
            '123a53cz', 'replace', '/name', 'new_name', 70)

        mock_patch.assert_called_once_with(
            '/rest/testuri/123a53cz', request_body, custom_headers={})

    @mock.patch.object(connection, 'patch')
    def test_patch_request_when_id_is_provided_v300(self, mock_patch):
        request_body = [{
            'op': 'replace',
            'path': '/name',
            'value': 'new_name',
        }]
        mock_patch.return_value = {}, {}

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.patch(
            '123a53cz', 'replace', '/name', 'new_name', 70)

        mock_patch.assert_called_once_with(
            '/rest/testuri/123a53cz', request_body, custom_headers={'Content-Type': 'application/json-patch+json'})

    @mock.patch.object(connection, 'patch')
    def test_patch_request_when_uri_is_provided(self, mock_patch):
        request_body = [{
            'op': 'replace',
            'path': '/name',
            'value': 'new_name',
        }]
        mock_patch.return_value = {}, {}

        self.resource_client.patch(
            '/rest/testuri/123a53cz', 'replace', '/name', 'new_name', 60)

        mock_patch.assert_called_once_with(
            '/rest/testuri/123a53cz', request_body, custom_headers={'Content-Type': 'application/json-patch+json'})

    @mock.patch.object(connection, 'patch')
    def test_patch_with_custom_headers_v200(self, mock_patch):
        mock_patch.return_value = {}, {}

        self.connection._apiVersion = 200

        self.resource_client.patch('/rest/testuri/123', 'operation', '/field', 'value',
                                   custom_headers=self.custom_headers)

        mock_patch.assert_called_once_with(mock.ANY, mock.ANY, custom_headers={'Accept-Language': 'en_US'})

    @mock.patch.object(connection, 'patch')
    def test_patch_with_custom_headers_v300(self, mock_patch):
        mock_patch.return_value = {}, {}

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.patch('/rest/testuri/123', 'operation', '/field', 'value',
                              custom_headers=self.custom_headers)

        mock_patch.assert_called_once_with(mock.ANY,
                                           mock.ANY,
                                           custom_headers={'Accept-Language': 'en_US',
                                                           'Content-Type': 'application/json-patch+json'})

    @mock.patch.object(connection, 'patch')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_patch_return_entity(self, mock_wait4task, mock_patch):
        entity = {"resource_id": "123a53cz"}
        mock_patch.return_value = self.task, self.task
        mock_wait4task.return_value = entity

        result = self.resource_client.patch(
            '123a53cz', 'replace', '/name', 'new_name', -1)

        self.assertEqual(result, entity)

    @mock.patch.object(connection, 'patch')
    @mock.patch.object(TaskMonitor, 'get_completed_task')
    def test_patch_request_custom_headers_with_content_type(self, mock_task, mock_patch):

        dict_info = {"resource_name": "a name"}

        mock_patch.return_value = {}, {}

        headers = {'Content-Type': 'application/json',
                   'Extra': 'extra'}
        self.connection._apiVersion = 300

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.patch_request('/rest/testuri/id', body=dict_info, custom_headers=headers)

        mock_patch.assert_called_once_with('/rest/testuri/id', dict_info, custom_headers=headers)

    @mock.patch.object(connection, 'patch')
    @mock.patch.object(TaskMonitor, 'get_completed_task')
    def test_patch_request_custom_headers(self, mock_task, mock_patch):

        dict_info = {"resource_name": "a name"}

        mock_patch.return_value = {}, {}
        headers = {'Extra': 'extra'}
        self.connection._apiVersion = 300

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.patch_request('/rest/testuri/id', body=dict_info, custom_headers=headers)

        mock_patch.assert_called_once_with(
            '/rest/testuri/id',
            dict_info,
            custom_headers={'Extra': 'extra',
                            'Content-Type': 'application/json-patch+json'})

    @mock.patch.object(connection, 'patch')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_wait_for_activity_on_patch(self, mock_wait4task, mock_patch):
        entity = {"resource_id": "123a53cz"}
        mock_patch.return_value = self.task, self.task
        mock_wait4task.return_value = entity

        self.resource_client.patch(
            '123a53cz', 'replace', '/name', 'new_name', -1)

        mock_wait4task.assert_called_once_with(self.task, mock.ANY)

    def test_delete_with_none(self):
        try:
            self.resource_client.delete(None)
        except ValueError as e:
            self.assertTrue("Resource" in e.args[0])
        else:
            self.fail()

    @mock.patch.object(connection, 'delete')
    def test_delete_with_dict_uri(self, mock_delete):

        resource = {"uri": "uri"}

        mock_delete.return_value = {}, {}
        delete_result = self.resource_client.delete(resource)

        self.assertTrue(delete_result)
        mock_delete.assert_called_once_with("uri", custom_headers=None)

    def test_delete_with_empty_dict(self):
        try:
            self.resource_client.delete({})
        except ValueError as e:
            self.assertTrue("Resource" in e.args[0])
        else:
            self.fail()

    def test_get_with_none(self):
        try:
            self.resource_client.get(None)
        except ValueError as e:
            self.assertTrue("id" in e.args[0])
        else:
            self.fail()

    def test_get_collection_with_none(self):
        try:
            self.resource_client.get_collection(None)
        except ValueError as e:
            self.assertTrue("id" in e.args[0])
        else:
            self.fail()

    def test_create_with_none(self):
        try:
            self.resource_client.create(None)
        except ValueError as e:
            self.assertTrue("Resource" in e.args[0])
        else:
            self.fail()

    def test_create_with_empty_dict(self):
        try:
            self.resource_client.create({})
        except ValueError as e:
            self.assertTrue("Resource" in e.args[0])
        else:
            self.fail()

    def test_update_with_none(self):
        try:
            self.resource_client.update(None)
        except ValueError as e:
            self.assertTrue("Resource" in e.args[0])
        else:
            self.fail()

    def test_update_with_empty_dict(self):
        try:
            self.resource_client.update({})
        except ValueError as e:
            self.assertTrue("Resource" in e.args[0])
        else:
            self.fail()

    def test_get_by_with_name_none(self):
        try:
            self.resource_client.get_by(None, None)
        except ValueError as e:
            self.assertTrue("field" in e.args[0])
        else:
            self.fail()

    @mock.patch.object(connection, 'get')
    def test_get_with_uri_should_work(self, mock_get):
        mock_get.return_value = {}
        uri = self.URI + "/ad28cf21-8b15-4f92-bdcf-51cb2042db32"
        self.resource_client.get(uri)

        mock_get.assert_called_once_with(uri)

    def test_get_with_uri_with_incompatible_url_shoud_fail(self):
        message = "Unrecognized URI for this resource"
        uri = "/rest/interconnects/ad28cf21-8b15-4f92-bdcf-51cb2042db32"
        try:
            self.resource_client.get(uri)
        except exceptions.HPOneViewUnknownType as exception:
            self.assertEqual(message, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_get_with_uri_from_another_resource_with_incompatible_url_shoud_fail(self):
        message = "Unrecognized URI for this resource"
        uri = "/rest/interconnects/ad28cf21-8b15-4f92-bdcf-51cb2042db32"
        fake_resource = FakeResource(None)
        try:
            fake_resource.get_fake(uri)
        except exceptions.HPOneViewUnknownType as exception:
            self.assertEqual(message, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    @mock.patch.object(connection, 'get')
    def test_get_utilization_with_args(self, mock_get):
        self.resource_client.get_utilization('09USE7335NW3', fields='AmbientTemperature,AveragePower,PeakPower',
                                             filter='startDate=2016-05-30T03:29:42.361Z',
                                             refresh=True, view='day')

        expected_uri = '/rest/testuri/09USE7335NW3/utilization' \
                       '?filter=startDate%3D2016-05-30T03%3A29%3A42.361Z' \
                       '&fields=AmbientTemperature%2CAveragePower%2CPeakPower' \
                       '&refresh=true' \
                       '&view=day'

        mock_get.assert_called_once_with(expected_uri)

    @mock.patch.object(connection, 'get')
    def test_get_utilization_with_multiple_filters(self, mock_get):
        self.resource_client.get_utilization(
            '09USE7335NW3',
            fields='AmbientTemperature,AveragePower,PeakPower',
            filter=['startDate=2016-05-30T03:29:42.361Z',
                    'endDate=2016-05-31T03:29:42.361Z'],
            refresh=True,
            view='day')

        expected_uri = '/rest/testuri/09USE7335NW3/utilization' \
                       '?filter=startDate%3D2016-05-30T03%3A29%3A42.361Z' \
                       '&filter=endDate%3D2016-05-31T03%3A29%3A42.361Z' \
                       '&fields=AmbientTemperature%2CAveragePower%2CPeakPower' \
                       '&refresh=true' \
                       '&view=day'

        mock_get.assert_called_once_with(expected_uri)

    @mock.patch.object(connection, 'get')
    def test_get_utilization_by_id_with_defaults(self, mock_get):
        self.resource_client.get_utilization('09USE7335NW3')

        expected_uri = '/rest/testuri/09USE7335NW3/utilization'

        mock_get.assert_called_once_with(expected_uri)

    @mock.patch.object(connection, 'get')
    def test_get_utilization_by_uri_with_defaults(self, mock_get):
        self.resource_client.get_utilization('/rest/testuri/09USE7335NW3')

        expected_uri = '/rest/testuri/09USE7335NW3/utilization'

        mock_get.assert_called_once_with(expected_uri)

    def test_get_utilization_with_empty(self):

        try:
            self.resource_client.get_utilization('')
        except ValueError as exception:
            self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_uri_with_id_should_work(self):
        input = '09USE7335NW35'
        expected_output = '/rest/testuri/09USE7335NW35'
        result = self.resource_client.build_uri(input)
        self.assertEqual(expected_output, result)

    def test_build_uri_with_uri_should_work(self):
        input = '/rest/testuri/09USE7335NW3'
        expected_output = '/rest/testuri/09USE7335NW3'
        result = self.resource_client.build_uri(input)
        self.assertEqual(expected_output, result)

    def test_build_uri_with_none_should_raise_exception(self):
        try:
            self.resource_client.build_uri(None)
        except ValueError as exception:
            self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_uri_with_empty_str_should_raise_exception(self):
        try:
            self.resource_client.build_uri('')
        except ValueError as exception:
            self.assertEqual(RESOURCE_CLIENT_INVALID_ID, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_uri_with_different_resource_uri_should_raise_exception(self):
        try:
            self.resource_client.build_uri(
                '/rest/test/another/resource/uri/09USE7335NW3')
        except exceptions.HPOneViewUnknownType as exception:
            self.assertEqual(UNRECOGNIZED_URI, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_uri_with_incomplete_uri_should_raise_exception(self):
        try:
            self.resource_client.build_uri('/rest/')
        except exceptions.HPOneViewUnknownType as exception:
            self.assertEqual(UNRECOGNIZED_URI, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    def test_build_subresource_uri(self):
        options = [
            dict(
                resource='1',
                subresource='2',
                path='sub',
                uri='/rest/testuri/1/sub/2'),
            dict(
                resource='/rest/testuri/3',
                subresource='4',
                path='sub',
                uri='/rest/testuri/3/sub/4'),
            dict(
                resource='5',
                subresource='/rest/testuri/5/sub/6',
                path='sub',
                uri='/rest/testuri/5/sub/6'),
            dict(
                resource='/rest/testuri/7',
                subresource='/rest/testuri/7/sub/8',
                path='sub',
                uri='/rest/testuri/7/sub/8'),
            dict(
                resource=None,
                subresource='/rest/testuri/9/sub/10',
                path='sub',
                uri='/rest/testuri/9/sub/10'),
            dict(
                resource='/rest/testuri/11',
                subresource='12',
                path='/sub/',
                uri='/rest/testuri/11/sub/12'),
            dict(
                resource='/rest/testuri/13',
                subresource=None,
                path='/sub/',
                uri='/rest/testuri/13/sub'),
        ]

        for option in options:
            uri = self.resource_client.build_subresource_uri(option['resource'], option['subresource'], option['path'])
            self.assertEqual(uri, option['uri'])

    def test_build_subresource_uri_with_subresourceid_and_without_resource_should_fail(self):
        try:
            self.resource_client.build_subresource_uri(None, "123456", 'sub-path')
        except exceptions.HPOneViewValueError as exception:
            self.assertEqual(RESOURCE_ID_OR_URI_REQUIRED, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'get_completed_task')
    def test_create_report_should_do_post_request(self, mock_get_completed_task, mock_post):
        task_with_output = self.task.copy()
        task_with_output['taskOutput'] = []

        mock_post.return_value = self.task, {}
        mock_get_completed_task.return_value = task_with_output

        self.resource_client.create_report("/rest/path/create-report")

        mock_post.assert_called_once_with("/rest/path/create-report", {})

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'get_completed_task')
    def test_create_report_should_wait_task_completion(self, mock_get_completed_task, mock_post):
        task_with_output = self.task.copy()
        task_with_output['taskOutput'] = []

        mock_post.return_value = self.task, {}
        mock_get_completed_task.return_value = task_with_output

        self.resource_client.create_report("/rest/path/create-report", timeout=60)

        mock_get_completed_task.assert_called_once_with(self.task, 60)

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'get_completed_task')
    def test_create_report_should_return_output_list_when_results(self, mock_get_completed_task, mock_post):
        task_output = [
            {"type": "FCIssueResponseV2", "created": "2015-03-24T15: 32: 50.889Z"},
            {"type": "FCIssueResponseV2", "created": "2015-03-13T14: 10: 50.322Z"}
        ]
        task_with_output = self.task.copy()
        task_with_output['taskOutput'] = task_output

        mock_post.return_value = self.task, {}
        mock_get_completed_task.return_value = task_with_output

        result = self.resource_client.create_report("/rest/path/create-report")

        self.assertEqual(result, task_output)

    @mock.patch.object(connection, 'post')
    @mock.patch.object(TaskMonitor, 'get_completed_task')
    def test_create_report_should_return_empty_list_when_output_is_empty(self, mock_get_completed_task, mock_post):
        task_with_output = self.task.copy()
        task_with_output['taskOutput'] = []

        mock_post.return_value = self.task, {}
        mock_get_completed_task.return_value = task_with_output

        result = self.resource_client.create_report("/rest/path/create-report")

        self.assertEqual(result, [])

    @mock.patch.object(connection, 'post')
    def test_create_report_should_raise_exception_when_not_task(self, mock_post):
        task_with_output = self.task.copy()
        task_with_output['taskOutput'] = []

        mock_post.return_value = None, {}

        try:
            self.resource_client.create_report("/rest/path/create-report")
        except exceptions.HPOneViewException as exception:
            self.assertEqual(RESOURCE_CLIENT_TASK_EXPECTED, exception.args[0])
        else:
            self.fail("Expected Exception was not raised")

    @mock.patch.object(connection, 'post')
    def test_create_when_the_resource_is_a_list(self, mock_post):
        dict_to_create = [{"resource_name": "a name"}]
        mock_post.return_value = {}, {}

        resource_client = ResourceClient(self.connection, self.URI)
        resource_client.create(dict_to_create, timeout=-1)

        mock_post.assert_called_once_with(self.URI, dict_to_create, custom_headers=None)

    def test_merge_api_default_values(self):
        resource = {'name': 'resource1'}
        default_values = {
            '200': {"type": "EnclosureGroupV200"},
            '300': {"type": "EnclosureGroupV300"}
        }

        expected = {'name': 'resource1', "type": "EnclosureGroupV300"}

        resource_client = ResourceClient(self.connection, self.URI)
        result = resource_client.merge_default_values(resource, default_values)

        self.assertEqual(result, expected)

    def test_should_not_merge_when_default_values_not_defined(self):
        resource = {'name': 'resource1'}
        default_values = {}

        expected = {'name': 'resource1'}

        resource_client = ResourceClient(self.connection, self.URI)
        result = resource_client.merge_default_values(resource, default_values)

        self.assertEqual(result, expected)

    @mock.patch.object(connection, 'post_multipart_with_response_handling')
    def test_upload_should_call_post_multipart(self, mock_post_multipart):
        uri = '/rest/testuri/'
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, mock.Mock()

        self.resource_client.upload(filepath, uri)

        mock_post_multipart.assert_called_once_with(uri, filepath, 'SPPgen9snap6.2015_0405.81.iso')

    @mock.patch.object(connection, 'post_multipart_with_response_handling')
    def test_upload_should_call_post_multipart_with_resource_uri_when_not_uri_provided(self, mock_post_multipart):
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, mock.Mock()

        self.resource_client.upload(filepath)

        mock_post_multipart.assert_called_once_with('/rest/testuri', mock.ANY, mock.ANY)

    @mock.patch.object(connection, 'post_multipart_with_response_handling')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    @mock.patch.object(connection, 'get')
    def test_upload_should_wait_for_task_when_response_is_task(self, mock_get, mock_wait4task, mock_post_multipart):
        uri = '/rest/testuri/'
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = self.task, mock.Mock()

        self.resource_client.upload(filepath, uri)

        mock_wait4task.assert_called_once_with(self.task, -1)

    @mock.patch.object(connection, 'post_multipart_with_response_handling')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_upload_should_not_wait_for_task_when_response_is_not_task(self, mock_wait4task, mock_post_multipart):
        uri = '/rest/testuri/'
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, mock.Mock()

        self.resource_client.upload(filepath, uri)

        mock_wait4task.not_been_called()

    @mock.patch.object(connection, 'post_multipart_with_response_handling')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    @mock.patch.object(connection, 'get')
    def test_upload_should_return_associated_resource_when_response_is_task(self, mock_get, mock_wait4task,
                                                                            mock_post_multipart):
        fake_associated_resurce = mock.Mock()
        uri = '/rest/testuri/'
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = self.task, mock.Mock()
        mock_wait4task.return_value = fake_associated_resurce

        result = self.resource_client.upload(filepath, uri)

        self.assertEqual(result, fake_associated_resurce)

    @mock.patch.object(connection, 'post_multipart_with_response_handling')
    @mock.patch.object(TaskMonitor, 'wait_for_task')
    def test_upload_should_return_resource_when_response_is_not_task(self, mock_wait4task, mock_post_multipart):
        fake_response_body = mock.Mock()
        uri = '/rest/testuri/'
        filepath = "test/SPPgen9snap6.2015_0405.81.iso"
        mock_post_multipart.return_value = None, fake_response_body

        result = self.resource_client.upload(filepath, uri)

        self.assertEqual(result, fake_response_body)

    @mock.patch.object(connection, 'download_to_stream')
    @mock.patch(mock_builtin('open'))
    def test_download_should_call_download_to_stream_with_given_uri(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = '/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315'
        mock_open.return_value = io.StringIO()

        self.resource_client.download(uri, file_path)

        mock_download_to_stream.assert_called_once_with(mock.ANY, uri, custom_headers=mock.ANY)

    @mock.patch.object(connection, 'download_to_stream')
    @mock.patch(mock_builtin('open'))
    def test_download_should_call_download_to_stream_with_open_file(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = '/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315'
        fake_file = io.StringIO()
        mock_open.return_value = fake_file

        self.resource_client.download(uri, file_path)

        mock_open.assert_called_once_with(file_path, 'wb')
        mock_download_to_stream.assert_called_once_with(fake_file, uri, custom_headers=mock.ANY)

    @mock.patch.object(connection, 'download_to_stream')
    @mock.patch(mock_builtin('open'))
    def test_download_should_return_true_when_success(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = '/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315'
        mock_download_to_stream.return_value = True
        mock_open.return_value = io.StringIO()

        result = self.resource_client.download(uri, file_path)

        self.assertTrue(result)

    @mock.patch.object(connection, 'download_to_stream')
    @mock.patch(mock_builtin('open'))
    def test_download_should_return_false_when_error(self, mock_open, mock_download_to_stream):
        file_path = "~/archive.log"
        uri = '/rest/testuri/3ec91dd2-0ebb-4484-8b2d-90d065114315'
        mock_download_to_stream.return_value = False
        mock_open.return_value = io.StringIO()

        result = self.resource_client.download(uri, file_path)

        self.assertFalse(result)

    def test_transform_list_to_dict(self):
        list = ['one', 'two', {'tree': 3}, 'four', 5]

        dict_transformed = transform_list_to_dict(list=list)

        self.assertEqual(dict_transformed,
                         {'5': True,
                          'four': True,
                          'one': True,
                          'tree': 3,
                          'two': True})

    def test_extract_id_from_uri(self):
        uri = '/rest/plan-scripts/3518be0e-17c1-4189-8f81-83f3724f6155'
        id = '3518be0e-17c1-4189-8f81-83f3724f6155'
        extracted_id = extract_id_from_uri(uri)
        self.assertEqual(id, extracted_id)

    def test_extract_id_from_uri_with_extra_slash(self):
        uri = '/rest/plan-scripts/3518be0e-17c1-4189-8f81-83f3724f6155/'
        extracted_id = extract_id_from_uri(uri)
        self.assertEqual(extracted_id, '')

    def test_extract_id_from_uri_passing_id(self):
        uri = '3518be0e-17c1-4189-8f81-83f3724f6155'
        extracted_id = extract_id_from_uri(uri)
        self.assertEqual(extracted_id, '3518be0e-17c1-4189-8f81-83f3724f6155')

    def test_extract_id_from_uri_unsupported(self):
        # This example is not supported yet
        uri = '/rest/plan-scripts/3518be0e-17c1-4189-8f81-83f3724f6155/otherthing'
        extracted_id = extract_id_from_uri(uri)
        self.assertEqual(extracted_id, 'otherthing')

[((3182, 3252), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (3199, 3252), False, 'import mock\n'), ((3635, 3705), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (3652, 3705), False, 'import mock\n'), ((4081, 4151), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (4098, 4151), False, 'import mock\n'), ((4157, 4204), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (4174, 4204), False, 'import mock\n'), ((4210, 4246), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (4227, 4246), False, 'import mock\n'), ((4638, 4708), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (4655, 4708), False, 'import mock\n'), ((4714, 4761), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (4731, 4761), False, 'import mock\n'), ((5125, 5195), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (5142, 5195), False, 'import mock\n'), ((5201, 5248), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (5218, 5248), False, 'import mock\n'), ((5254, 5290), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (5271, 5290), False, 'import mock\n'), ((5884, 5954), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (5901, 5954), False, 'import mock\n'), ((5960, 6007), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (5977, 6007), False, 'import mock\n'), ((6438, 6489), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (6455, 6489), False, 'import mock\n'), ((6922, 6973), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (6939, 6973), False, 'import mock\n'), ((7501, 7552), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (7518, 7552), False, 'import mock\n'), ((7993, 8044), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (8010, 8044), False, 'import mock\n'), ((8752, 8789), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (8769, 8789), False, 'import mock\n'), ((8795, 8842), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (8812, 8842), False, 'import mock\n'), ((9183, 9220), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (9200, 9220), False, 'import mock\n'), ((9226, 9273), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (9243, 9273), False, 'import mock\n'), ((9636, 9673), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (9653, 9673), False, 'import mock\n'), ((9679, 9726), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (9696, 9726), False, 'import mock\n'), ((10118, 10155), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (10135, 10155), False, 'import mock\n'), ((10161, 10208), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (10178, 10208), False, 'import mock\n'), ((10599, 10636), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (10616, 10636), False, 'import mock\n'), ((10901, 10952), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (10918, 10952), False, 'import mock\n'), ((10958, 10994), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (10975, 10994), False, 'import mock\n'), ((11000, 11047), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (11017, 11047), False, 'import mock\n'), ((11611, 11662), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (11628, 11662), False, 'import mock\n'), ((11668, 11704), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (11685, 11704), False, 'import mock\n'), ((11710, 11757), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (11727, 11757), False, 'import mock\n'), ((12199, 12250), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (12216, 12250), False, 'import mock\n'), ((12256, 12292), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (12273, 12292), False, 'import mock\n'), ((12298, 12345), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (12315, 12345), False, 'import mock\n'), ((12848, 12884), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (12865, 12884), False, 'import mock\n'), ((13510, 13561), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (13527, 13561), False, 'import mock\n'), ((13567, 13605), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (13584, 13605), False, 'import mock\n'), ((14096, 14147), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (14113, 14147), False, 'import mock\n'), ((14153, 14191), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (14170, 14191), False, 'import mock\n'), ((14679, 14730), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (14696, 14730), False, 'import mock\n'), ((14736, 14774), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (14753, 14774), False, 'import mock\n'), ((15258, 15309), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (15275, 15309), False, 'import mock\n'), ((15315, 15353), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (15332, 15353), False, 'import mock\n'), ((15776, 15827), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (15793, 15827), False, 'import mock\n'), ((15833, 15871), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (15850, 15871), False, 'import mock\n'), ((16443, 16494), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (16460, 16494), False, 'import mock\n'), ((16500, 16538), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (16517, 16538), False, 'import mock\n'), ((16544, 16591), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (16561, 16591), False, 'import mock\n'), ((16961, 17012), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (16978, 17012), False, 'import mock\n'), ((17018, 17056), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (17035, 17056), False, 'import mock\n'), ((17062, 17114), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (17079, 17114), False, 'import mock\n'), ((17659, 17710), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (17676, 17710), False, 'import mock\n'), ((17716, 17754), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (17733, 17754), False, 'import mock\n'), ((17760, 17812), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (17777, 17812), False, 'import mock\n'), ((18407, 18458), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (18424, 18458), False, 'import mock\n'), ((18464, 18502), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (18481, 18502), False, 'import mock\n'), ((18508, 18555), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (18525, 18555), False, 'import mock\n'), ((19215, 19266), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (19232, 19266), False, 'import mock\n'), ((19272, 19308), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (19289, 19308), False, 'import mock\n'), ((19994, 20045), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (20011, 20045), False, 'import mock\n'), ((20051, 20087), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (20068, 20087), False, 'import mock\n'), ((20875, 20926), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (20892, 20926), False, 'import mock\n'), ((20932, 20968), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (20949, 20968), False, 'import mock\n'), ((21218, 21269), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (21235, 21269), False, 'import mock\n'), ((21275, 21311), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (21292, 21311), False, 'import mock\n'), ((21822, 21858), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (21839, 21858), False, 'import mock\n'), ((22326, 22369), 'mock.patch.object', 'mock.patch.object', (['ResourceHelper', '"""do_put"""'], {}), "(ResourceHelper, 'do_put')\n", (22343, 22369), False, 'import mock\n'), ((22375, 22426), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (22392, 22426), False, 'import mock\n'), ((22980, 23023), 'mock.patch.object', 'mock.patch.object', (['ResourceHelper', '"""do_get"""'], {}), "(ResourceHelper, 'do_get')\n", (22997, 23023), False, 'import mock\n'), ((23360, 23397), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""get_by"""'], {}), "(Resource, 'get_by')\n", (23377, 23397), False, 'import mock\n'), ((23737, 23780), 'mock.patch.object', 'mock.patch.object', (['ResourceHelper', '"""do_get"""'], {}), "(ResourceHelper, 'do_get')\n", (23754, 23780), False, 'import mock\n'), ((23786, 23823), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""get_by"""'], {}), "(Resource, 'get_by')\n", (23803, 23823), False, 'import mock\n'), ((24254, 24291), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""get_by"""'], {}), "(Resource, 'get_by')\n", (24271, 24291), False, 'import mock\n'), ((24578, 24614), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (24595, 24614), False, 'import mock\n'), ((25334, 25370), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (25351, 25370), False, 'import mock\n'), ((25593, 25629), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (25610, 25629), False, 'import mock\n'), ((25886, 25922), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (25903, 25922), False, 'import mock\n'), ((26220, 26256), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (26237, 26256), False, 'import mock\n'), ((26629, 26665), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (26646, 26665), False, 'import mock\n'), ((27433, 27469), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (27450, 27469), False, 'import mock\n'), ((28256, 28292), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (28273, 28292), False, 'import mock\n'), ((29080, 29116), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (29097, 29116), False, 'import mock\n'), ((29931, 29967), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (29948, 29967), False, 'import mock\n'), ((30829, 30865), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (30846, 30865), False, 'import mock\n'), ((31354, 31390), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (31371, 31390), False, 'import mock\n'), ((31643, 31679), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (31660, 31679), False, 'import mock\n'), ((31923, 31966), 'mock.patch.object', 'mock.patch.object', (['ResourceHelper', '"""do_get"""'], {}), "(ResourceHelper, 'do_get')\n", (31940, 31966), False, 'import mock\n'), ((32224, 32261), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (32241, 32261), False, 'import mock\n'), ((32632, 32669), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (32649, 32669), False, 'import mock\n'), ((33153, 33190), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (33170, 33190), False, 'import mock\n'), ((33586, 33623), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (33603, 33623), False, 'import mock\n'), ((34030, 34067), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (34047, 34067), False, 'import mock\n'), ((34446, 34483), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (34463, 34483), False, 'import mock\n'), ((34838, 34875), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (34855, 34875), False, 'import mock\n'), ((35115, 35152), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (35132, 35152), False, 'import mock\n'), ((35158, 35205), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (35175, 35205), False, 'import mock\n'), ((35512, 35563), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (35529, 35563), False, 'import mock\n'), ((35569, 35608), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (35586, 35608), False, 'import mock\n'), ((35896, 35935), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (35913, 35935), False, 'import mock\n'), ((36235, 36286), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (36252, 36286), False, 'import mock\n'), ((36292, 36331), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (36309, 36331), False, 'import mock\n'), ((36337, 36384), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (36354, 36384), False, 'import mock\n'), ((36796, 36847), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (36813, 36847), False, 'import mock\n'), ((36853, 36892), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (36870, 36892), False, 'import mock\n'), ((36898, 36945), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (36915, 36945), False, 'import mock\n'), ((37396, 37447), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (37413, 37447), False, 'import mock\n'), ((37453, 37489), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (37470, 37489), False, 'import mock\n'), ((38045, 38096), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (38062, 38096), False, 'import mock\n'), ((38102, 38138), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (38119, 38138), False, 'import mock\n'), ((38518, 38569), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (38535, 38569), False, 'import mock\n'), ((38575, 38611), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (38592, 38611), False, 'import mock\n'), ((39062, 39113), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (39079, 39113), False, 'import mock\n'), ((39119, 39155), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (39136, 39155), False, 'import mock\n'), ((39643, 39694), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (39660, 39694), False, 'import mock\n'), ((39700, 39736), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (39717, 39736), False, 'import mock\n'), ((40195, 40246), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (40212, 40246), False, 'import mock\n'), ((40252, 40288), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (40269, 40288), False, 'import mock\n'), ((40704, 40755), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (40721, 40755), False, 'import mock\n'), ((40761, 40797), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (40778, 40797), False, 'import mock\n'), ((40803, 40850), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (40820, 40850), False, 'import mock\n'), ((41443, 41494), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""ensure_resource_data"""'], {}), "(Resource, 'ensure_resource_data')\n", (41460, 41494), False, 'import mock\n'), ((41500, 41536), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (41517, 41536), False, 'import mock\n'), ((41542, 41589), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (41559, 41589), False, 'import mock\n'), ((42013, 42050), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""get_by"""'], {}), "(Resource, 'get_by')\n", (42030, 42050), False, 'import mock\n'), ((42243, 42280), 'mock.patch.object', 'mock.patch.object', (['Resource', '"""get_by"""'], {}), "(Resource, 'get_by')\n", (42260, 42280), False, 'import mock\n'), ((42561, 42597), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (42578, 42597), False, 'import mock\n'), ((42760, 42796), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (42777, 42796), False, 'import mock\n'), ((42963, 42999), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (42980, 42999), False, 'import mock\n'), ((43251, 43287), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (43268, 43287), False, 'import mock\n'), ((43524, 43560), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (43541, 43560), False, 'import mock\n'), ((43800, 43836), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (43817, 43836), False, 'import mock\n'), ((44054, 44090), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (44071, 44090), False, 'import mock\n'), ((44408, 44444), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (44425, 44444), False, 'import mock\n'), ((50353, 50389), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (50370, 50389), False, 'import mock\n'), ((51440, 51476), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (51457, 51476), False, 'import mock\n'), ((51699, 51735), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (51716, 51735), False, 'import mock\n'), ((51992, 52028), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (52009, 52028), False, 'import mock\n'), ((52326, 52362), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (52343, 52362), False, 'import mock\n'), ((52735, 52771), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (52752, 52771), False, 'import mock\n'), ((53539, 53575), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (53556, 53575), False, 'import mock\n'), ((54362, 54398), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (54379, 54398), False, 'import mock\n'), ((55186, 55222), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (55203, 55222), False, 'import mock\n'), ((56037, 56073), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (56054, 56073), False, 'import mock\n'), ((56935, 56971), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (56952, 56971), False, 'import mock\n'), ((57460, 57496), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (57477, 57496), False, 'import mock\n'), ((57749, 57785), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (57766, 57785), False, 'import mock\n'), ((58029, 58068), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (58046, 58068), False, 'import mock\n'), ((58074, 58121), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (58091, 58121), False, 'import mock\n'), ((58564, 58603), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (58581, 58603), False, 'import mock\n'), ((58897, 58936), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (58914, 58936), False, 'import mock\n'), ((58942, 58989), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (58959, 58989), False, 'import mock\n'), ((59441, 59480), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (59458, 59480), False, 'import mock\n'), ((59486, 59533), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (59503, 59533), False, 'import mock\n'), ((59950, 59989), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (59967, 59989), False, 'import mock\n'), ((59995, 60042), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (60012, 60042), False, 'import mock\n'), ((60774, 60810), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (60791, 60810), False, 'import mock\n'), ((60967, 61003), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (60984, 61003), False, 'import mock\n'), ((61158, 61201), 'mock.patch.object', 'mock.patch.object', (['ResourceClient', '"""get_by"""'], {}), "(ResourceClient, 'get_by')\n", (61175, 61201), False, 'import mock\n'), ((61514, 61557), 'mock.patch.object', 'mock.patch.object', (['ResourceClient', '"""get_by"""'], {}), "(ResourceClient, 'get_by')\n", (61531, 61557), False, 'import mock\n'), ((61838, 61874), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (61855, 61874), False, 'import mock\n'), ((62129, 62165), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (62146, 62165), False, 'import mock\n'), ((62413, 62449), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (62430, 62449), False, 'import mock\n'), ((62775, 62811), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (62792, 62811), False, 'import mock\n'), ((63077, 63121), 'mock.patch.object', 'mock.patch.object', (['ResourceClient', '"""get_all"""'], {}), "(ResourceClient, 'get_all')\n", (63094, 63121), False, 'import mock\n'), ((63342, 63386), 'mock.patch.object', 'mock.patch.object', (['ResourceClient', '"""get_all"""'], {}), "(ResourceClient, 'get_all')\n", (63359, 63386), False, 'import mock\n'), ((63810, 63854), 'mock.patch.object', 'mock.patch.object', (['ResourceClient', '"""get_all"""'], {}), "(ResourceClient, 'get_all')\n", (63827, 63854), False, 'import mock\n'), ((64331, 64375), 'mock.patch.object', 'mock.patch.object', (['ResourceClient', '"""get_all"""'], {}), "(ResourceClient, 'get_all')\n", (64348, 64375), False, 'import mock\n'), ((64650, 64694), 'mock.patch.object', 'mock.patch.object', (['ResourceClient', '"""get_all"""'], {}), "(ResourceClient, 'get_all')\n", (64667, 64694), False, 'import mock\n'), ((65048, 65084), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (65065, 65084), False, 'import mock\n'), ((65090, 65137), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (65107, 65137), False, 'import mock\n'), ((65624, 65660), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (65641, 65660), False, 'import mock\n'), ((65666, 65713), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (65683, 65713), False, 'import mock\n'), ((66116, 66152), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (66133, 66152), False, 'import mock\n'), ((66158, 66205), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (66175, 66205), False, 'import mock\n'), ((66632, 66668), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (66649, 66668), False, 'import mock\n'), ((66984, 67020), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (67001, 67020), False, 'import mock\n'), ((67432, 67468), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (67449, 67468), False, 'import mock\n'), ((67840, 67876), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (67857, 67876), False, 'import mock\n'), ((68289, 68325), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (68306, 68325), False, 'import mock\n'), ((68814, 68850), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (68831, 68850), False, 'import mock\n'), ((69305, 69341), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (69322, 69341), False, 'import mock\n'), ((69765, 69801), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (69782, 69801), False, 'import mock\n'), ((70213, 70249), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (70230, 70249), False, 'import mock\n'), ((70255, 70302), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (70272, 70302), False, 'import mock\n'), ((70798, 70834), 'mock.patch.object', 'mock.patch.object', (['connection', '"""put"""'], {}), "(connection, 'put')\n", (70815, 70834), False, 'import mock\n'), ((70840, 70887), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (70857, 70887), False, 'import mock\n'), ((71288, 71325), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (71305, 71325), False, 'import mock\n'), ((71331, 71378), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (71348, 71378), False, 'import mock\n'), ((71857, 71894), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (71874, 71894), False, 'import mock\n'), ((71900, 71947), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (71917, 71947), False, 'import mock\n'), ((72310, 72347), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (72327, 72347), False, 'import mock\n'), ((72353, 72400), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (72370, 72400), False, 'import mock\n'), ((72797, 72834), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (72814, 72834), False, 'import mock\n'), ((72840, 72887), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (72857, 72887), False, 'import mock\n'), ((73316, 73353), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (73333, 73353), False, 'import mock\n'), ((73671, 73708), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (73688, 73708), False, 'import mock\n'), ((74004, 74041), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (74021, 74041), False, 'import mock\n'), ((74407, 74444), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (74424, 74444), False, 'import mock\n'), ((74911, 74948), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (74928, 74948), False, 'import mock\n'), ((75381, 75418), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (75398, 75418), False, 'import mock\n'), ((75798, 75835), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (75815, 75835), False, 'import mock\n'), ((76214, 76251), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (76231, 76251), False, 'import mock\n'), ((76606, 76643), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (76623, 76643), False, 'import mock\n'), ((76649, 76696), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (76666, 76696), False, 'import mock\n'), ((77180, 77217), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (77197, 77217), False, 'import mock\n'), ((77223, 77270), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (77240, 77270), False, 'import mock\n'), ((77577, 77615), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (77594, 77615), False, 'import mock\n'), ((78118, 78156), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (78135, 78156), False, 'import mock\n'), ((78724, 78762), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (78741, 78762), False, 'import mock\n'), ((79277, 79315), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (79294, 79315), False, 'import mock\n'), ((79738, 79776), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (79755, 79776), False, 'import mock\n'), ((80406, 80444), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (80423, 80444), False, 'import mock\n'), ((80450, 80497), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (80467, 80497), False, 'import mock\n'), ((80865, 80903), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (80882, 80903), False, 'import mock\n'), ((80909, 80961), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (80926, 80961), False, 'import mock\n'), ((81550, 81588), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (81567, 81588), False, 'import mock\n'), ((81594, 81646), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (81611, 81646), False, 'import mock\n'), ((82284, 82322), 'mock.patch.object', 'mock.patch.object', (['connection', '"""patch"""'], {}), "(connection, 'patch')\n", (82301, 82322), False, 'import mock\n'), ((82328, 82375), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (82345, 82375), False, 'import mock\n'), ((82988, 83027), 'mock.patch.object', 'mock.patch.object', (['connection', '"""delete"""'], {}), "(connection, 'delete')\n", (83005, 83027), False, 'import mock\n'), ((85118, 85154), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (85135, 85154), False, 'import mock\n'), ((86346, 86382), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (86363, 86382), False, 'import mock\n'), ((87075, 87111), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (87092, 87111), False, 'import mock\n'), ((87919, 87955), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (87936, 87955), False, 'import mock\n'), ((88210, 88246), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (88227, 88246), False, 'import mock\n'), ((92585, 92622), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (92602, 92622), False, 'import mock\n'), ((92628, 92680), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (92645, 92680), False, 'import mock\n'), ((93127, 93164), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (93144, 93164), False, 'import mock\n'), ((93170, 93222), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (93187, 93222), False, 'import mock\n'), ((93683, 93720), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (93700, 93720), False, 'import mock\n'), ((93726, 93778), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (93743, 93778), False, 'import mock\n'), ((94432, 94469), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (94449, 94469), False, 'import mock\n'), ((94475, 94527), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""get_completed_task"""'], {}), "(TaskMonitor, 'get_completed_task')\n", (94492, 94527), False, 'import mock\n'), ((94969, 95006), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (94986, 95006), False, 'import mock\n'), ((95526, 95563), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post"""'], {}), "(connection, 'post')\n", (95543, 95563), False, 'import mock\n'), ((96813, 96883), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (96830, 96883), False, 'import mock\n'), ((97266, 97336), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (97283, 97336), False, 'import mock\n'), ((97712, 97782), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (97729, 97782), False, 'import mock\n'), ((97788, 97835), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (97805, 97835), False, 'import mock\n'), ((97841, 97877), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (97858, 97877), False, 'import mock\n'), ((98269, 98339), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (98286, 98339), False, 'import mock\n'), ((98345, 98392), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (98362, 98392), False, 'import mock\n'), ((98756, 98826), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (98773, 98826), False, 'import mock\n'), ((98832, 98879), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (98849, 98879), False, 'import mock\n'), ((98885, 98921), 'mock.patch.object', 'mock.patch.object', (['connection', '"""get"""'], {}), "(connection, 'get')\n", (98902, 98921), False, 'import mock\n'), ((99515, 99585), 'mock.patch.object', 'mock.patch.object', (['connection', '"""post_multipart_with_response_handling"""'], {}), "(connection, 'post_multipart_with_response_handling')\n", (99532, 99585), False, 'import mock\n'), ((99591, 99638), 'mock.patch.object', 'mock.patch.object', (['TaskMonitor', '"""wait_for_task"""'], {}), "(TaskMonitor, 'wait_for_task')\n", (99608, 99638), False, 'import mock\n'), ((100069, 100120), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (100086, 100120), False, 'import mock\n'), ((100578, 100629), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (100595, 100629), False, 'import mock\n'), ((101177, 101228), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (101194, 101228), False, 'import mock\n'), ((101669, 101720), 'mock.patch.object', 'mock.patch.object', (['connection', '"""download_to_stream"""'], {}), "(connection, 'download_to_stream')\n", (101686, 101720), False, 'import mock\n'), ((2997, 3025), 'hpOneView.connection.connection', 'connection', (['"""127.0.0.1"""', '(300)'], {}), "('127.0.0.1', 300)\n", (3007, 3025), False, 'from hpOneView.connection import connection\n'), ((5531, 5542), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (5540, 5542), False, 'import mock\n'), ((6150, 6161), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (6159, 6161), False, 'import mock\n'), ((6775, 6788), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (6786, 6788), False, 'import io\n'), ((6506, 6526), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (6518, 6526), False, 'from tests.test_utils import mock_builtin\n'), ((7246, 7259), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (7257, 7259), False, 'import io\n'), ((6990, 7010), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (7002, 7010), False, 'from tests.test_utils import mock_builtin\n'), ((7876, 7889), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (7887, 7889), False, 'import io\n'), ((7569, 7589), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (7581, 7589), False, 'from tests.test_utils import mock_builtin\n'), ((8368, 8381), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (8379, 8381), False, 'import io\n'), ((8061, 8081), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (8073, 8081), False, 'from tests.test_utils import mock_builtin\n'), ((8573, 8601), 'hpOneView.connection.connection', 'connection', (['"""127.0.0.1"""', '(300)'], {}), "('127.0.0.1', 300)\n", (8583, 8601), False, 'from hpOneView.connection import connection\n'), ((13337, 13365), 'hpOneView.connection.connection', 'connection', (['"""127.0.0.1"""', '(300)'], {}), "('127.0.0.1', 300)\n", (13347, 13365), False, 'from hpOneView.connection import connection\n'), ((19030, 19058), 'hpOneView.connection.connection', 'connection', (['"""127.0.0.1"""', '(300)'], {}), "('127.0.0.1', 300)\n", (19040, 19058), False, 'from hpOneView.connection import connection\n'), ((21647, 21675), 'hpOneView.connection.connection', 'connection', (['"""127.0.0.1"""', '(300)'], {}), "('127.0.0.1', 300)\n", (21657, 21675), False, 'from hpOneView.connection import connection\n'), ((22089, 22117), 'hpOneView.connection.connection', 'connection', (['"""127.0.0.1"""', '(300)'], {}), "('127.0.0.1', 300)\n", (22099, 22117), False, 'from hpOneView.connection import connection\n'), ((22272, 22319), 'hpOneView.resources.resource.ResourceHelper', 'ResourceHelper', (['self.URI', 'self.connection', 'None'], {}), '(self.URI, self.connection, None)\n', (22286, 22319), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((34249, 34290), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (34263, 34290), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((48791, 48828), 'hpOneView.resources.resource.merge_resources', 'merge_resources', (['resource1', 'resource2'], {}), '(resource1, resource2)\n', (48806, 48828), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((49080, 49138), 'hpOneView.resources.resource.merge_default_values', 'merge_default_values', (['[resource1, resource2]', 'default_type'], {}), '([resource1, resource2], default_type)\n', (49100, 49138), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((49613, 49655), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['con', '"""/rest/fake/resource"""'], {}), "(con, '/rest/fake/resource')\n", (49627, 49655), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((50080, 50106), 'hpOneView.connection.connection', 'connection', (['self.host', '(300)'], {}), '(self.host, 300)\n', (50090, 50106), False, 'from hpOneView.connection import connection\n'), ((50138, 50179), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (50152, 50179), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((70025, 70066), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (70039, 70066), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((76017, 76058), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (76031, 76058), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((78424, 78465), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (78438, 78465), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((79908, 79949), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (79922, 79949), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((81305, 81346), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (81319, 81346), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((81916, 81957), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (81930, 81957), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((95752, 95793), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (95766, 95793), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((96267, 96308), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (96281, 96308), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((96641, 96682), 'hpOneView.resources.resource.ResourceClient', 'ResourceClient', (['self.connection', 'self.URI'], {}), '(self.connection, self.URI)\n', (96655, 96682), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((99162, 99173), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (99171, 99173), False, 'import mock\n'), ((99781, 99792), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (99790, 99792), False, 'import mock\n'), ((100406, 100419), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (100417, 100419), False, 'import io\n'), ((100137, 100157), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (100149, 100157), False, 'from tests.test_utils import mock_builtin\n'), ((100902, 100915), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (100913, 100915), False, 'import io\n'), ((100646, 100666), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (100658, 100666), False, 'from tests.test_utils import mock_builtin\n'), ((101552, 101565), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (101563, 101565), False, 'import io\n'), ((101245, 101265), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (101257, 101265), False, 'from tests.test_utils import mock_builtin\n'), ((102044, 102057), 'io.StringIO', 'io.StringIO', ([], {}), '()\n', (102055, 102057), False, 'import io\n'), ((101737, 101757), 'tests.test_utils.mock_builtin', 'mock_builtin', (['"""open"""'], {}), "('open')\n", (101749, 101757), False, 'from tests.test_utils import mock_builtin\n'), ((102282, 102315), 'hpOneView.resources.resource.transform_list_to_dict', 'transform_list_to_dict', ([], {'list': 'list'}), '(list=list)\n', (102304, 102315), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((102741, 102765), 'hpOneView.resources.resource.extract_id_from_uri', 'extract_id_from_uri', (['uri'], {}), '(uri)\n', (102760, 102765), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((102963, 102987), 'hpOneView.resources.resource.extract_id_from_uri', 'extract_id_from_uri', (['uri'], {}), '(uri)\n', (102982, 102987), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((103159, 103183), 'hpOneView.resources.resource.extract_id_from_uri', 'extract_id_from_uri', (['uri'], {}), '(uri)\n', (103178, 103183), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((103466, 103490), 'hpOneView.resources.resource.extract_id_from_uri', 'extract_id_from_uri', (['uri'], {}), '(uri)\n', (103485, 103490), False, 'from hpOneView.resources.resource import ResourceClient, ResourceHelper, ResourceFileHandlerMixin, ResourceZeroBodyMixin, ResourcePatchMixin, ResourceUtilizationMixin, ResourceSchemaMixin, Resource, RESOURCE_CLIENT_INVALID_ID, UNRECOGNIZED_URI, TaskMonitor, RESOURCE_CLIENT_TASK_EXPECTED, RESOURCE_ID_OR_URI_REQUIRED, transform_list_to_dict, extract_id_from_uri, merge_resources, merge_default_values, unavailable_method\n'), ((3464, 3475), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (3473, 3475), False, 'import mock\n'), ((3926, 3937), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (3935, 3937), False, 'import mock\n'), ((4505, 4516), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (4514, 4516), False, 'import mock\n'), ((5013, 5024), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (5022, 5024), False, 'import mock\n'), ((5684, 5695), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (5693, 5695), False, 'import mock\n'), ((27304, 27321), 'mock.call', 'call', (['uri_list[0]'], {}), '(uri_list[0])\n', (27308, 27321), False, 'from mock import call\n'), ((27323, 27340), 'mock.call', 'call', (['uri_list[1]'], {}), '(uri_list[1])\n', (27327, 27340), False, 'from mock import call\n'), ((27342, 27359), 'mock.call', 'call', (['uri_list[2]'], {}), '(uri_list[2])\n', (27346, 27359), False, 'from mock import call\n'), ((28127, 28144), 'mock.call', 'call', (['uri_list[0]'], {}), '(uri_list[0])\n', (28131, 28144), False, 'from mock import call\n'), ((28146, 28163), 'mock.call', 'call', (['uri_list[1]'], {}), '(uri_list[1])\n', (28150, 28163), False, 'from mock import call\n'), ((28165, 28182), 'mock.call', 'call', (['uri_list[2]'], {}), '(uri_list[2])\n', (28169, 28182), False, 'from mock import call\n'), ((53410, 53427), 'mock.call', 'call', (['uri_list[0]'], {}), '(uri_list[0])\n', (53414, 53427), False, 'from mock import call\n'), ((53429, 53446), 'mock.call', 'call', (['uri_list[1]'], {}), '(uri_list[1])\n', (53433, 53446), False, 'from mock import call\n'), ((53448, 53465), 'mock.call', 'call', (['uri_list[2]'], {}), '(uri_list[2])\n', (53452, 53465), False, 'from mock import call\n'), ((54233, 54250), 'mock.call', 'call', (['uri_list[0]'], {}), '(uri_list[0])\n', (54237, 54250), False, 'from mock import call\n'), ((54252, 54269), 'mock.call', 'call', (['uri_list[1]'], {}), '(uri_list[1])\n', (54256, 54269), False, 'from mock import call\n'), ((54271, 54288), 'mock.call', 'call', (['uri_list[2]'], {}), '(uri_list[2])\n', (54275, 54288), False, 'from mock import call\n'), ((97095, 97106), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (97104, 97106), False, 'import mock\n'), ((97557, 97568), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (97566, 97568), False, 'import mock\n'), ((98136, 98147), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (98145, 98147), False, 'import mock\n'), ((98644, 98655), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (98653, 98655), False, 'import mock\n'), ((99315, 99326), 'mock.Mock', 'mock.Mock', ([], {}), '()\n', (99324, 99326), False, 'import mock\n')]