Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Feb 21, 2024
1 parent b6b5bbc commit 7f337b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hn_sdk/client/v0/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
UPDATES_PATH = ConfigReader.get("client", "HACKER_NEWS_API", "UPDATES_PATH")


def get_item_by_id(item_id: str) -> dict:
def get_item_by_id(item_id: int) -> dict:
"""
https://github.com/HackerNews/API?tab=readme-ov-file#items
"""
if not isinstance(item_id, int):
raise Exception("item id must be an integer")
url = f"{BASE_URL}/{VERSION}/{ITEM_PATH}/{item_id}.json"
response = rest_call(requests.get, url)
return response.json()
Expand Down
5 changes: 5 additions & 0 deletions test_e2e/test_client/v0/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def __required_keys_in_response(self, response: dict) -> bool:
return False
return True

def test_get_item_by_id_item_id_not_int_raises_exception(self):
with self.assertRaises(Exception) as context:
get_item_by_id("foo")
self.assertEqual("item id must be an integer", str(context.exception))

def test_get_item_by_id_story(self):
resp = get_item_by_id(self.__TEST_STORY_ID)
self.assertIsInstance(resp, dict)
Expand Down

0 comments on commit 7f337b4

Please sign in to comment.