class IndexResourcesTest(unittest.TestCase): INDEX_RESOURCE = dict( uri="/rest/index/resources/rest/resource/uri", resourceUri="/rest/resource/uri", type="IndexResourceV300", category="the-resource-category", created="2014-03-31T02:08:27.884Z", modified="2014-03-31T02:08:27.884Z", eTag=None, members=[{'name': 'sh1'}, {'name': 'sh2'}] ) def return_index(self): return self.INDEX_RESOURCE def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host, 800) self._resource = IndexResources(self.connection) @mock.patch.object(ResourceClient, 'get_all', return_value=dict(members='test')) def test_get_all_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' expected_uri = '/rest/index/resources?filter=name=TestName&sort=name:ascending' self._resource.get_all(start=2, count=500, filter=filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, uri=expected_uri) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_called_once_without_results(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' expected_uri = '/rest/index/resources?filter=name=TestName&sort=name:ascending' self._resource.get_all(start=2, count=500, filter=filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, uri=expected_uri) @mock.patch.object(ResourceClient, 'get') def test_get_called_once(self, mock_get): index_uri = "/rest/server-hardwares/fake" expected_call_uri = "/rest/index/resources/rest/server-hardwares/fake" self._resource.get(index_uri) mock_get.assert_called_once_with(expected_call_uri) @mock.patch.object(ResourceClient, 'get') def test_get_aggregated_called_once(self, mock_get_aggregated): expected_uri = '/rest/index/resources/aggregated?attribute=Model&attribute=State&category=server-hardware&childLimit=6' self._resource.get_aggregated(['Model', 'State'], 'server-hardware') mock_get_aggregated.assert_called_once_with(expected_uri)
def get_resources_associated_with_scope(connection, scope_uri): index_resource = IndexResources(connection) query_string = "scopeUris='{}'".format(scope_uri) all_index_resources = index_resource.get_all(category=category_list, query=query_string) response = [dict_response['uri'] for dict_response in all_index_resources] return response
def get_resources_associated_with_label(connection, label): index_resource = IndexResources(connection) query_string = "labels='{}'".format(label) all_index_resources = index_resource.get_all(category=category_list, query=query_string) response = [dict_response['uri'] for dict_response in all_index_resources] return response