Add ability to filter from categories with unicode
Change-Id: I31974dc6044ffcd7411e0a5ed95b2599587004fa closes-bug: 1473640
This commit is contained in:
parent
54479c362e
commit
92b30c30f4
|
@ -226,6 +226,27 @@ class UnitTestsForClassesAndFunctions(testtools.TestCase):
|
|||
|
||||
self.assertEqual(api.json_request.call_count, 2)
|
||||
|
||||
def test_package_filter_encoding_good(self):
|
||||
responses = [
|
||||
{'next_marker': 'test_marker',
|
||||
'packages': [{'name': 'test_package_1'}]},
|
||||
{'packages': [{'name': 'test_package_2'}]}
|
||||
]
|
||||
|
||||
def json_request(method, url, *args, **kwargs):
|
||||
self.assertIn('category=%D0%BF%D0%B8%D0%B2%D0%BE', url)
|
||||
return mock.MagicMock(), responses.pop(0)
|
||||
|
||||
api = mock.MagicMock()
|
||||
api.configure_mock(**{'json_request.side_effect': json_request})
|
||||
|
||||
manager = packages.PackageManager(api)
|
||||
category = '\xd0\xbf\xd0\xb8\xd0\xb2\xd0\xbe'
|
||||
kwargs = {'category': category.decode('utf-8')}
|
||||
list(manager.filter(**kwargs))
|
||||
|
||||
self.assertEqual(api.json_request.call_count, 2)
|
||||
|
||||
def test_action_manager_get_result(self):
|
||||
api_mock = mock.MagicMock(
|
||||
json_request=lambda *args, **kwargs: (None, {'a': 'b'}))
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
import urllib
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
@ -70,7 +71,12 @@ class PackageManager(base.Manager):
|
|||
return self._get('/v1/catalog/packages/{0}'.format(app_id))
|
||||
|
||||
def filter(self, **kwargs):
|
||||
|
||||
def construct_url(params):
|
||||
for k, v in params.items():
|
||||
if isinstance(v, six.text_type):
|
||||
v = v.encode('utf-8')
|
||||
params[k] = v
|
||||
return '?'.join(
|
||||
['/v1/catalog/packages', urllib.urlencode(params, doseq=True)]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue