Skip to content

Commit

Permalink
Fix Python 2.7 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Sep 6, 2018
1 parent 5d3deba commit eb89e3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sentinelsat/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def get_product_odata(self, id, full=False):
https://github.com/SentinelDataHub/DataHubSystem/blob/master/addon/sentinel-2/src/main/resources/META-INF/sentinel-2.owl
https://github.com/SentinelDataHub/DataHubSystem/blob/master/addon/sentinel-3/src/main/resources/META-INF/sentinel-3.owl
"""
url = urljoin(self.api_url, "odata/v1/Products('{}')?$format=json".format(id))
url = urljoin(self.api_url, u"odata/v1/Products('{}')?$format=json".format(id))
if full:
url += '&$expand=Attributes'
response = self.session.get(url, auth=self.session.auth)
Expand Down Expand Up @@ -595,7 +595,7 @@ def check_query_length(query):
Ratio of the query length to the maximum length
"""
# The server uses the Java's URLEncoder implementation internally, which we are replicating here
effective_length = len(quote_plus(query, safe="-_.*", encoding='utf8').replace('~', '%7E'))
effective_length = len(quote_plus(query, safe="-_.*").replace('~', '%7E'))
return effective_length / 3938

def _query_names(self, names):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_mod.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import hashlib
import textwrap
from datetime import date, datetime, timedelta
Expand Down Expand Up @@ -374,15 +375,15 @@ def test_count():
@pytest.mark.scihub
def test_unicode_support():
api = SentinelAPI(**_api_kwargs)
test_str = 'õäü:'
test_str = u'٩(●̮̮̃•̃)۶:'

with pytest.raises(SentinelAPIError) as excinfo:
api.count(raw=test_str)
assert test_str == excinfo.value.response.json()['feed']['opensearch:Query']['searchTerms']

with pytest.raises(SentinelAPIError) as excinfo:
api.get_product_odata(test_str)
assert test_str in excinfo.value.msg
assert test_str in excinfo.value.response.json()['error']['message']['value']


@my_vcr.use_cassette
Expand Down

0 comments on commit eb89e3e

Please sign in to comment.