From 01869462df984231af8a0227778cbba647211ccc Mon Sep 17 00:00:00 2001 From: "Tobias Wellnitz, DH1TW" Date: Tue, 3 Mar 2020 02:21:40 +0100 Subject: [PATCH] Bugfix for badly escaped json data after reading from redis (#16) Apostrophes and quotation marks where escaped after retrieving the JSON formatted data from redis. --- pyhamtools/lookuplib.py | 3 +-- test/test_lookuplib_redis.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pyhamtools/lookuplib.py b/pyhamtools/lookuplib.py index 76aa260..400cf96 100644 --- a/pyhamtools/lookuplib.py +++ b/pyhamtools/lookuplib.py @@ -1485,8 +1485,7 @@ class LookupLib(object): Deserialize a JSON into a dictionary """ - my_dict = json.loads(json_data.decode('utf8').replace("'", '"'), - encoding='UTF-8') + my_dict = json.loads(json_data.decode('utf8'), encoding='UTF-8') for item in my_dict: if item == const.ADIF: diff --git a/test/test_lookuplib_redis.py b/test/test_lookuplib_redis.py index 8eef81f..2ccb0dc 100644 --- a/test/test_lookuplib_redis.py +++ b/test/test_lookuplib_redis.py @@ -22,6 +22,14 @@ response_Exception_VP8STI_with_start_and_stop_date = { 'cqz': 13, } +response_TU5PCT = { + 'adif': 428, + 'country': u"COTE D'IVOIRE", + 'continent': u'AF', + 'latitude': 5.3, + 'longitude': -4.0, + 'cqz': 35, + } class TestStoreDataInRedis: @@ -32,6 +40,7 @@ class TestStoreDataInRedis: assert fix_redis.lookup_callsign("VK9XO") == fixClublogXML.lookup_callsign("VK9XO") assert fix_redis.lookup_prefix("DH") == fixClublogXML.lookup_prefix("DH") + with pytest.raises(KeyError): fix_redis.is_invalid_operation("VK0MC") @@ -55,3 +64,4 @@ class TestStoreDataInRedis: timestamp = datetime(year=2016, month=1, day=20, tzinfo=UTC) ci = Callinfo(fix_redis) assert ci.get_all("VP8STI", timestamp) == response_Exception_VP8STI_with_start_and_stop_date + assert ci.get_all("tu5pct") == response_TU5PCT