2014-04-24 14:01:53 +02:00
|
|
|
import pytest
|
2014-04-25 23:46:44 +02:00
|
|
|
import os
|
2014-04-24 14:01:53 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
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_Prefix_DH = {
|
|
|
|
|
'adif': 230,
|
|
|
|
|
'country': 'Fed. Rep. of Germany',
|
|
|
|
|
'continent': '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,
|
|
|
|
|
'ituz' : 28
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response_Exception_3D2RI = {
|
|
|
|
|
'adif': 460,
|
|
|
|
|
'country': 'Rotuma Island',
|
|
|
|
|
'continent': 'OC',
|
|
|
|
|
'latitude': -12.48,
|
2018-01-27 15:11:46 +01:00
|
|
|
'longitude': 177.08,
|
2014-04-24 14:01:53 +02:00
|
|
|
'cqz': 32,
|
|
|
|
|
'ituz' : 56
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
2014-04-25 23:46:44 +02:00
|
|
|
def fix_plist_file(request):
|
|
|
|
|
dir = os.path.dirname(__file__)
|
|
|
|
|
cty_file_rel = "./fixtures/cty.plist"
|
|
|
|
|
cty_file_abs = os.path.join(dir, cty_file_rel)
|
|
|
|
|
return cty_file_abs
|
2014-04-24 14:01:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#TESTS
|
|
|
|
|
#===========================================================
|
|
|
|
|
|
|
|
|
|
#@pytest.mark.skipif(True, reason="slow test")
|
|
|
|
|
class Test_Countryfile_Constructor:
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
def test_constructor_with_file_instead_of_downlad(self, fix_plist_file):
|
|
|
|
|
lib = LookupLib("countryfile", filename=fix_plist_file)
|
|
|
|
|
assert lib.lookup_callsign("3D2RI") == response_Exception_3D2RI
|
2014-04-24 14:01:53 +02:00
|
|
|
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
def test_constructor_with_invalid_file(self):
|
|
|
|
|
with pytest.raises(IOError):
|
|
|
|
|
lib = LookupLib("countryfile", filename="foo bar")
|
|
|
|
|
lib.lookup_callsign("GB0BVL")
|
2014-04-24 14:01:53 +02:00
|
|
|
|
|
|
|
|
class Test_countryfile_Getter_Setter:
|
|
|
|
|
|
|
|
|
|
#lookup_entity(adif)
|
|
|
|
|
#===============================
|
|
|
|
|
def test_getException(self, fixCountryFile):
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixCountryFile.lookup_entity(230)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#lookup_callsign(callsign, [date])
|
|
|
|
|
#===============================
|
|
|
|
|
def test_getException(self, fixCountryFile):
|
|
|
|
|
assert fixCountryFile.lookup_callsign("3D2RI") == response_Exception_3D2RI
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixCountryFile.lookup_callsign("QRM")
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixCountryFile.lookup_callsign("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#lookup_prefix(prefix, [date])
|
|
|
|
|
#=========================
|
|
|
|
|
def test_lookup_prefix(self, fixCountryFile):
|
|
|
|
|
assert fixCountryFile.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
|
|
|
fixCountryFile.lookup_prefix("QRM")
|
|
|
|
|
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixCountryFile.lookup_prefix("")
|
|
|
|
|
|
|
|
|
|
#is_invalid_operation(callsign, [date])
|
|
|
|
|
#===============================
|
|
|
|
|
def test_is_invalid_operation(self, fixCountryFile):
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixCountryFile.is_invalid_operation("5W1CFN")
|
|
|
|
|
|
|
|
|
|
#lookup_zone_exception(callsign, [date])
|
|
|
|
|
#====================================
|
|
|
|
|
def test_lookup_zone_exception(self, fixCountryFile):
|
2014-04-25 23:46:44 +02:00
|
|
|
with pytest.raises(KeyError):
|
2014-04-24 14:01:53 +02:00
|
|
|
fixCountryFile.lookup_zone_exception("dp0gvn")
|