2014-06-15 09:06:17 +02:00
|
|
|
import pytest
|
|
|
|
|
import json
|
2023-12-28 21:02:41 +01:00
|
|
|
from datetime import datetime, timezone
|
2014-06-15 09:06:17 +02:00
|
|
|
|
|
|
|
|
import redis
|
|
|
|
|
|
2016-08-18 14:54:50 +02:00
|
|
|
from pyhamtools import LookupLib, Callinfo
|
2014-06-15 09:06:17 +02:00
|
|
|
|
|
|
|
|
r = redis.Redis()
|
|
|
|
|
|
|
|
|
|
|
2016-08-18 14:54:50 +02:00
|
|
|
response_Exception_VP8STI_with_start_and_stop_date = {
|
|
|
|
|
'adif': 240,
|
|
|
|
|
'country': u'SOUTH SANDWICH ISLANDS',
|
|
|
|
|
'continent': u'SA',
|
2019-05-30 14:24:22 +02:00
|
|
|
'latitude': -59.48,
|
|
|
|
|
'longitude': -27.29,
|
2016-08-18 14:54:50 +02:00
|
|
|
'cqz': 13,
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-03 02:21:40 +01:00
|
|
|
response_TU5PCT = {
|
|
|
|
|
'adif': 428,
|
|
|
|
|
'country': u"COTE D'IVOIRE",
|
|
|
|
|
'continent': u'AF',
|
|
|
|
|
'latitude': 5.3,
|
|
|
|
|
'longitude': -4.0,
|
|
|
|
|
'cqz': 35,
|
|
|
|
|
}
|
2016-08-18 14:54:50 +02:00
|
|
|
|
2014-06-15 09:06:17 +02:00
|
|
|
class TestStoreDataInRedis:
|
|
|
|
|
|
|
|
|
|
def test_copy_data_in_redis(self, fixClublogXML, fix_redis):
|
|
|
|
|
|
|
|
|
|
fixClublogXML.copy_data_in_redis("clx", redis.Redis())
|
|
|
|
|
assert fix_redis.lookup_entity(280) == fixClublogXML.lookup_entity(280)
|
|
|
|
|
assert fix_redis.lookup_callsign("VK9XO") == fixClublogXML.lookup_callsign("VK9XO")
|
|
|
|
|
assert fix_redis.lookup_prefix("DH") == fixClublogXML.lookup_prefix("DH")
|
|
|
|
|
|
2020-03-03 02:21:40 +01:00
|
|
|
|
2014-06-15 09:06:17 +02:00
|
|
|
with pytest.raises(KeyError):
|
|
|
|
|
fix_redis.is_invalid_operation("VK0MC")
|
|
|
|
|
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1994, month=12, day=30, tzinfo=timezone.utc)
|
2014-06-15 09:06:17 +02:00
|
|
|
assert fix_redis.is_invalid_operation("VK0MC", timestamp)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
|
fix_redis.lookup_zone_exception("DH1TW")
|
|
|
|
|
|
|
|
|
|
assert fix_redis.lookup_zone_exception("dp0gvn") == 38
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_copy_data_in_redis_2(self, fixCountryFile):
|
|
|
|
|
|
|
|
|
|
lib = LookupLib(lookuptype="redis", redis_prefix="CF", redis_instance=r)
|
|
|
|
|
fixCountryFile.copy_data_in_redis("CF", r)
|
|
|
|
|
assert lib.lookup_callsign("3D2RI") == fixCountryFile.lookup_callsign("3D2RI")
|
2016-08-18 14:54:50 +02:00
|
|
|
assert lib.lookup_prefix("DH") == fixCountryFile.lookup_prefix("DH")
|
|
|
|
|
|
|
|
|
|
def test_redis_lookup(self, fixClublogXML, fix_redis):
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=2016, month=1, day=20, tzinfo=timezone.utc)
|
2016-08-18 14:54:50 +02:00
|
|
|
ci = Callinfo(fix_redis)
|
|
|
|
|
assert ci.get_all("VP8STI", timestamp) == response_Exception_VP8STI_with_start_and_stop_date
|
2020-03-03 02:21:40 +01:00
|
|
|
assert ci.get_all("tu5pct") == response_TU5PCT
|