Fix repr tests and url quoting in bytes/strings

This commit is contained in:
Honza Král
2014-05-29 02:42:59 +02:00
parent 40fbb2a1c3
commit 38ae1bd3c3
2 changed files with 4 additions and 10 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ from functools import wraps
from ..compat import string_types, quote_plus
# parts of URL to be omitted
SKIP_IN_PATH = (None, '', [], ())
SKIP_IN_PATH = (None, b'', [], ())
def _escape(value):
"""
@@ -43,7 +43,7 @@ def _make_path(*parts):
#TODO: maybe only allow some parts to be lists/tuples ?
return '/' + '/'.join(
# preserve ',' and '*' in url for nicer URLs in logs
quote_plus(_escape(p), ',*') for p in parts if p not in SKIP_IN_PATH)
quote_plus(_escape(p), b',*') for p in parts if p not in SKIP_IN_PATH)
# parameters that apply to all methods
GLOBAL_PARAMS = ('pretty', 'format', )
+2 -8
View File
@@ -48,14 +48,8 @@ class TestClient(ElasticsearchTestCase):
self.assertEquals('<Elasticsearch([{}])>', repr(self.client))
def test_repr_contains_hosts_passed_in(self):
self.assertEquals(
'<Elasticsearch([%r])>' % {"host": "es.org", "port": 123},
repr(Elasticsearch(['es.org:123']))
)
self.assertIn("es.org", repr(Elasticsearch(['es.org:123'])))
def test_repr_truncates_host_to_10(self):
hosts = [{"host": "es" + str(i)} for i in range(20)]
self.assertEquals(
'<Elasticsearch(%r)>' % [{'host': 'es0'}, {'host': 'es1'}, {'host': 'es2'}, {'host': 'es3'}, {'host': 'es4'}, '...'],
repr(Elasticsearch(hosts))
)
self.assertNotIn("es5", repr(Elasticsearch(hosts)))