2014-04-24 14:01:53 +02:00
|
|
|
import pytest
|
2023-12-28 21:02:41 +01:00
|
|
|
from datetime import datetime, timezone
|
2014-04-25 23:46:44 +02:00
|
|
|
import os
|
2014-04-24 14:01:53 +02:00
|
|
|
|
|
|
|
|
from pyhamtools.lookuplib import LookupLib
|
2014-04-25 23:46:44 +02:00
|
|
|
from pyhamtools.exceptions import APIKeyMissingError
|
2014-04-24 14:01:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#Fixtures
|
|
|
|
|
#===========================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response_Entity_230 = {
|
2016-01-11 23:38:28 +01:00
|
|
|
'country': u'FEDERAL REPUBLIC OF GERMANY',
|
|
|
|
|
'continent': u'EU',
|
|
|
|
|
'latitude': 51.0,
|
2018-01-27 15:11:46 +01:00
|
|
|
'longitude': 10.0,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 14,
|
2015-04-06 20:00:30 +02:00
|
|
|
'prefix' : u'DL',
|
2014-04-24 14:01:53 +02:00
|
|
|
'deleted' : False,
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 23:38:28 +01:00
|
|
|
response_Exception_KC6MM_1990 = {
|
|
|
|
|
'adif': 22,
|
2015-04-06 20:00:30 +02:00
|
|
|
'country': u'PALAU',
|
2016-01-11 23:38:28 +01:00
|
|
|
'continent': u'OC',
|
2025-03-02 00:07:00 +01:00
|
|
|
'latitude': 9.52,
|
|
|
|
|
'longitude': 138.21,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 27,
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 23:38:28 +01:00
|
|
|
response_Exception_KC6MM_1992 = {
|
|
|
|
|
'adif': 22,
|
|
|
|
|
'country': u'PALAU',
|
|
|
|
|
'continent': u'OC',
|
2025-03-02 00:07:00 +01:00
|
|
|
'latitude': 9.52,
|
|
|
|
|
'longitude': 138.21,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 27,
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 23:38:28 +01:00
|
|
|
response_Exception_VK9XX_with_end_date = {
|
|
|
|
|
'adif': 35,
|
|
|
|
|
'country': u'CHRISTMAS ISLAND',
|
|
|
|
|
'continent': u'OC',
|
2022-12-05 01:01:45 +01:00
|
|
|
'latitude': -10.52,
|
|
|
|
|
'longitude': 105.54,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 29,
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 23:38:28 +01:00
|
|
|
response_Exception_VK9XO_with_start_date = {
|
|
|
|
|
'adif': 35,
|
|
|
|
|
'country': u'CHRISTMAS ISLAND',
|
|
|
|
|
'continent': u'OC',
|
2023-12-28 21:02:41 +01:00
|
|
|
'latitude': -10.48,
|
2025-03-02 00:07:00 +01:00
|
|
|
'longitude': 105.62,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 29,
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 23:38:28 +01:00
|
|
|
response_Exception_AX9NYG = {
|
|
|
|
|
'adif': 38,
|
|
|
|
|
'country': u'COCOS (KEELING) ISLAND',
|
|
|
|
|
'continent': u'OC',
|
|
|
|
|
'latitude': -12.20,
|
2018-01-27 15:11:46 +01:00
|
|
|
'longitude': 96.80,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 29,
|
|
|
|
|
}
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
response_Prefix_DH = {
|
2016-01-11 23:38:28 +01:00
|
|
|
'country': u'FEDERAL REPUBLIC OF GERMANY',
|
2014-04-24 14:01:53 +02:00
|
|
|
'adif' : 230,
|
2016-01-11 23:38:28 +01:00
|
|
|
'continent': u'EU',
|
|
|
|
|
'latitude': 51.0,
|
2018-01-27 15:11:46 +01:00
|
|
|
'longitude': 10.0,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 14,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response_Prefix_VK9_until_1975 = {
|
2016-01-11 23:38:28 +01:00
|
|
|
'country': u'PAPUA TERR',
|
2014-04-24 14:01:53 +02:00
|
|
|
'adif' : 198,
|
2016-01-11 23:38:28 +01:00
|
|
|
'continent': u'OC',
|
|
|
|
|
'latitude': -9.40,
|
2018-01-27 15:11:46 +01:00
|
|
|
'longitude': 147.10,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 28,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response_Prefix_VK9_starting_1976 = {
|
2016-01-11 23:38:28 +01:00
|
|
|
'country': u'NORFOLK ISLAND',
|
2014-04-24 14:01:53 +02:00
|
|
|
'adif' : 189,
|
2016-01-11 23:38:28 +01:00
|
|
|
'continent': u'OC',
|
|
|
|
|
'latitude': -29.00,
|
2018-01-27 15:11:46 +01:00
|
|
|
'longitude': 168.00,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response_Prefix_ZD5_1964_to_1971 = {
|
2019-11-27 03:10:08 +01:00
|
|
|
'country': u'KINGDOM OF ESWATINI',
|
2014-04-24 14:01:53 +02:00
|
|
|
'adif' : 468,
|
2016-01-11 23:38:28 +01:00
|
|
|
'continent': u'AF',
|
|
|
|
|
'latitude': -26.30,
|
2018-01-27 15:11:46 +01:00
|
|
|
'longitude': 31.10,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 38,
|
|
|
|
|
}
|
2016-01-11 23:38:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
@pytest.fixture(scope="function")
|
2014-04-25 23:46:44 +02:00
|
|
|
def fix_cty_xml_file(request):
|
|
|
|
|
dir = os.path.dirname(__file__)
|
|
|
|
|
cty_file_rel = "./fixtures/cty.xml"
|
|
|
|
|
cty_file_abs = os.path.join(dir, cty_file_rel)
|
|
|
|
|
return cty_file_abs
|
2014-04-24 14:01:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#TESTS
|
|
|
|
|
#===========================================================
|
|
|
|
|
class TestclublogXML_Getters:
|
|
|
|
|
|
|
|
|
|
#lookup_entity(callsign)
|
|
|
|
|
#===============================
|
|
|
|
|
|
|
|
|
|
def test_lookup_entity(self, fixClublogXML):
|
|
|
|
|
assert fixClublogXML.lookup_entity(230) == response_Entity_230
|
|
|
|
|
assert fixClublogXML.lookup_entity("230") == response_Entity_230
|
|
|
|
|
|
2014-05-08 15:03:16 +02:00
|
|
|
with pytest.raises(ValueError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_entity("foo")
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_entity(1000)
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_entity(999)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#lookup_callsign(callsign, [date])
|
|
|
|
|
#===============================
|
|
|
|
|
|
|
|
|
|
def test_lookup_callsign_same_callsign_different_exceptions(self, fixClublogXML):
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1990, month=10, day=12, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_callsign("kc6mm", timestamp) == response_Exception_KC6MM_1990
|
|
|
|
|
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1992, month=3, day=8, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_callsign("kc6mm", timestamp) == response_Exception_KC6MM_1992
|
|
|
|
|
|
|
|
|
|
def test_lookup_callsign_exception_only_with_start_date(self, fixClublogXML):
|
|
|
|
|
#timestamp > startdate
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1962, month=7, day=7, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_callsign("vk9xo", timestamp) == response_Exception_VK9XO_with_start_date
|
|
|
|
|
assert fixClublogXML.lookup_callsign("vk9xo") == response_Exception_VK9XO_with_start_date
|
|
|
|
|
|
|
|
|
|
#timestamp < startdate
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1962, month=7, day=5, tzinfo=timezone.utc)
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_callsign("vk9xo", timestamp)
|
|
|
|
|
|
|
|
|
|
def test_lookup_callsign_exception_only_with_end_date(self, fixClublogXML):
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
#timestamp < enddate
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1975, month=9, day=14, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_callsign("vk9xx", timestamp) == response_Exception_VK9XX_with_end_date
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
# timestamp > enddate
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_callsign("vk9xx")
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1975, month=9, day=16, tzinfo=timezone.utc)
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_callsign("vk9xx", timestamp)
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
def test_lookup_callsign_exception_no_start_nor_end_date(self, fixClublogXML):
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1975, month=9, day=14, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_callsign("ax9nyg", timestamp) == response_Exception_AX9NYG
|
|
|
|
|
assert fixClublogXML.lookup_callsign("ax9nyg" ) == response_Exception_AX9NYG
|
2016-01-11 23:38:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
#lookup_prefix(prefix, [date])
|
|
|
|
|
#=========================
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
def test_lookup_prefix(self, fixClublogXML):
|
|
|
|
|
assert fixClublogXML.lookup_prefix("DH") == response_Prefix_DH
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_prefix("QRM")
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_prefix("")
|
|
|
|
|
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
def test_lookup_prefix_with_changing_entities(self, fixClublogXML):
|
|
|
|
|
#return old entity (PAPUA TERR)
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1975, month=9, day=14, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_prefix("VK9", timestamp) == response_Prefix_VK9_until_1975
|
|
|
|
|
|
|
|
|
|
#return empty dict - Prefix was not assigned at that time
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1975, month=9, day=16, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_prefix("VK9", timestamp)
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
#return new entity (Norfolk Island)
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime.now(timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_prefix("VK9", timestamp ) == response_Prefix_VK9_starting_1976
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
def test_lookup_prefix_with_entities_having_start_and_stop(self, fixClublogXML):
|
|
|
|
|
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp_before = datetime(year=1964, month=11, day=1, tzinfo=timezone.utc)
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_prefix("ZD5", timestamp_before)
|
|
|
|
|
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp_valid = datetime(year=1964, month=12, day=2, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_prefix("ZD5", timestamp_valid) == response_Prefix_ZD5_1964_to_1971
|
|
|
|
|
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp_after = datetime(year=1971, month=8, day=1, tzinfo=timezone.utc)
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_prefix("ZD5", timestamp_after)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#is_invalid_operation(callsign, [date])
|
|
|
|
|
#====================================
|
|
|
|
|
|
|
|
|
|
def test_is_invalid_operations(self, fixClublogXML):
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
#No dataset --> default Operation is True
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.is_invalid_operation("dh1tw")
|
|
|
|
|
|
|
|
|
|
#Invalid Operation with start and end date
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp_before = datetime(year=1993, month=12, day=30, tzinfo=timezone.utc)
|
|
|
|
|
timestamp = datetime(year=1994, month=12, day=30, tzinfo=timezone.utc)
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.is_invalid_operation("vk0mc")
|
|
|
|
|
|
|
|
|
|
assert fixClublogXML.is_invalid_operation("vk0mc", timestamp)
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.is_invalid_operation("vk0mc", timestamp_before)
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
#Invalid Operation with start date
|
|
|
|
|
assert fixClublogXML.is_invalid_operation("5W1CFN")
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp_before = datetime(year=2012, month=1, day=31, tzinfo=timezone.utc)
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.is_invalid_operation("5W1CFN", timestamp_before)
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
|
|
|
|
|
#lookup_zone_exception(callsign, [date])
|
|
|
|
|
#====================================
|
2016-01-11 23:38:28 +01:00
|
|
|
|
2014-04-24 14:01:53 +02:00
|
|
|
def test_lookup_zone_exception(self, fixClublogXML):
|
|
|
|
|
|
|
|
|
|
#No dataset --> default answer: None
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_zone_exception("dh1tw")
|
|
|
|
|
|
|
|
|
|
#zone exception with no date
|
|
|
|
|
assert fixClublogXML.lookup_zone_exception("dp0gvn") == 38
|
|
|
|
|
|
|
|
|
|
#zone exception with start and end date
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp = datetime(year=1992, month=10, day=2, tzinfo=timezone.utc)
|
|
|
|
|
timestamp_before = datetime(year=1992, month=9, day=30, tzinfo=timezone.utc)
|
|
|
|
|
timestamp_after = datetime(year=1993, month=3, day=1, tzinfo=timezone.utc)
|
2014-04-24 14:01:53 +02:00
|
|
|
assert fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp) == 38
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp_before)
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp_after)
|
|
|
|
|
|
2014-04-28 01:59:18 +02:00
|
|
|
#zone exception with start date
|
2023-12-28 21:02:41 +01:00
|
|
|
timestamp_before = datetime(year=2013, month=12, day=26,tzinfo=timezone.utc)
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixClublogXML.lookup_zone_exception("dh1hb/p", timestamp_before)
|