mirror of https://github.com/craigerl/aprsd.git
Fixed unit tests for Location plugin
This commit is contained in:
parent
9931c8a6c5
commit
80b85e648f
|
@ -68,10 +68,12 @@ class LocationPlugin(plugin.APRSDRegexCommandPluginBase, plugin.APRSFIKEYMixin):
|
||||||
area_info = f"{address.get('county')}, {address.get('state')}"
|
area_info = f"{address.get('county')}, {address.get('state')}"
|
||||||
else:
|
else:
|
||||||
# what to do for address for non US?
|
# what to do for address for non US?
|
||||||
area_info = f"{address.get('country')}"
|
area_info = f"{address.get('country'), 'Unknown'}"
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error(f"Failed to fetch Geopy address {ex}")
|
LOG.error(f"Failed to fetch Geopy address {ex}")
|
||||||
area_info = ""
|
print("FUICK")
|
||||||
|
print(ex)
|
||||||
|
area_info = "Unknown Location"
|
||||||
|
|
||||||
try: # altitude not always provided
|
try: # altitude not always provided
|
||||||
alt = float(aprs_data["entries"][0]["altitude"])
|
alt = float(aprs_data["entries"][0]["altitude"])
|
||||||
|
|
|
@ -49,51 +49,61 @@ class TestLocationPlugin(test_plugin.TestPlugin):
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
@mock.patch("aprsd.plugin_utils.get_aprs_fi")
|
@mock.patch("aprsd.plugin_utils.get_aprs_fi")
|
||||||
@mock.patch("aprsd.plugin_utils.get_weather_gov_for_gps")
|
@mock.patch("geopy.geocoders.Nominatim.reverse")
|
||||||
@mock.patch("time.time")
|
@mock.patch("time.time")
|
||||||
def test_location_unknown_gps(self, mock_time, mock_weather, mock_check_aprs):
|
def test_location_unknown_gps(self, mock_time, mock_geocode, mock_check_aprs):
|
||||||
# When the aprs.fi api key isn't set, then
|
# When the aprs.fi api key isn't set, then
|
||||||
# the LocationPlugin will be disabled.
|
# the LocationPlugin will be disabled.
|
||||||
mock_check_aprs.return_value = {
|
mock_check_aprs.return_value = {
|
||||||
"entries": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"lat": 10,
|
"lat": 1,
|
||||||
"lng": 11,
|
"lng": 1,
|
||||||
"lasttime": 10,
|
"lasttime": 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
mock_weather.side_effect = Exception
|
mock_geocode.side_effect = Exception
|
||||||
mock_time.return_value = 10
|
mock_time.return_value = 10
|
||||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||||
fortune = location_plugin.LocationPlugin()
|
fortune = location_plugin.LocationPlugin()
|
||||||
expected = "KFAKE: Unknown Location 0' 10,11 0.0h ago"
|
expected = "KFAKE: Unknown Location 0' 1.00,1.00 0.0h ago"
|
||||||
packet = fake.fake_packet(message="location")
|
packet = fake.fake_packet(message="location")
|
||||||
actual = fortune.filter(packet)
|
actual = fortune.filter(packet)
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
@mock.patch("aprsd.plugin_utils.get_aprs_fi")
|
@mock.patch("aprsd.plugin_utils.get_aprs_fi")
|
||||||
@mock.patch("aprsd.plugin_utils.get_weather_gov_for_gps")
|
@mock.patch("geopy.geocoders.Nominatim.reverse")
|
||||||
@mock.patch("time.time")
|
@mock.patch("time.time")
|
||||||
def test_location_works(self, mock_time, mock_weather, mock_check_aprs):
|
def test_location_works(self, mock_time, mock_geocode, mock_check_aprs):
|
||||||
# When the aprs.fi api key isn't set, then
|
# When the aprs.fi api key isn't set, then
|
||||||
# the LocationPlugin will be disabled.
|
# the LocationPlugin will be disabled.
|
||||||
mock_check_aprs.return_value = {
|
mock_check_aprs.return_value = {
|
||||||
"entries": [
|
"entries": [
|
||||||
{
|
{
|
||||||
"lat": 10,
|
"lat": 1,
|
||||||
"lng": 11,
|
"lng": 1,
|
||||||
"lasttime": 10,
|
"lasttime": 10,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
expected_town = "Appomattox, VA"
|
expected = "Appomattox"
|
||||||
wx_data = {"location": {"areaDescription": expected_town}}
|
state = "VA"
|
||||||
mock_weather.return_value = wx_data
|
|
||||||
|
class TempLocation:
|
||||||
|
raw = {
|
||||||
|
"address": {
|
||||||
|
"county": expected,
|
||||||
|
"country_code": "us",
|
||||||
|
"state": state,
|
||||||
|
"country": "United States",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
mock_geocode.return_value = TempLocation()
|
||||||
mock_time.return_value = 10
|
mock_time.return_value = 10
|
||||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||||
fortune = location_plugin.LocationPlugin()
|
fortune = location_plugin.LocationPlugin()
|
||||||
expected = f"KFAKE: {expected_town} 0' 10,11 0.0h ago"
|
expected = f"KFAKE: {expected}, {state} 0' 1.00,1.00 0.0h ago"
|
||||||
packet = fake.fake_packet(message="location")
|
packet = fake.fake_packet(message="location")
|
||||||
actual = fortune.filter(packet)
|
actual = fortune.filter(packet)
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
Loading…
Reference in New Issue