Add support for Bing Maps and corresponding tests. Fixes #86
parent
516789400b
commit
edfe0ba51a
|
@ -265,7 +265,7 @@ def test_location_lat_or_lon_dependency_missing(data, msg):
|
||||||
assert msg in str(excinfo.value)
|
assert msg in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_map_url_long_lat_provided():
|
def test_google_map_url_long_lat_provided():
|
||||||
EXPECTED_URL = "https://www.google.com/maps/search/?api=1&query=41.862401%2C-87.616001"
|
EXPECTED_URL = "https://www.google.com/maps/search/?api=1&query=41.862401%2C-87.616001"
|
||||||
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ def test_map_url_long_lat_provided():
|
||||||
assert loc_url == EXPECTED_URL
|
assert loc_url == EXPECTED_URL
|
||||||
|
|
||||||
|
|
||||||
def test_map_url_multiple_props_no_long_lat_provided():
|
def test_google_map_url_multiple_props_no_long_lat_provided():
|
||||||
EXPECTED_URL = "https://www.google.com/maps/search/?api=1&query=1410+Museum+Campus+Drive%2C+Chicago%2C+IL+60605%2CUnited+States+of+America%2CNorth+America"
|
EXPECTED_URL = "https://www.google.com/maps/search/?api=1&query=1410+Museum+Campus+Drive%2C+Chicago%2C+IL+60605%2CUnited+States+of+America%2CNorth+America"
|
||||||
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ def test_map_url_multiple_props_no_long_lat_provided():
|
||||||
assert loc_url == EXPECTED_URL
|
assert loc_url == EXPECTED_URL
|
||||||
|
|
||||||
|
|
||||||
def test_map_url_multiple_props_and_long_lat_provided():
|
def test_google_map_url_multiple_props_and_long_lat_provided():
|
||||||
EXPECTED_URL = "https://www.google.com/maps/search/?api=1&query=41.862401%2C-87.616001"
|
EXPECTED_URL = "https://www.google.com/maps/search/?api=1&query=41.862401%2C-87.616001"
|
||||||
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
@ -336,3 +336,58 @@ def test_map_url_invalid_map_engine_provided():
|
||||||
loc.to_maps_url("Fake Maps")
|
loc.to_maps_url("Fake Maps")
|
||||||
|
|
||||||
assert "is not a valid or currently-supported map engine" in str(excinfo.value)
|
assert "is not a valid or currently-supported map engine" in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_bing_map_url_long_lat_provided():
|
||||||
|
EXPECTED_URL = "https://bing.com/maps/default.aspx?where1=41.862401%2C-87.616001&lvl=16"
|
||||||
|
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
loc = stix2.v21.Location(
|
||||||
|
type="location",
|
||||||
|
id=LOCATION_ID,
|
||||||
|
created=now,
|
||||||
|
modified=now,
|
||||||
|
latitude=41.862401,
|
||||||
|
longitude=-87.616001,
|
||||||
|
)
|
||||||
|
|
||||||
|
loc_url = loc.to_maps_url("Bing Maps")
|
||||||
|
assert loc_url == EXPECTED_URL
|
||||||
|
|
||||||
|
|
||||||
|
def test_bing_map_url_multiple_props_no_long_lat_provided():
|
||||||
|
EXPECTED_URL = "https://bing.com/maps/default.aspx?where1=1410+Museum+Campus+Drive%2C+Chicago%2C+IL+60605%2CUnited+States+of+America%2CNorth+America&lvl=16"
|
||||||
|
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
loc = stix2.v21.Location(
|
||||||
|
type="location",
|
||||||
|
id=LOCATION_ID,
|
||||||
|
created=now,
|
||||||
|
modified=now,
|
||||||
|
region="North America",
|
||||||
|
country="United States of America",
|
||||||
|
street_address="1410 Museum Campus Drive, Chicago, IL 60605",
|
||||||
|
)
|
||||||
|
|
||||||
|
loc_url = loc.to_maps_url("Bing Maps")
|
||||||
|
assert loc_url == EXPECTED_URL
|
||||||
|
|
||||||
|
|
||||||
|
def test_bing_map_url_multiple_props_and_long_lat_provided():
|
||||||
|
EXPECTED_URL = "https://bing.com/maps/default.aspx?where1=41.862401%2C-87.616001&lvl=16"
|
||||||
|
now = dt.datetime(2019, 2, 7, 12, 34, 56, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
loc = stix2.v21.Location(
|
||||||
|
type="location",
|
||||||
|
id=LOCATION_ID,
|
||||||
|
created=now,
|
||||||
|
modified=now,
|
||||||
|
region="North America",
|
||||||
|
country="United States of America",
|
||||||
|
street_address="1410 Museum Campus Drive, Chicago, IL 60605",
|
||||||
|
latitude=41.862401,
|
||||||
|
longitude=-87.616001,
|
||||||
|
)
|
||||||
|
|
||||||
|
loc_url = loc.to_maps_url("Bing Maps")
|
||||||
|
assert loc_url == EXPECTED_URL
|
||||||
|
|
|
@ -276,20 +276,34 @@ class Location(STIXDomainObject):
|
||||||
properties = ['street_address', 'city', 'country', 'region', 'administrative_area', 'postal_code']
|
properties = ['street_address', 'city', 'country', 'region', 'administrative_area', 'postal_code']
|
||||||
params = [self.get(prop) for prop in properties if self.get(prop) is not None]
|
params = [self.get(prop) for prop in properties if self.get(prop) is not None]
|
||||||
|
|
||||||
return self._to_maps_url_creator(map_engine, params)
|
return self._to_maps_url_dispatcher(map_engine, params)
|
||||||
|
|
||||||
def _to_maps_url_creator(self, map_engine, params):
|
def _to_maps_url_dispatcher(self, map_engine, params):
|
||||||
if map_engine == "Google Maps":
|
if map_engine == "Google Maps":
|
||||||
url_base = "https://www.google.com/maps/search/?api=1&query="
|
return self._to_google_maps_url(params)
|
||||||
url_ending = params[0]
|
elif map_engine == "Bing Maps":
|
||||||
for i in range(1, len(params)):
|
return self._to_bing_maps_url(params)
|
||||||
url_ending = url_ending + "," + params[i]
|
|
||||||
|
|
||||||
final_url = url_base + quote_plus(url_ending)
|
|
||||||
return final_url
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(map_engine + " is not a valid or currently-supported map engine")
|
raise ValueError(map_engine + " is not a valid or currently-supported map engine")
|
||||||
|
|
||||||
|
def _to_google_maps_url(self, params):
|
||||||
|
url_base = "https://www.google.com/maps/search/?api=1&query="
|
||||||
|
url_ending = params[0]
|
||||||
|
for i in range(1, len(params)):
|
||||||
|
url_ending = url_ending + "," + params[i]
|
||||||
|
|
||||||
|
final_url = url_base + quote_plus(url_ending)
|
||||||
|
return final_url
|
||||||
|
|
||||||
|
def _to_bing_maps_url(self, params):
|
||||||
|
url_base = "https://bing.com/maps/default.aspx?where1="
|
||||||
|
url_ending = params[0]
|
||||||
|
for i in range(1, len(params)):
|
||||||
|
url_ending = url_ending + "," + params[i]
|
||||||
|
|
||||||
|
final_url = url_base + quote_plus(url_ending) + "&lvl=16" # level 16 zoom so long/lat searches shown more clearly
|
||||||
|
return final_url
|
||||||
|
|
||||||
|
|
||||||
class Malware(STIXDomainObject):
|
class Malware(STIXDomainObject):
|
||||||
# TODO: Add link
|
# TODO: Add link
|
||||||
|
|
Loading…
Reference in New Issue