Skip to content

Commit

Permalink
Merge pull request #607 from HackerShark/fix/location-object-0-bug
Browse files Browse the repository at this point in the history
Fix for issue #572
  • Loading branch information
rpiazza authored Dec 2, 2024
2 parents 68ba448 + d7b14cb commit 91c09ff
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stix2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def _check_properties_dependency(self, list_of_properties, list_of_dependent_pro
failed_dependency_pairs = []
for p in list_of_properties:
for dp in list_of_dependent_properties:
if not self.get(p) and self.get(dp):
if p not in self and dp in self:
failed_dependency_pairs.append((p, dp))
elif p in self and (self[p] is None or self[p] is False) and dp in self and self[dp] is not None:
failed_dependency_pairs.append((p, dp))
if failed_dependency_pairs:
raise DependentPropertiesError(self.__class__, failed_dependency_pairs)
Expand Down
45 changes: 45 additions & 0 deletions stix2/test/v21/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,48 @@ def test_bing_map_url_multiple_props_and_long_lat_provided():

loc_url = loc.to_maps_url("Bing Maps")
assert loc_url == expected_url


def test_bing_map_url_for_0_long_lat():
expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C0.0&lvl=16"

loc = stix2.v21.Location(
region="Gulf of Guinea",
country="International waters",
street_address="0°N, 0°E – Null Island",
latitude=0.0,
longitude=0.0,
)

loc_url = loc.to_maps_url("Bing Maps")
assert loc_url == expected_url


def test_bing_map_url_for_0_long():
expected_url = "https://bing.com/maps/default.aspx?where1=0.0%2C39.668&lvl=16"

loc = stix2.v21.Location(
region="Eastern Africa",
country="Kenya",
street_address="0°N, 39.668°E",
latitude=0.0,
longitude=39.668,
)

loc_url = loc.to_maps_url("Bing Maps")
assert loc_url == expected_url


def test_bing_map_url_for_0_lat():
expected_url = "https://bing.com/maps/default.aspx?where1=51.477%2C0.0&lvl=16"

loc = stix2.v21.Location(
region="Western Europe",
country="United Kingdom",
street_address="Royal Observatory, Blackheath Ave, Greenwich, London SE10 8XJ, United Kingdom",
latitude=51.477,
longitude=0.0,
)

loc_url = loc.to_maps_url("Bing Maps")
assert loc_url == expected_url

0 comments on commit 91c09ff

Please sign in to comment.