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) self._resource = IndexResources(self.connection) @mock.patch.object(ResourceClient, 'get', 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?count=500&filter=name=TestName&sort=name:ascending&start=2' self._resource.get_all(start=2, count=500, filter=filter, sort=sort) mock_get_all.assert_called_once_with(expected_uri) @mock.patch.object(ResourceClient, 'get') def test_get_all_called_once_without_results(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' expected_uri = '/rest/index/resources?count=500&filter=name=TestName&sort=name:ascending&start=2' self._resource.get_all(start=2, count=500, filter=filter, sort=sort) mock_get_all.assert_called_once_with(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 index_resources(self): """ Gets the Index Resources API client. Returns: IndexResources: """ if not self.__index_resources: self.__index_resources = IndexResources(self.__connection) return self.__index_resources
def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._resource = IndexResources(self.connection)