def managed_sans(self): """ Gets the Managed SANs API client. Returns: ManagedSANs: """ return ManagedSANs(self.__connection)
def managed_sans(self): """ Gets the Managed SANs API client. Returns: ManagedSANs: """ if not self.__managed_sans: self.__managed_sans = ManagedSANs(self.__connection) return self.__managed_sans
def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ManagedSANs(http_connection)
class ManagedSANsTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ManagedSANs(http_connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get_all): query_filter = "name EQ 'TestName'" sort = 'name:ascending' self._resource.get_all(start=2, count=500, query=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, query=query_filter, sort=sort) @mock.patch.object(ResourceClient, 'get_all') def test_get_by_name_should_return_san_manager_when_found(self, mock_get_all): mock_get_all.return_value = [ {"name": "SAN1_0", "uri": "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC"}, {"name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6"} ] managed_san = self._resource.get_by_name("SAN1_1") expected_result = {"name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6"} self.assertEqual(managed_san, expected_result) @mock.patch.object(ResourceClient, 'get_all') def test_get_by_name_should_return_null_when_not_found(self, mock_get_all): mock_get_all.return_value = [ {"name": "SAN1_0", "uri": "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC"}, {"name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6"} ] managed_san = self._resource.get_by_name("SAN1_3") self.assertIsNone(managed_san) @mock.patch.object(ResourceClient, 'get') def test_get_by_id(self, mock_get): id = "280FF951-F007-478F-AC29-E4655FC76DDC" self._resource.get(id) mock_get.assert_called_once_with(id_or_uri=id) @mock.patch.object(ResourceClient, 'update') def test_update_with_uri(self, mock_update): uri = "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" data = {"attributes": "values"} self._resource.update(uri, data) mock_update.assert_called_once_with(data, timeout=-1, uri=uri) @mock.patch.object(ResourceClient, 'update') def test_update_with_id(self, mock_update): uri = "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" data = {"attributes": "values"} self._resource.update("280FF951-F007-478F-AC29-E4655FC76DDC", data) mock_update.assert_called_once_with(data, timeout=-1, uri=uri) @mock.patch.object(ResourceClient, 'get_all') def test_get_endpoints_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' managed_san_id = '280FF951-F007-478F-AC29-E4655FC76DDC' uri = '/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC/endpoints/' self._resource.get_endpoints(managed_san_id, 2, 500, filter, sort) mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort, uri=uri) @mock.patch.object(ResourceClient, 'get_all') def test_get_endpoints_called_once_with_default(self, mock_get_all): managed_san_id = '280FF951-F007-478F-AC29-E4655FC76DDC' uri = '/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC/endpoints/' self._resource.get_endpoints(managed_san_id) mock_get_all.assert_called_once_with(0, -1, filter='', sort='', uri=uri) @mock.patch.object(ResourceClient, 'create_with_zero_body') def test_create_endpoints_csv_file_called_once_when_id_provided(self, mock_create_with_zero_body): id = '280FF951-F007-478F-AC29-E4655FC76DDC' self._resource.create_endpoints_csv_file(id) expected_uri = '/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC/endpoints/' mock_create_with_zero_body.assert_called_once_with(uri=expected_uri, timeout=-1) @mock.patch.object(ResourceClient, 'create_with_zero_body') def test_create_endpoints_csv_file_called_once_when_uri_provided(self, mock_create_with_zero_body): uri = "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" self._resource.create_endpoints_csv_file(uri) expected_uri = '/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC/endpoints/' mock_create_with_zero_body.assert_called_once_with(uri=expected_uri, timeout=-1) @mock.patch.object(ResourceClient, 'create_report') def test_create_issues_report_called_once_when_id_provided(self, mock_create_report): id = '280FF951-F007-478F-AC29-E4655FC76DDC' self._resource.create_issues_report(id) expected_uri = '/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC/issues/' mock_create_report.assert_called_once_with(uri=expected_uri, timeout=-1) @mock.patch.object(ResourceClient, 'create_report') def test_create_issues_report_called_once_when_uri_provided(self, mock_create_report): uri = "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" self._resource.create_issues_report(uri) expected_uri = '/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC/issues/' mock_create_report.assert_called_once_with(uri=expected_uri, timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_wwn(self, mock_get): wwn = "20:00:4A:2B:21:E0:00:00" self._resource.get_wwn(wwn) uri = "/rest/fc-sans/managed-sans?locate=20:00:4A:2B:21:E0:00:00" mock_get.assert_called_once_with(uri)
def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ManagedSANs(http_connection) self.uri = "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" self._resource.data = {"uri": self.uri}
class ManagedSANsTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ManagedSANs(http_connection) self.uri = "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" self._resource.data = {"uri": self.uri} @mock.patch.object(ResourceHelper, 'get_all') def test_get_all(self, mock_get_all): query_filter = "name EQ 'TestName'" sort = 'name:ascending' self._resource.get_all(start=2, count=500, query=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, query=query_filter, sort=sort) @mock.patch.object(ResourceHelper, 'get_all') def test_get_by_name_should_return_san_manager_when_found(self, mock_get_all): mock_get_all.return_value = [ {"name": "SAN1_0", "uri": "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC"}, {"name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6"} ] managed_san = self._resource.get_by_name("SAN1_1") expected_result = {"name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6"} self.assertEqual(managed_san.data, expected_result) @mock.patch.object(ResourceHelper, 'get_all') def test_get_by_name_should_return_null_when_not_found(self, mock_get_all): mock_get_all.return_value = [ {"name": "SAN1_0", "uri": "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC"}, {"name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6"} ] managed_san = self._resource.get_by_name("SAN1_3") self.assertIsNone(managed_san) @mock.patch.object(Resource, 'ensure_resource_data') @mock.patch.object(ResourceHelper, 'update') def test_update(self, mock_update, mock_ensure_client_data): uri = self._resource.data["uri"] data = {"attributes": "values"} self._resource.update(data) data["uri"] = uri mock_update.assert_called_once_with(data, uri, False, -1, None) @mock.patch.object(ResourceHelper, 'get_all') def test_get_endpoints_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' uri = '{}/endpoints/'.format(self._resource.data["uri"]) self._resource.get_endpoints(2, 500, filter, sort) mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort, uri=uri) @mock.patch.object(ResourceHelper, 'get_all') def test_get_endpoints_called_once_with_default(self, mock_get_all): uri = '{}/endpoints/'.format(self._resource.data["uri"]) self._resource.get_endpoints() mock_get_all.assert_called_once_with(0, -1, filter='', sort='', uri=uri) @mock.patch.object(ResourceHelper, 'do_post') def test_create_endpoints_csv_file_called_once_when_id_provided(self, mock_do_post): self._resource.create_endpoints_csv_file() expected_uri = '{}/endpoints/'.format(self._resource.data["uri"]) mock_do_post.assert_called_once_with(expected_uri, {}, -1, None) @mock.patch.object(ResourceHelper, 'do_post') def test_create_endpoints_csv_file_called_once_when_uri_provided(self, mock_do_post): self._resource.create_endpoints_csv_file() expected_uri = '{}/endpoints/'.format(self._resource.data["uri"]) mock_do_post.assert_called_once_with(expected_uri, {}, -1, None) @mock.patch.object(ResourceHelper, 'create_report') def test_create_issues_report_called_once(self, mock_create_report): self._resource.create_issues_report() expected_uri = '{}/issues/'.format(self._resource.data["uri"]) mock_create_report.assert_called_once_with(expected_uri, -1) @mock.patch.object(ResourceHelper, 'create_report') def test_create_issues_report_called_once_when_uri_provided(self, mock_create_report): self._resource.create_issues_report() expected_uri = '{}/issues/'.format(self._resource.data["uri"]) mock_create_report.assert_called_once_with(expected_uri, -1)
class ManagedSANsTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ManagedSANs(http_connection) self.uri = "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" self._resource.data = {"uri": self.uri} @mock.patch.object(ResourceHelper, 'get_all') def test_get_all(self, mock_get_all): query_filter = "name EQ 'TestName'" sort = 'name:ascending' self._resource.get_all(start=2, count=500, query=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, query=query_filter, sort=sort) @mock.patch.object(ResourceHelper, 'get_all') def test_get_by_name_should_return_san_manager_when_found( self, mock_get_all): mock_get_all.return_value = [{ "name": "SAN1_0", "uri": "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" }, { "name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6" }] managed_san = self._resource.get_by_name("SAN1_1") expected_result = { "name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6" } self.assertEqual(managed_san.data, expected_result) @mock.patch.object(ResourceHelper, 'get_all') def test_get_by_name_should_return_null_when_not_found(self, mock_get_all): mock_get_all.return_value = [{ "name": "SAN1_0", "uri": "/rest/fc-sans/managed-sans/280FF951-F007-478F-AC29-E4655FC76DDC" }, { "name": "SAN1_1", "uri": "/rest/fc-sans/managed-sans/6fee02f3-b7c7-42bd-a528-04341e16bad6" }] managed_san = self._resource.get_by_name("SAN1_3") self.assertIsNone(managed_san) @mock.patch.object(Resource, 'ensure_resource_data') @mock.patch.object(ResourceHelper, 'update') def test_update(self, mock_update, mock_ensure_client_data): uri = self._resource.data["uri"] data = {"attributes": "values"} self._resource.update(data) data["uri"] = uri mock_update.assert_called_once_with(data, uri, False, -1, None) @mock.patch.object(ResourceHelper, 'get_all') def test_get_endpoints_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' uri = '{}/endpoints/'.format(self._resource.data["uri"]) self._resource.get_endpoints(2, 500, filter, sort) mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort, uri=uri) @mock.patch.object(ResourceHelper, 'get_all') def test_get_endpoints_called_once_with_default(self, mock_get_all): uri = '{}/endpoints/'.format(self._resource.data["uri"]) self._resource.get_endpoints() mock_get_all.assert_called_once_with(0, -1, filter='', sort='', uri=uri) @mock.patch.object(ResourceHelper, 'do_post') def test_create_endpoints_csv_file_called_once_when_id_provided( self, mock_do_post): self._resource.create_endpoints_csv_file() expected_uri = '{}/endpoints/'.format(self._resource.data["uri"]) mock_do_post.assert_called_once_with(expected_uri, {}, -1, None) @mock.patch.object(ResourceHelper, 'do_post') def test_create_endpoints_csv_file_called_once_when_uri_provided( self, mock_do_post): self._resource.create_endpoints_csv_file() expected_uri = '{}/endpoints/'.format(self._resource.data["uri"]) mock_do_post.assert_called_once_with(expected_uri, {}, -1, None) @mock.patch.object(ResourceHelper, 'create_report') def test_create_issues_report_called_once(self, mock_create_report): self._resource.create_issues_report() expected_uri = '{}/issues/'.format(self._resource.data["uri"]) mock_create_report.assert_called_once_with(expected_uri, -1) @mock.patch.object(ResourceHelper, 'create_report') def test_create_issues_report_called_once_when_uri_provided( self, mock_create_report): self._resource.create_issues_report() expected_uri = '{}/issues/'.format(self._resource.data["uri"]) mock_create_report.assert_called_once_with(expected_uri, -1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_wwn_called_once(self, mock_get): uri = '/rest/fc-sans/managed-sans?locate=test' self._resource.get_wwn('test') mock_get.assert_called_once_with(uri)