Added Push to Redis and Redis as a LookupLib

This commit is contained in:
dh1tw 2014-05-08 15:03:16 +02:00
parent d6d90d3e2a
commit 8216f488ef
11 changed files with 602 additions and 224 deletions

View file

@ -72,4 +72,9 @@ def fixCountryFile(request):
def fix_callinfo(request, fixApiKey):
lib = LookupLib(request.param, fixApiKey)
callinfo = Callinfo(lib)
return(callinfo)
return(callinfo)
@pytest.fixture(scope="module")
def fix_redis():
import redis
return LookupLib(lookuptype="redis", redis_instance=redis.Redis(), redis_prefix="clx")

View file

@ -48,7 +48,6 @@ response_prefix_C6A_countryfile = {
}
response_Exception_VK9XO_with_start_date = {
'adif': 35,
'country': 'CHRISTMAS ISLAND',
@ -72,6 +71,24 @@ response_lat_long_dh1tw = {
const.LONGITUDE: -10.0
}
response_maritime_mobile = {
'adif': 999,
'continent': '',
'country': 'MARITIME MOBILE',
'cqz': 0,
'latitude': 0.0,
'longitude': 0.0
}
response_aircraft_mobile = {
'adif': 998,
'continent': '',
'country': 'AIRCAFT MOBILE',
'cqz': 0,
'latitude': 0.0,
'longitude': 0.0
}
class Test_callinfo_methods:
def test_callinfo_iterate_prefix(self, fix_callinfo):
@ -87,31 +104,38 @@ class Test_callinfo_methods:
with pytest.raises(KeyError):
fix_callinfo._iterate_prefix("QRM")
def test_is_maritime_mobile(self, fix_callinfo):
assert fix_callinfo.check_if_mm("DH1TW/MM")
assert not fix_callinfo.check_if_mm("DH1TW")
def test_is_aircraft_mobile(self, fix_callinfo):
assert fix_callinfo.check_if_am("DH1TW/AM")
assert not fix_callinfo.check_if_am("DH1TW")
def test_if_beacon(self, fix_callinfo):
assert fix_callinfo.check_if_beacon("DH1TW/B")
assert fix_callinfo.check_if_beacon("DH1TW/BCN")
assert not fix_callinfo.check_if_beacon("DH1TW")
def test_get_homecall(self, fix_callinfo):
assert fix_callinfo.get_homecall("HB9/DH1TW") == "DH1TW"
assert fix_callinfo.get_homecall("SM3/DH1TW/P") == "DH1TW"
assert fix_callinfo.get_homecall("QRM") is None
with pytest.raises(ValueError):
fix_callinfo.get_homecall("QRM")
def test_dismantle_callsign(self, fix_callinfo):
if fix_callinfo._lookuplib._lookuptype == "clublogxml" or fix_callinfo._lookuplib._lookuptype == "countryfile":
with pytest.raises(KeyError):
fix_callinfo._dismantle_callsign("DH1TW/MM")
with pytest.raises(KeyError):
fix_callinfo._dismantle_callsign("DH1TW/AM")
if fix_callinfo._lookuplib._lookuptype == "clublogxml":
#assert fix_callinfo._dismantle_callsign("DH1TW/BCN")[const.BEACON]
assert fix_callinfo._dismantle_callsign("DH1TW/QRP") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/QRPP") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/BCN") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/LH") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("HC2AO/DL") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/P") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/5") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/M") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/B") == response_prefix_DH_clublog
#assert fix_callinfo._dismantle_callsign("DH1TW/B")[const.BEACON]
assert fix_callinfo._dismantle_callsign("DH1TW") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DH1TW/B") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("DL/HC2AO") == response_prefix_DH_clublog
assert fix_callinfo._dismantle_callsign("9H5A/C6A") == response_prefix_C6A_clublog
# assert fix_callinfo._dismantle_callsign("C6A/9H5A") == response_Prefix_C6A
@ -119,15 +143,14 @@ class Test_callinfo_methods:
if fix_callinfo._lookuplib._lookuptype == "countryfile":
assert fix_callinfo._dismantle_callsign("DH1TW/QRP") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DH1TW/QRPP") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DH1TW/BCN") == response_prefix_DH_countryfile
#assert fix_callinfo._dismantle_callsign("DH1TW/BCN")[const.BEACON]
assert fix_callinfo._dismantle_callsign("DH1TW/LH") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("HC2AO/DL") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DH1TW/P") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DH1TW/5") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DH1TW/M") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DH1TW/B") == response_prefix_DH_countryfile
#assert fix_callinfo._dismantle_callsign("DH1TW/B")[const.BEACON]
assert fix_callinfo._dismantle_callsign("DH1TW") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DH1TW/B") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("DL/HC2AO") == response_prefix_DH_countryfile
assert fix_callinfo._dismantle_callsign("9H5A/C6A") == response_prefix_C6A_countryfile
# assert fix_callinfo._dismantle_callsign("C6A/9H5A") == response_Prefix_C6A
@ -135,12 +158,18 @@ class Test_callinfo_methods:
def test_lookup_callsign(selfself, fix_callinfo):
assert fix_callinfo._lookup_callsign("DH1TW/MM") == response_maritime_mobile
assert fix_callinfo._lookup_callsign("DH1TW/AM") == response_aircraft_mobile
if fix_callinfo._lookuplib._lookuptype == "clublogxml" or fix_callinfo._lookuplib._lookuptype == "clublogapi":
with pytest.raises(KeyError):
fix_callinfo._lookup_callsign("5W1CFN")
assert fix_callinfo._lookup_callsign("DH1TW/BCN")[const.BEACON]
assert fix_callinfo._lookup_callsign("VK9XO") == response_Exception_VK9XO_with_start_date
assert fix_callinfo._lookup_callsign("DH1TW") == response_prefix_DH_clublog
elif fix_callinfo._lookuplib._lookuptype == "countryfile":
assert fix_callinfo._lookup_callsign("DH1TW") == response_prefix_DH_countryfile
with pytest.raises(KeyError):
@ -158,6 +187,8 @@ class Test_callinfo_methods:
elif fix_callinfo._lookuplib._lookuptype == "countryfile":
assert fix_callinfo.get_all("DH1TW") == response_prefix_DH_countryfile
assert fix_callinfo.get_all("DH1TW/MM") == response_maritime_mobile
def test_is_valid_callsign(self, fix_callinfo):
assert fix_callinfo.is_valid_callsign("DH1TW")
assert not fix_callinfo.is_valid_callsign("QRM")

View file

@ -142,7 +142,7 @@ class TestclublogXML_Getters:
assert fixClublogXML.lookup_entity(230) == response_Entity_230
assert fixClublogXML.lookup_entity("230") == response_Entity_230
with pytest.raises(KeyError):
with pytest.raises(ValueError):
fixClublogXML.lookup_entity("foo")
with pytest.raises(KeyError):

View file

@ -41,7 +41,7 @@ def fixSetExceptions(request):
class Test_Getter_Setter_Api_Types_for_all_sources:
def test_lookup_entity_without_entity_nr(self, fixGeneralApi):
with pytest.raises(LookupError):
with pytest.raises(Exception):
fixGeneralApi.lookup_entity()
def test_lookup_entity(self, fixGeneralApi, fixEntities):
@ -91,6 +91,10 @@ class Test_Getter_Setter_Api_Types_for_all_sources:
assert len(entity) == count
except KeyError:
pass
except TypeError:
pass
except ValueError:
pass
def test_lookup_callsign(self, fixGeneralApi, fixExceptions):
try:

View file

@ -1,58 +1,58 @@
import pytest
from pyhamtools.utils import freq_to_band
from pyhamtools.consts import Modes as mode
from pyhamtools.consts import LookupConventions as const
class Test_utils_freq_to_band():
def test_hf_frequencies(self):
assert freq_to_band(137) == {"band" : 2190, "mode":mode.CW}
assert freq_to_band(137) == {"band" : 2190, "mode":const.CW}
assert freq_to_band(1805) == {"band" : 160, "mode":mode.CW}
assert freq_to_band(1838) == {"band" : 160, "mode":mode.DIGITAL}
assert freq_to_band(1870) == {"band" : 160, "mode":mode.LSB}
assert freq_to_band(1805) == {"band" : 160, "mode":const.CW}
assert freq_to_band(1838) == {"band" : 160, "mode":const.DIGITAL}
assert freq_to_band(1870) == {"band" : 160, "mode":const.LSB}
assert freq_to_band(3500) == {"band" : 80, "mode":mode.CW}
assert freq_to_band(3580) == {"band" : 80, "mode":mode.DIGITAL}
assert freq_to_band(3799) == {"band" : 80, "mode":mode.LSB}
assert freq_to_band(3500) == {"band" : 80, "mode":const.CW}
assert freq_to_band(3580) == {"band" : 80, "mode":const.DIGITAL}
assert freq_to_band(3799) == {"band" : 80, "mode":const.LSB}
assert freq_to_band(5200) == {"band" : 60, "mode":None}
assert freq_to_band(7000) == {"band" : 40, "mode":mode.CW}
assert freq_to_band(7044) == {"band" : 40, "mode":mode.DIGITAL}
assert freq_to_band(7139) == {"band" : 40, "mode":mode.LSB}
assert freq_to_band(7000) == {"band" : 40, "mode":const.CW}
assert freq_to_band(7044) == {"band" : 40, "mode":const.DIGITAL}
assert freq_to_band(7139) == {"band" : 40, "mode":const.LSB}
assert freq_to_band(10100) == {"band" : 30, "mode":mode.CW}
assert freq_to_band(10141) == {"band" : 30, "mode":mode.DIGITAL}
assert freq_to_band(10100) == {"band" : 30, "mode":const.CW}
assert freq_to_band(10141) == {"band" : 30, "mode":const.DIGITAL}
assert freq_to_band(14000) == {"band" : 20, "mode":mode.CW}
assert freq_to_band(14070) == {"band" : 20, "mode":mode.DIGITAL}
assert freq_to_band(14349) == {"band" : 20, "mode":mode.USB}
assert freq_to_band(14000) == {"band" : 20, "mode":const.CW}
assert freq_to_band(14070) == {"band" : 20, "mode":const.DIGITAL}
assert freq_to_band(14349) == {"band" : 20, "mode":const.USB}
assert freq_to_band(18068) == {"band" : 17, "mode":mode.CW}
assert freq_to_band(18096) == {"band" : 17, "mode":mode.DIGITAL}
assert freq_to_band(18250) == {"band" : 17, "mode":mode.USB}
assert freq_to_band(18068) == {"band" : 17, "mode":const.CW}
assert freq_to_band(18096) == {"band" : 17, "mode":const.DIGITAL}
assert freq_to_band(18250) == {"band" : 17, "mode":const.USB}
assert freq_to_band(21000) == {"band" : 15, "mode":mode.CW}
assert freq_to_band(21070) == {"band" : 15, "mode":mode.DIGITAL}
assert freq_to_band(21449) == {"band" : 15, "mode":mode.USB}
assert freq_to_band(21000) == {"band" : 15, "mode":const.CW}
assert freq_to_band(21070) == {"band" : 15, "mode":const.DIGITAL}
assert freq_to_band(21449) == {"band" : 15, "mode":const.USB}
assert freq_to_band(24890) == {"band" : 12, "mode":mode.CW}
assert freq_to_band(24916) == {"band" : 12, "mode":mode.DIGITAL}
assert freq_to_band(24965) == {"band" : 12, "mode":mode.USB}
assert freq_to_band(24890) == {"band" : 12, "mode":const.CW}
assert freq_to_band(24916) == {"band" : 12, "mode":const.DIGITAL}
assert freq_to_band(24965) == {"band" : 12, "mode":const.USB}
assert freq_to_band(28000) == {"band" : 10, "mode":mode.CW}
assert freq_to_band(28070) == {"band" : 10, "mode":mode.DIGITAL}
assert freq_to_band(28500) == {"band" : 10, "mode":mode.USB}
assert freq_to_band(28000) == {"band" : 10, "mode":const.CW}
assert freq_to_band(28070) == {"band" : 10, "mode":const.DIGITAL}
assert freq_to_band(28500) == {"band" : 10, "mode":const.USB}
assert freq_to_band(50000) == {"band" : 6, "mode":mode.CW}
assert freq_to_band(50100) == {"band" : 6, "mode":mode.USB}
assert freq_to_band(50500) == {"band" : 6, "mode":mode.DIGITAL}
assert freq_to_band(50000) == {"band" : 6, "mode":const.CW}
assert freq_to_band(50100) == {"band" : 6, "mode":const.USB}
assert freq_to_band(50500) == {"band" : 6, "mode":const.DIGITAL}
def test_vhf_frequencies(self):
assert freq_to_band(70001) == {"band" : 4, "mode":None}
assert freq_to_band(144000) == {"band" : 2, "mode":mode.CW}
assert freq_to_band(144150) == {"band" : 2, "mode":mode.USB}
assert freq_to_band(144000) == {"band" : 2, "mode":const.CW}
assert freq_to_band(144150) == {"band" : 2, "mode":const.USB}
assert freq_to_band(144400) == {"band" : 2, "mode":None}
assert freq_to_band(220000) == {"band" : 1.25, "mode":None}