Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update geocoder_api.py #77

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions herepy/geocoder_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def address_with_boundingbox(

def address_with_details(
self,
house_number: int,
street: str,
city: str,
country: str,
lang: str = "en-US",
house_number: Optional[int] = None,
street: Optional[str] = None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

) -> Optional[GeocoderResponse]:
"""Geocodes with given address details
Args:
Expand All @@ -129,11 +129,16 @@ def address_with_details(
Raises:
HEREError"""

qq_query = ""
if house_number is not None:
qq_query += f"houseNumber={house_number};"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add new test cases to cover the optional parameters?

if street is not None:
qq_query += f"street={street};"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

qq_query += f"city={city};"
qq_query += f"country={country}"

data = {
"qq": str.format("houseNumber={0};", house_number)
+ str.format("street={0};", street)
+ str.format("city={0};", city)
+ str.format("country={0}", country),
"qq": qq_query,
"apiKey": self._api_key,
"lang": lang,
}
Expand Down
45 changes: 44 additions & 1 deletion tests/test_geocoder_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,53 @@ def test_addresswithdetails_whensucceed(self):
expectedResponse,
status=200,
)
response = self._api.address_with_details(34, "Barbaros", "Istanbul", "Turkey")
response = self._api.address_with_details(
street="Barbaros",
city="Istanbul",
country="Turkey",
house_number=34
)
self.assertTrue(response)
self.assertIsInstance(response, herepy.GeocoderResponse)

@responses.activate
def test_address_with_detail_without_street(self):
with open("testdata/models/geocoder.json", "r") as f:
expected_response = f.read()
responses.add(
responses.GET,
"https://geocode.search.hereapi.com/v1/geocode",
expected_response,
status=200,
)
response = self._api.address_with_details(
city="Istanbul",
country="Turkey",
house_number=34,
street= None
)
self.assertTrue(response)
self.assertIsInstance(response, herepy.GeocoderResponse)

@responses.activate
def test_address_with_detail_without_house_number(self):
with open("testdata/models/geocoder.json", "r") as f:
expected_response = f.read()
responses.add(
responses.GET,
"https://geocode.search.hereapi.com/v1/geocode",
expected_response,
status=200,
)
response = self._api.address_with_details(
street="Barbaros",
city="Istanbul",
country="Turkey",
house_number= None
)
self.assertTrue(response)
self.assertIsInstance(response, herepy.GeocoderResponse)

@responses.activate
def test_addresswithdetails_whenerroroccurred(self):
with open("testdata/models/geocoder_error.json", "r") as f:
Expand Down
Loading