1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
import pytest
from datetime import datetime
#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(Exception):
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 KeyError:
pass
except TypeError:
pass
except ValueError:
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 KeyError:
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 KeyError:
pass
except AttributeError:
pass
def test_get_InvalidOperation(self, fixGeneralApi, fixInvalidOperations):
try:
invOp = fixGeneralApi.is_invalid_operation(fixInvalidOperations)
assert type(invOp) is bool
except KeyError:
pass
except AttributeError:
pass
def test_get_ZoneException(self, fixGeneralApi, fixZoneExceptions):
try:
zEx = fixGeneralApi.lookup_zone_exception(fixZoneExceptions)
assert type(zEx) is int
except KeyError:
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 KeyError:
pass
except AttributeError:
pass
|