mirror of
https://github.com/dh1tw/pyhamtools.git
synced 2026-04-05 14:35:49 +00:00
Initial Commit
This commit is contained in:
parent
9656aa3cb5
commit
d054e97ed4
64 changed files with 349324 additions and 0 deletions
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
77
test/conftest.py
Normal file
77
test/conftest.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
#
|
||||
# @pytest.fixture()
|
||||
# def cleandir():
|
||||
# newpath = tempfile.mkdtemp()
|
||||
# os.chdir(newpath)
|
||||
#
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
|
||||
@pytest.fixture(scope="session", params=["a", "", 12.5, -5, {"foo" : "bar"}, [5, "foo"]])
|
||||
def fixNonUnsignedInteger(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="session", params=[12.5, -5, 34569, {"foo" : "bar"}, [5, "foo"]])
|
||||
def fixNonString(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="session", params=[12.5, -5.5, 34569.0000001])
|
||||
def fixFloats(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="session", params=["", "-5.5", "foo bar"])
|
||||
def fixStrings(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="session", params=[0, -2322321, 32321321])
|
||||
def fixIntegers(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="session", params=[{"foo": "bar"}, {}, {-99.99 : {"foo": 12}}])
|
||||
def fixDicts(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="session", params=[["foo", "bar", 99.12], [None, 55, "foo"]])
|
||||
def fixLists(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="session", params=[None])
|
||||
def fixNone(request):
|
||||
return request.param
|
||||
|
||||
|
||||
|
||||
API_KEY = ""
|
||||
@pytest.fixture(scope="session")
|
||||
def fixApiKey(request):
|
||||
return(API_KEY)
|
||||
|
||||
@pytest.fixture(scope="module", params=["clublogapi", "clublogxml", "countryfile"])
|
||||
def fixGeneralApi(request, fixApiKey):
|
||||
"""Fixture returning all possible instances of LookupLib"""
|
||||
Lib = LookupLib(request.param, fixApiKey)
|
||||
# pytest.skip("better later")
|
||||
return(Lib)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def fixClublogApi(request, fixApiKey):
|
||||
Lib = LookupLib("clublogapi", fixApiKey)
|
||||
return(Lib)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def fixClublogXML(request, fixApiKey):
|
||||
Lib = LookupLib("clublogxml", fixApiKey)
|
||||
return(Lib)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def fixCountryFile(request):
|
||||
Lib = LookupLib("countryfile")
|
||||
return(Lib)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def fixRedis(request):
|
||||
Lib = LookupLib("redis")
|
||||
return(Lib)
|
||||
46
test/test_lookuplib.py
Normal file
46
test/test_lookuplib.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import pytest
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
from pyhamtools.exceptions import APIKeyMissingError
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", params=[5, -5, "", "foo bar", 11.5, {}, [], None, ("foo", "bar")])
|
||||
def fixAnyValue(request):
|
||||
return request.param
|
||||
|
||||
|
||||
class TestlookupLib:
|
||||
|
||||
def test_construction_without_kwargs(self):
|
||||
"""Load with non without any args & kwargs"""
|
||||
with pytest.raises(APIKeyMissingError):
|
||||
LookupLib()
|
||||
|
||||
def test_construction_with_invalid_kwargs(self, fixAnyValue):
|
||||
"""Load with non without any args & kwargs"""
|
||||
with pytest.raises(AttributeError):
|
||||
LookupLib(fixAnyValue)
|
||||
|
||||
|
||||
|
||||
class TestlookupLibHelper:
|
||||
|
||||
# def test_checkApiKeyValidity(self, fixClublogApi, fixApiKey):
|
||||
#
|
||||
# with pytest.raises(AttributeError):
|
||||
# fixClublogApi._checkApiKeyValidity()
|
||||
#
|
||||
# with pytest.raises(ValueError):
|
||||
# fixClublogApi._checkApiKeyValidity(apikey="")
|
||||
#
|
||||
# assert fixClublogApi._checkApiKeyValidity(apikey=fixApiKey) is True
|
||||
|
||||
|
||||
def test_generateRandomWord(self, fixClublogApi, fixNonUnsignedInteger):
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
fixClublogApi._generate_random_word()
|
||||
|
||||
assert type(fixClublogApi._generate_random_word(5)) is str
|
||||
assert len(fixClublogApi._generate_random_word(5)) is 5
|
||||
|
||||
119
test/test_lookuplib_clublogapi.py
Normal file
119
test/test_lookuplib_clublogapi.py
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
import pytest
|
||||
from datetime import datetime
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
|
||||
from pyhamtools.exceptions import APIKeyMissingError, LookupError, NoResult
|
||||
|
||||
#Fixtures
|
||||
#===========================================================
|
||||
|
||||
response_Exception_DH1TW = {
|
||||
'adif': 230,
|
||||
'country': 'FEDERAL REPUBLIC OF GERMANY',
|
||||
'continent': 'EU',
|
||||
'latitude': 51.0,
|
||||
'longitude': -10.0,
|
||||
'cqz': 14
|
||||
}
|
||||
|
||||
response_Exception_VU9KV = {
|
||||
'adif': 324,
|
||||
'country': 'INDIA',
|
||||
'continent': 'AS',
|
||||
'latitude': 22.0,
|
||||
'longitude': -80.0,
|
||||
'cqz': 22
|
||||
}
|
||||
|
||||
|
||||
response_Exception_VU9KV_with_Date = {
|
||||
'adif': 11,
|
||||
'country': 'ANDAMAN & NICOBAR ISLANDS',
|
||||
'continent': 'AS',
|
||||
'latitude': 11.70,
|
||||
'longitude': -92.80,
|
||||
'cqz': 26
|
||||
}
|
||||
|
||||
|
||||
response_Exception_DH1TW_MM = {
|
||||
'adif': 999,
|
||||
'country': 'MARITIME MOBILE',
|
||||
'continent': '',
|
||||
'latitude': 0.0,
|
||||
'longitude': 0.0,
|
||||
'cqz': 0
|
||||
}
|
||||
|
||||
response_Exception_DH1TW_AM = {
|
||||
'adif': 998,
|
||||
'country': 'AIRCRAFT MOBILE',
|
||||
'continent': '',
|
||||
'longitude': 0.0,
|
||||
'latitude': 0.0,
|
||||
'cqz': 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#TESTS
|
||||
#===========================================================
|
||||
|
||||
|
||||
class TestClublogApi_Constructor:
|
||||
|
||||
def test_with_invalid_api_key(self):
|
||||
with pytest.raises(APIKeyMissingError):
|
||||
lib = LookupLib(lookuptype="clublogapi", apikey="foo")
|
||||
lib.lookup_callsign("DH1TW")
|
||||
|
||||
def test_with_no_api_key(self):
|
||||
with pytest.raises(APIKeyMissingError):
|
||||
lib = LookupLib(lookuptype="clublogapi")
|
||||
lib.lookup_callsign("DH1TW")
|
||||
|
||||
class TestclublogApi_Getters:
|
||||
|
||||
#getEntity(adif)
|
||||
#===============================
|
||||
def test_lookup_callsign(self, fixClublogApi):
|
||||
assert fixClublogApi.lookup_entity(230) is None
|
||||
|
||||
|
||||
#lookup_callsign(callsign, [date])
|
||||
#===============================
|
||||
|
||||
def test_lookup_callsign(self, fixClublogApi):
|
||||
assert fixClublogApi.lookup_callsign("DH1TW") == response_Exception_DH1TW
|
||||
assert fixClublogApi.lookup_callsign("VU9KV") == response_Exception_VU9KV
|
||||
d = datetime.utcnow().replace(year=1971, month=04, day=14)
|
||||
assert fixClublogApi.lookup_callsign("VU9KV", d) == response_Exception_VU9KV_with_Date
|
||||
assert fixClublogApi.lookup_callsign("DH1TW/MM") == response_Exception_DH1TW_MM
|
||||
assert fixClublogApi.lookup_callsign("DH1TW/AM") == response_Exception_DH1TW_AM
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogApi.lookup_callsign("QRM")
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogApi.lookup_callsign("")
|
||||
|
||||
#lookup_prefix(prefix, [date])
|
||||
#===============================
|
||||
def test_lookup_callsign(self, fixClublogApi):
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogApi.lookup_prefix("DH")
|
||||
|
||||
|
||||
#is_invalid_operation(callsign, [date])
|
||||
#===============================
|
||||
def test_is_invalid_operation(self, fixClublogApi):
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogApi.is_invalid_operation("5W1CFN")
|
||||
|
||||
|
||||
#lookup_zone_exception(callsign, [date])
|
||||
#====================================
|
||||
def test_lookup_zone_exception(self, fixClublogApi):
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogApi.lookup_zone_exception("dp0gvn")
|
||||
313
test/test_lookuplib_clublogxml.py
Normal file
313
test/test_lookuplib_clublogxml.py
Normal file
|
|
@ -0,0 +1,313 @@
|
|||
import pytest
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
from pyhamtools.exceptions import APIKeyMissingError, LookupError, NoResult
|
||||
|
||||
UTC = pytz.UTC
|
||||
|
||||
|
||||
#Fixtures
|
||||
#===========================================================
|
||||
|
||||
|
||||
|
||||
response_Entity_230 = {
|
||||
'country': 'FEDERAL REPUBLIC OF GERMANY',
|
||||
'continent': 'EU',
|
||||
'latitude': 51.0,
|
||||
'longitude': -10.0,
|
||||
'cqz': 14,
|
||||
'prefix' : 'DL',
|
||||
'deleted' : False,
|
||||
'start' : datetime(year=1973, month=9, day=17).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
response_Exception_KC6MM_1990 = {
|
||||
'adif': 22,
|
||||
'country': 'PALAU',
|
||||
'continent': 'OC',
|
||||
'latitude': 9.50,
|
||||
'longitude': -138.20,
|
||||
'cqz': 27,
|
||||
'start' : datetime(year=1990, month=10, day=11).replace(tzinfo=UTC),
|
||||
'end' : datetime(year=1990, month=10, day=16, hour=23, minute=59, second=59).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
response_Exception_KC6MM_1992 = {
|
||||
'adif': 22,
|
||||
'country': 'PALAU',
|
||||
'continent': 'OC',
|
||||
'latitude': 9.50,
|
||||
'longitude': -138.20,
|
||||
'cqz': 27,
|
||||
'start' : datetime(year=1992, month=3, day=7).replace(tzinfo=UTC),
|
||||
'end' : datetime(year=1992, month=3, day=9, hour=23, minute=59, second=59).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
|
||||
response_Exception_VK9XX_with_end_date = {
|
||||
'adif': 35,
|
||||
'country': 'CHRISTMAS ISLAND',
|
||||
'continent': 'OC',
|
||||
'latitude': -10.50,
|
||||
'longitude': -105.70,
|
||||
'cqz': 29,
|
||||
'end' : datetime(year=1975, month=9, day=15, hour=23, minute=59, second=59).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
response_Exception_VK9XO_with_start_date = {
|
||||
'adif': 35,
|
||||
'country': 'CHRISTMAS ISLAND',
|
||||
'continent': 'OC',
|
||||
'latitude': -10.50,
|
||||
'longitude': -105.70,
|
||||
'cqz': 29,
|
||||
'start' : datetime(year=1962, month=7, day=6).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
response_Exception_AX9NYG = {
|
||||
'adif': 38,
|
||||
'country': 'COCOS (KEELING) ISLAND',
|
||||
'continent': 'OC',
|
||||
'latitude': -12.20,
|
||||
'longitude': -96.80,
|
||||
'cqz': 29,
|
||||
}
|
||||
|
||||
response_Prefix_DH = {
|
||||
'country': 'FEDERAL REPUBLIC OF GERMANY',
|
||||
'adif' : 230,
|
||||
'continent': 'EU',
|
||||
'latitude': 51.0,
|
||||
'longitude': -10.0,
|
||||
'cqz': 14,
|
||||
}
|
||||
|
||||
response_Prefix_VK9_until_1975 = {
|
||||
'country': 'PAPUA TERR',
|
||||
'adif' : 198,
|
||||
'continent': 'OC',
|
||||
'latitude': -9.40,
|
||||
'longitude': -147.10,
|
||||
'cqz': 28,
|
||||
'end' : datetime(year=1975, month=9, day=15, hour=23, minute=59, second=59).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
response_Prefix_VK9_starting_1976 = {
|
||||
'country': 'NORFOLK ISLAND',
|
||||
'adif' : 189,
|
||||
'continent': 'OC',
|
||||
'latitude': -29.00,
|
||||
'longitude': -168.00,
|
||||
'cqz': 32,
|
||||
'start' : datetime(year=1976, month=9, day=16).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
response_Prefix_ZD5_1964_to_1971 = {
|
||||
'country': 'SWAZILAND',
|
||||
'adif' : 468,
|
||||
'continent': 'AF',
|
||||
'latitude': -26.30,
|
||||
'longitude': -31.10,
|
||||
'cqz': 38,
|
||||
'start' : datetime(year=1964, month=12, day=1).replace(tzinfo=UTC),
|
||||
'end' : datetime(year=1971, month=7, day=31, hour=23, minute=59, second=59).replace(tzinfo=UTC)
|
||||
}
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def fixCtyXmlFile(request):
|
||||
return "/Users/user/projects/pyhamtools/pyhamtools/cty.xml"
|
||||
|
||||
|
||||
#TESTS
|
||||
#===========================================================
|
||||
|
||||
class TestClublogXML_Constructor:
|
||||
|
||||
def test_with_invalid_api_key(self):
|
||||
with pytest.raises(APIKeyMissingError):
|
||||
lib = LookupLib(apikey="foo")
|
||||
lib.lookup_entity(230)
|
||||
|
||||
def test_with_no_api_key(self):
|
||||
with pytest.raises(APIKeyMissingError):
|
||||
lib = LookupLib()
|
||||
lib.lookup_entity(230)
|
||||
|
||||
def test_with_file(self, fixCtyXmlFile):
|
||||
lib = LookupLib(filename=fixCtyXmlFile)
|
||||
assert lib.lookup_entity(230) == response_Entity_230
|
||||
|
||||
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
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_entity("foo")
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_entity(1000)
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_entity(999)
|
||||
|
||||
|
||||
#lookup_callsign(callsign, [date])
|
||||
#===============================
|
||||
|
||||
def test_lookup_callsign_same_callsign_different_exceptions(self, fixClublogXML):
|
||||
timestamp = datetime(year=1990, month=10, day=12, tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_callsign("kc6mm", timestamp) == response_Exception_KC6MM_1990
|
||||
|
||||
timestamp = datetime(year=1992, month=3, day=8, tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_callsign("kc6mm", timestamp) == response_Exception_KC6MM_1992
|
||||
|
||||
def test_lookup_callsign_exception_only_with_start_date(self, fixClublogXML):
|
||||
#timestamp > startdate
|
||||
timestamp = datetime(year=1962, month=7, day=7, tzinfo=UTC)
|
||||
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
|
||||
timestamp = datetime(year=1962, month=7, day=5, tzinfo=UTC)
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_callsign("vk9xo", timestamp)
|
||||
|
||||
def test_lookup_callsign_exception_only_with_end_date(self, fixClublogXML):
|
||||
|
||||
#timestamp < enddate
|
||||
timestamp = datetime(year=1975, month=9, day=14, tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_callsign("vk9xx", timestamp) == response_Exception_VK9XX_with_end_date
|
||||
|
||||
# timestamp > enddate
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_callsign("vk9xx")
|
||||
|
||||
timestamp = datetime(year=1975, month=9, day=16, tzinfo=UTC)
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_callsign("vk9xx", timestamp)
|
||||
|
||||
def test_lookup_callsign_exception_no_start_nor_end_date(self, fixClublogXML):
|
||||
|
||||
timestamp = datetime(year=1975, month=9, day=14, tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_callsign("ax9nyg", timestamp) == response_Exception_AX9NYG
|
||||
assert fixClublogXML.lookup_callsign("ax9nyg" ) == response_Exception_AX9NYG
|
||||
|
||||
|
||||
|
||||
#lookup_prefix(prefix, [date])
|
||||
#=========================
|
||||
|
||||
def test_lookup_prefix(self, fixClublogXML):
|
||||
assert fixClublogXML.lookup_prefix("DH") == response_Prefix_DH
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_prefix("QRM")
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_prefix("")
|
||||
|
||||
|
||||
def test_lookup_prefix_with_changing_entities(self, fixClublogXML):
|
||||
#return old entity (PAPUA TERR)
|
||||
timestamp = datetime(year=1975, month=9, day=14).replace(tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_prefix("VK9", timestamp) == response_Prefix_VK9_until_1975
|
||||
|
||||
#return empty dict - Prefix was not assigned at that time
|
||||
timestamp = datetime(year=1975, month=9, day=16).replace(tzinfo=UTC)
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_prefix("VK9", timestamp)
|
||||
|
||||
#return new entity (Norfolk Island)
|
||||
timestamp = datetime.utcnow().replace(tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_prefix("VK9", timestamp ) == response_Prefix_VK9_starting_1976
|
||||
|
||||
def test_lookup_prefix_with_entities_having_start_and_stop(self, fixClublogXML):
|
||||
|
||||
timestamp_before = datetime(year=1964, month=11, day=1).replace(tzinfo=UTC)
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_prefix("ZD5", timestamp_before)
|
||||
|
||||
timestamp_valid = datetime(year=1964, month=12, day=2).replace(tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_prefix("ZD5", timestamp_valid) == response_Prefix_ZD5_1964_to_1971
|
||||
|
||||
timestamp_after = datetime(year=1971, month=8, day=1).replace(tzinfo=UTC)
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_prefix("ZD5", timestamp_after)
|
||||
|
||||
|
||||
|
||||
#is_invalid_operation(callsign, [date])
|
||||
#====================================
|
||||
|
||||
def test_is_invalid_operations(self, fixClublogXML):
|
||||
|
||||
#No dataset --> default Operation is True
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.is_invalid_operation("dh1tw")
|
||||
|
||||
#Invalid Operation with start and end date
|
||||
timestamp_before = datetime(year=1993, month=12, day=30).replace(tzinfo=UTC)
|
||||
timestamp = datetime(year=1994, month=12, day=30).replace(tzinfo=UTC)
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.is_invalid_operation("vk0mc")
|
||||
|
||||
assert fixClublogXML.is_invalid_operation("vk0mc", timestamp)
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.is_invalid_operation("vk0mc", timestamp_before)
|
||||
|
||||
#Invalid Operation with start date
|
||||
timestamp_before = datetime(year=2012, month=1, day=31).replace(tzinfo=UTC)
|
||||
assert fixClublogXML.is_invalid_operation("5W1CFN")
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.is_invalid_operation("5W1CFN", timestamp_before)
|
||||
|
||||
#Invalid Operation with end date
|
||||
timestamp_before = datetime(year=2004, month=04, day=02).replace(tzinfo=UTC)
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.is_invalid_operation("T33C")
|
||||
|
||||
assert fixClublogXML.is_invalid_operation("T33C", timestamp_before)
|
||||
|
||||
|
||||
|
||||
#lookup_zone_exception(callsign, [date])
|
||||
#====================================
|
||||
|
||||
def test_lookup_zone_exception(self, fixClublogXML):
|
||||
|
||||
#No dataset --> default answer: None
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_zone_exception("dh1tw")
|
||||
|
||||
#zone exception with no date
|
||||
assert fixClublogXML.lookup_zone_exception("dp0gvn") == 38
|
||||
|
||||
#zone exception with start and end date
|
||||
timestamp = datetime(year=1992, month=10, day=2).replace(tzinfo=UTC)
|
||||
timestamp_before = datetime(year=1992, month=9, day=30).replace(tzinfo=UTC)
|
||||
timestamp_after = datetime(year=1993, month=03, day=1).replace(tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp) == 38
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp_before)
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_zone_exception("dl1kvc/p", timestamp_after)
|
||||
|
||||
#zone exception with start date
|
||||
timestamp_before = datetime(year=2013, month=12, day=26).replace(tzinfo=UTC)
|
||||
assert fixClublogXML.lookup_zone_exception("dh1hb/p")
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixClublogXML.lookup_zone_exception("dh1hb/p", timestamp_before)
|
||||
97
test/test_lookuplib_countryfile.py
Normal file
97
test/test_lookuplib_countryfile.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
import pytest
|
||||
from datetime import datetime
|
||||
|
||||
from pyhamtools.lookuplib import LookupLib
|
||||
from pyhamtools.exceptions import APIKeyMissingError, NoResult, LookupError
|
||||
|
||||
#Fixtures
|
||||
#===========================================================
|
||||
|
||||
response_Prefix_DH = {
|
||||
'adif': 230,
|
||||
'country': 'Fed. Rep. of Germany',
|
||||
'continent': 'EU',
|
||||
'latitude': 51.0,
|
||||
'longitude': -10.0,
|
||||
'cqz': 14,
|
||||
'ituz' : 28
|
||||
}
|
||||
|
||||
|
||||
response_Exception_3D2RI = {
|
||||
'adif': 460,
|
||||
'country': 'Rotuma Island',
|
||||
'continent': 'OC',
|
||||
'latitude': -12.48,
|
||||
'longitude': -177.08,
|
||||
'cqz': 32,
|
||||
'ituz' : 56
|
||||
}
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def fixPlistFile(request):
|
||||
return "/Users/user/projects/pyhamtools/pyhamtools/cty.plist"
|
||||
|
||||
|
||||
#TESTS
|
||||
#===========================================================
|
||||
|
||||
#@pytest.mark.skipif(True, reason="slow test")
|
||||
class Test_Countryfile_Constructor:
|
||||
|
||||
def test_object_construction_with_invalid_files(self):
|
||||
with pytest.raises(AttributeError):
|
||||
LookupLib("countryfile", download=False)
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
LookupLib("countryfile", filename="", download=False)
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
LookupLib("countryfile", filename="foo bar", download=False)
|
||||
|
||||
|
||||
|
||||
|
||||
class Test_countryfile_Getter_Setter:
|
||||
|
||||
#lookup_entity(adif)
|
||||
#===============================
|
||||
def test_getException(self, fixCountryFile):
|
||||
with pytest.raises(NoResult):
|
||||
fixCountryFile.lookup_entity(230)
|
||||
|
||||
|
||||
#lookup_callsign(callsign, [date])
|
||||
#===============================
|
||||
def test_getException(self, fixCountryFile):
|
||||
assert fixCountryFile.lookup_callsign("3D2RI") == response_Exception_3D2RI
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixCountryFile.lookup_callsign("QRM")
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixCountryFile.lookup_callsign("")
|
||||
|
||||
|
||||
#lookup_prefix(prefix, [date])
|
||||
#=========================
|
||||
def test_lookup_prefix(self, fixCountryFile):
|
||||
assert fixCountryFile.lookup_prefix("DH") == response_Prefix_DH
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixCountryFile.lookup_prefix("QRM")
|
||||
|
||||
with pytest.raises(NoResult):
|
||||
fixCountryFile.lookup_prefix("")
|
||||
|
||||
#is_invalid_operation(callsign, [date])
|
||||
#===============================
|
||||
def test_is_invalid_operation(self, fixCountryFile):
|
||||
with pytest.raises(NoResult):
|
||||
fixCountryFile.is_invalid_operation("5W1CFN")
|
||||
|
||||
#lookup_zone_exception(callsign, [date])
|
||||
#====================================
|
||||
def test_lookup_zone_exception(self, fixCountryFile):
|
||||
with pytest.raises(NoResult):
|
||||
fixCountryFile.lookup_zone_exception("dp0gvn")
|
||||
207
test/test_lookuplib_gettersetter_api.py
Normal file
207
test/test_lookuplib_gettersetter_api.py
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pyhamtools.exceptions import NoResult
|
||||
|
||||
#Fixtures
|
||||
#===========================================================
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", params=[112, 5, "", "dh1tw", 11.5, -5, {}, []])
|
||||
def fixEntities(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="function", params=["dh1tw", "VE9ST/NA14", "VA3RLG/PM", "", 5, 12.5, -9999, {}, []])
|
||||
def fixExceptions(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="function", params=["DH", "DH1TW", "", 5, 12.5, -9999, {}, []])
|
||||
def fixPrefixes(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="function", params=["DH1TW", "JA3UB/GAZA", "", 5, 12.5, -9999, {}, []])
|
||||
def fixInvalidOperations(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="function", params=["DH1TW", "ve8ev", "", 5, 12.5, -9999, {}, []])
|
||||
def fixZoneExceptions(request):
|
||||
return request.param
|
||||
|
||||
@pytest.fixture(scope="function", params=[{"DH1TW": {'latitude': 51.0, 'country': 'FEDERAL REPUBLIC OF GERMANY',
|
||||
'continent': 'EU', 'longitude': -10.0, 'cqz': 14}}, {}, "ve8ev", "", 5, 12.5, -9999])
|
||||
def fixSetExceptions(request):
|
||||
return request.param
|
||||
|
||||
|
||||
|
||||
#TESTS
|
||||
#===========================================================
|
||||
|
||||
class Test_Getter_Setter_Api_Types_for_all_sources:
|
||||
|
||||
def test_lookup_entity_without_entity_nr(self, fixGeneralApi):
|
||||
with pytest.raises(LookupError):
|
||||
fixGeneralApi.lookup_entity()
|
||||
|
||||
def test_lookup_entity(self, fixGeneralApi, fixEntities):
|
||||
try:
|
||||
entity = fixGeneralApi.lookup_entity(fixEntities)
|
||||
|
||||
assert type(entity) is dict
|
||||
if len(entity) > 0:
|
||||
count = 0
|
||||
for attr in entity:
|
||||
if attr == "country":
|
||||
assert type(entity[attr] is str)
|
||||
count +=1
|
||||
if attr == "continent":
|
||||
assert type(entity[attr] is str)
|
||||
count +=1
|
||||
if attr == "prefix":
|
||||
assert type(entity[attr] is str)
|
||||
count +=1
|
||||
if attr == "deleted":
|
||||
assert type(entity[attr] is bool)
|
||||
count +=1
|
||||
if attr == "cqz":
|
||||
assert type(entity[attr] is int)
|
||||
count +=1
|
||||
if attr == "longitude":
|
||||
assert type(entity[attr] is float)
|
||||
count +=1
|
||||
if attr == "latitude":
|
||||
assert type(entity[attr] is float)
|
||||
count +=1
|
||||
if attr == "start":
|
||||
assert type(entity[attr] is datetime)
|
||||
count +=1
|
||||
if attr == "end":
|
||||
assert type(entity[attr] is datetime)
|
||||
count +=1
|
||||
if attr == "whitelist":
|
||||
assert type(entity[attr] is bool)
|
||||
count +=1
|
||||
if attr == "whitelist_start":
|
||||
assert type(entity[attr] is datetime)
|
||||
count +=1
|
||||
if attr == "whitelist_end":
|
||||
assert type(entity[attr] is datetime)
|
||||
count +=1
|
||||
assert len(entity) == count
|
||||
except NoResult:
|
||||
pass
|
||||
|
||||
def test_lookup_callsign(self, fixGeneralApi, fixExceptions):
|
||||
try:
|
||||
ex = fixGeneralApi.lookup_callsign(fixExceptions)
|
||||
assert type(ex) is dict
|
||||
count = 0
|
||||
for attr in ex:
|
||||
if attr == "latitude":
|
||||
assert type(ex[attr]) is float
|
||||
count +=1
|
||||
elif attr == "longitude":
|
||||
assert type(ex[attr]) is float
|
||||
count +=1
|
||||
elif attr == "country":
|
||||
assert type(ex[attr]) is str
|
||||
count +=1
|
||||
elif attr == "continent":
|
||||
assert type(ex[attr]) is str
|
||||
count +=1
|
||||
elif attr == "cqz":
|
||||
assert type(ex[attr]) is int
|
||||
count +=1
|
||||
elif attr == "ituz":
|
||||
assert type(ex[attr]) is int
|
||||
count +=1
|
||||
elif attr == "start":
|
||||
assert type(ex[attr]) is datetime
|
||||
count +=1
|
||||
elif attr == "end":
|
||||
assert type(ex[attr]) is datetime
|
||||
count +=1
|
||||
elif attr == "adif":
|
||||
assert type(ex[attr]) is int
|
||||
count +=1
|
||||
|
||||
#all attributes checked?
|
||||
assert len(ex) == count
|
||||
except NoResult:
|
||||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def test_lookup_prefix(self, fixGeneralApi, fixPrefixes):
|
||||
|
||||
try:
|
||||
prefix = fixGeneralApi.lookup_prefix(fixPrefixes)
|
||||
assert type(prefix) is dict
|
||||
count = 0
|
||||
for attr in prefix:
|
||||
if attr == "country":
|
||||
assert type(prefix[attr]) is str
|
||||
count +=1
|
||||
elif attr == "adif":
|
||||
assert type(prefix[attr]) is int
|
||||
count +=1
|
||||
elif attr == "cqz":
|
||||
assert type(prefix[attr]) is int
|
||||
count +=1
|
||||
elif attr == "ituz":
|
||||
assert type(prefix[attr]) is int
|
||||
count +=1
|
||||
elif attr == "continent":
|
||||
assert type(prefix[attr]) is str
|
||||
count +=1
|
||||
elif attr == "latitude":
|
||||
assert type(prefix[attr]) is float
|
||||
count +=1
|
||||
elif attr == "longitude":
|
||||
assert type(prefix[attr]) is float
|
||||
count +=1
|
||||
elif attr == "start":
|
||||
assert type(prefix[attr]) is datetime
|
||||
count +=1
|
||||
elif attr == "end":
|
||||
assert type(prefix[attr]) is datetime
|
||||
count +=1
|
||||
|
||||
#all attributes checked?
|
||||
assert len(prefix) == count
|
||||
except NoResult:
|
||||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
def test_get_InvalidOperation(self, fixGeneralApi, fixInvalidOperations):
|
||||
try:
|
||||
invOp = fixGeneralApi.is_invalid_operation(fixInvalidOperations)
|
||||
assert type(invOp) is bool
|
||||
except NoResult:
|
||||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def test_get_ZoneException(self, fixGeneralApi, fixZoneExceptions):
|
||||
try:
|
||||
zEx = fixGeneralApi.lookup_zone_exception(fixZoneExceptions)
|
||||
assert type(zEx) is int
|
||||
except NoResult:
|
||||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def test_set_Exception(self, fixGeneralApi, fixSetExceptions):
|
||||
try:
|
||||
response = fixGeneralApi.setException(fixSetExceptions)
|
||||
assert type(response) is bool
|
||||
assert fixGeneralApi.lookup_callsign(fixSetExceptions.keys()[0]) == fixSetExceptions[fixSetExceptions.keys()[0]]
|
||||
except NoResult:
|
||||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue