Skip to content

Commit 2a0aba4

Browse files
committedJun 28, 2018
Fix bug in index_resources.get_all()
The essential problem is that index_resources.get_all() calls the Resource get() method which doesn't handle pagination and thus only returns the first page of results. The complication is that index_resources.get_all() builds its own URI complete with filtering. Thus we call index_resources.get_all() with 'start', 'count' and 'uri' arguments and remove the 'start' and 'count' fields from the pre-built uri. The implicated index_resource unit-tests have been updated. Fixes HewlettPackard#364
1 parent a44fe18 commit 2a0aba4

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 4.7.1
2+
#### Bug fixes
3+
- [#364] (https://github.com/HewlettPackard/python-hpOneView/issues/364) Bug in index_resources.get_all()
4+
15
# 4.7.0
26
#### Notes
37
Extends support of the SDK to OneView Rest API version 600 (OneView v4.0).

‎hpOneView/resources/resource.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
###
3-
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
3+
# (C) Copyright (2012-2018) Hewlett Packard Enterprise Development LP
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal

‎hpOneView/resources/search/index_resources.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
###
3-
# (C) Copyright (2017) Hewlett Packard Enterprise Development LP
3+
# (C) Copyright (2017-2018) Hewlett Packard Enterprise Development LP
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -88,25 +88,18 @@ def get_all(self, category='', count=-1, fields='', filter='', padding=0, query=
8888
uri = self.URI + '?'
8989

9090
uri += self.__list_or_str_to_query(category, 'category')
91-
uri += self.__list_or_str_to_query(count, 'count')
9291
uri += self.__list_or_str_to_query(fields, 'fields')
9392
uri += self.__list_or_str_to_query(filter, 'filter')
9493
uri += self.__list_or_str_to_query(padding, 'padding')
9594
uri += self.__list_or_str_to_query(query, 'query')
9695
uri += self.__list_or_str_to_query(reference_uri, 'referenceUri')
9796
uri += self.__list_or_str_to_query(sort, 'sort')
98-
uri += self.__list_or_str_to_query(start, 'start')
9997
uri += self.__list_or_str_to_query(user_query, 'userQuery')
10098
uri += self.__list_or_str_to_query(view, 'view')
10199

102100
uri = uri.replace('?&', '?')
103101

104-
response = self._client.get(uri)
105-
106-
if response and 'members' in response and response['members']:
107-
return response['members']
108-
else:
109-
return []
102+
return self._client.get_all(start=start, count=count, uri=uri)
110103

111104
def get(self, uri):
112105
"""

‎tests/unit/resources/search/test_index_resources.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
###
3-
# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP
3+
# (C) Copyright (2012-2018) Hewlett Packard Enterprise Development LP
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -51,25 +51,24 @@ def setUp(self):
5151
self.connection = connection(self.host)
5252
self._resource = IndexResources(self.connection)
5353

54-
@mock.patch.object(ResourceClient, 'get', return_value=dict(members='test'))
54+
@mock.patch.object(ResourceClient, 'get_all', return_value=dict(members='test'))
5555
def test_get_all_called_once(self, mock_get_all):
5656
filter = 'name=TestName'
5757
sort = 'name:ascending'
5858

59-
expected_uri = '/rest/index/resources?count=500&filter=name=TestName&sort=name:ascending&start=2'
59+
expected_uri = '/rest/index/resources?filter=name=TestName&sort=name:ascending'
6060

6161
self._resource.get_all(start=2, count=500, filter=filter, sort=sort)
62-
mock_get_all.assert_called_once_with(expected_uri)
62+
mock_get_all.assert_called_once_with(start=2, count=500, uri=expected_uri)
6363

64-
@mock.patch.object(ResourceClient, 'get')
64+
@mock.patch.object(ResourceClient, 'get_all')
6565
def test_get_all_called_once_without_results(self, mock_get_all):
6666
filter = 'name=TestName'
6767
sort = 'name:ascending'
6868

69-
expected_uri = '/rest/index/resources?count=500&filter=name=TestName&sort=name:ascending&start=2'
70-
69+
expected_uri = '/rest/index/resources?filter=name=TestName&sort=name:ascending'
7170
self._resource.get_all(start=2, count=500, filter=filter, sort=sort)
72-
mock_get_all.assert_called_once_with(expected_uri)
71+
mock_get_all.assert_called_once_with(start=2, count=500, uri=expected_uri)
7372

7473
@mock.patch.object(ResourceClient, 'get')
7574
def test_get_called_once(self, mock_get):

0 commit comments

Comments
 (0)
Please sign in to comment.