diff options
author | Flaper Fesp <flaper87@gmail.com> | 2013-06-03 16:36:07 +0200 |
---|---|---|
committer | Flaper Fesp <flaper87@gmail.com> | 2013-06-03 17:40:50 +0200 |
commit | 81e88344fbd20b792e03eb1002fa5d68e5af212b (patch) | |
tree | cb39a5b1048bb7b0e682592ddeeae23b373e933f /tests | |
parent | 7d487834344e812c812dab0b14b9a51b5816554b (diff) | |
download | python-glanceclient-81e88344fbd20b792e03eb1002fa5d68e5af212b.tar.gz |
Add tests for encodings
The patch adds tests for headers encodings, incoming data decoding,
outgoing meta encoding and filters encoding.
Fixes bug: #1187013
Change-Id: I7e59bf6c44b9d188bd3faf32fc09f309f3ad67d3
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_http.py | 5 | ||||
-rw-r--r-- | tests/v1/test_images.py | 24 | ||||
-rw-r--r-- | tests/v2/test_images.py | 13 |
3 files changed, 41 insertions, 1 deletions
diff --git a/tests/test_http.py b/tests/test_http.py index 1f1f4e1..2d048c8 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -84,6 +84,11 @@ class TestClient(testtools.TestCase): headers=headers) self.assertEqual(resp, fake) + def test_headers_encoding(self): + headers = {"test": u'ni\xf1o'} + encoded = self.client.encode_headers(headers) + self.assertEqual(encoded["test"], "ni\xc3\xb1o") + def test_connection_refused_raw_request(self): """ Should receive a CommunicationError if connection refused. diff --git a/tests/v1/test_images.py b/tests/v1/test_images.py index c314cee..d2ead85 100644 --- a/tests/v1/test_images.py +++ b/tests/v1/test_images.py @@ -230,7 +230,8 @@ fixtures = { '/v1/images/3': { 'HEAD': ( { - 'x-image-meta-id': '3' + 'x-image-meta-id': '3', + 'x-image-meta-name': "ni\xc3\xb1o" }, None, ), @@ -313,6 +314,11 @@ class ImageManagerTest(testtools.TestCase): self.assertEqual(image.deleted, False) self.assertEqual(image.properties, {u'arch': u'x86_64'}) + def test_get_encoding(self): + image = self.mgr.get('3') + expect = [('HEAD', '/v1/images/3', {}, None)] + self.assertEqual(image.name, u"ni\xf1o") + def test_data(self): data = ''.join([b for b in self.mgr.data('1', do_checksum=False)]) expect = [('GET', '/v1/images/1', {}, None)] @@ -454,6 +460,22 @@ class ImageManagerTest(testtools.TestCase): expect = [('PUT', '/v1/images/1', expect_headers, None)] self.assertEqual(self.api.calls, expect) + def test_image_meta_to_headers_encoding(self): + # NOTE(flaper87): This doesn't make much sense + # _image_meta_to_headers decodes headers that will + # then be encoded before sending the request. If + # everything works as expected, there shouldn't be + # any need to enforce unicode in headers at this step. + # Will get rid of that in a separate patch. + fields = {"name": "ni\xc3\xb1o"} + headers = self.mgr._image_meta_to_headers(fields) + self.assertEqual(headers["x-image-meta-name"], u"ni\xf1o") + + def test_image_meta_from_headers_encoding(self): + fields = {"x-image-meta-name": "ni\xc3\xb1o"} + headers = self.mgr._image_meta_from_headers(fields) + self.assertEqual(headers["name"], u"ni\xf1o") + class ImageTest(testtools.TestCase): def setUp(self): diff --git a/tests/v2/test_images.py b/tests/v2/test_images.py index 7e96e06..ae40433 100644 --- a/tests/v2/test_images.py +++ b/tests/v2/test_images.py @@ -255,6 +255,19 @@ class TestController(testtools.TestCase): images = list(self.controller.list(**filters)) self.assertEqual(images[0].id, _EVERYTHING_ID) + def test_list_images_filters_encoding(self): + filters = {"owner": u"ni\xf1o"} + try: + list(self.controller.list(filters=filters)) + except KeyError: + # NOTE(flaper87): It raises KeyError because there's + # no fixture supporting this query: + # /v2/images?owner=ni%C3%B1o&limit=20 + # We just want to make sure filters are correctly encoded. + pass + + self.assertEqual(filters["owner"], "ni\xc3\xb1o") + def test_get_image(self): image = self.controller.get('3a4560a1-e585-443e-9b39-553b46ec92d1') self.assertEqual(image.id, '3a4560a1-e585-443e-9b39-553b46ec92d1') |