Skip to content

Commit

Permalink
Fixing broken URL tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whubsch committed Aug 1, 2024
1 parent 3ad7453 commit 1c888f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/overturetoosm/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def process_place(
new_props["phone"] = prop_obj.phones[0]

if prop_obj.websites is not None:
new_props["website"] = prop_obj.websites[0]
new_props["website"] = str(prop_obj.websites[0])

if add := prop_obj.addresses[0]:
if add.freeform:
Expand All @@ -89,10 +89,11 @@ def process_place(

if prop_obj.socials is not None:
for social in prop_obj.socials:
if "facebook" in str(social):
new_props["contact:facebook"] = social
social_str = str(social)
if "facebook" in social_str:
new_props["contact:facebook"] = social_str
elif "twitter" in str(social):
new_props["contact:twitter"] = social
new_props["contact:twitter"] = social_str

if prop_obj.brand:
new_props["brand"] = prop_obj.brand.names.primary
Expand Down
16 changes: 8 additions & 8 deletions tests/test_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def clean_fix() -> Dict[str, Any]:
"addr:state": "CA",
"addr:country": "US",
"phone": "+1234567890",
"website": "https://example.com",
"website": "https://example.com/",
"source": "dataset1 via overturetoosm",
"office": "lawyer",
"lawyer": "notary",
"contact:facebook": "https://www.facebook.com/example",
"contact:facebook": "https://www.facebook.com/example/",
}


Expand Down Expand Up @@ -71,8 +71,8 @@ def geojson_fix() -> Dict[str, Any]:
"alternate": ["alternate_category1", "alternate_category2"],
},
"confidence": 0.8,
"websites": ["https://example.com"],
"socials": ["https://www.facebook.com/example"],
"websites": ["https://example.com/"],
"socials": ["https://www.facebook.com/example/"],
"phones": ["+1234567890"],
"addresses": [
{
Expand Down Expand Up @@ -122,8 +122,8 @@ def props_fix() -> Dict[str, Any]:
"alternate": ["alternate_category1", "alternate_category2"],
},
"confidence": 0.8,
"websites": ["https://example.com"],
"socials": ["https://www.facebook.com/example"],
"websites": ["https://example.com/"],
"socials": ["https://www.facebook.com/example/"],
"phones": ["+1234567890"],
"addresses": [
{
Expand Down Expand Up @@ -163,9 +163,9 @@ def test_place_props_no_category(props_dict: dict, clean_dict: dict) -> None:

def test_place_props_twitter(props_dict: dict, clean_dict: dict) -> None:
"""Test that all properties are processed correctly"""
props_dict["socials"].append("https://twitter.com/example")
props_dict["socials"].append("https://twitter.com/example/")
new_props = process_place(props_dict)
clean_dict["contact:twitter"] = "https://twitter.com/example"
clean_dict["contact:twitter"] = "https://twitter.com/example/"
assert new_props == clean_dict


Expand Down

0 comments on commit 1c888f7

Please sign in to comment.