Skip to content

Commit

Permalink
Merge pull request #77 from dashdoc/master
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahselek authored May 14, 2024
2 parents 16b9261 + fb45fa5 commit 8fc6b96
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
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,
) -> 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};"
if street is not None:
qq_query += f"street={street};"
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

0 comments on commit 8fc6b96

Please sign in to comment.