Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Feb 20, 2024
1 parent 8fdb63c commit 1066b2e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hn_sdk/client/v0/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_user_by_username(username: str) -> dict:
return response.json()


def get_max_item() -> dict:
def get_max_item_id() -> dict:
"""
https://github.com/HackerNews/API?tab=readme-ov-file#live-data
"""
Expand Down
75 changes: 73 additions & 2 deletions test_e2e/test_client/v0/test_client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import time
import unittest

from hn_sdk.client.v0.client import get_item_by_id
from hn_sdk.client.v0.client import (
get_ask_stories,
get_best_stories,
get_item_by_id,
get_job_stories,
get_max_item_id,
get_new_stories,
get_show_stories,
get_top_stories,
get_updates,
get_user_by_username,
)


class TestClient(unittest.TestCase):
__DELAY_BETWEEN_TESTS = 0.25
__DELAY_BETWEEN_TESTS = 0.5
__RESPONSE_REQUIRED_KEYS = ["id"]
__TEST_STORY_ID = 8863
__TEST_COMMENT_ID = 2921983
__TEST_ASK_ID = 121003
__TEST_JOB_ID = 192327
__TEST_POLL_ID = 126809
__TEST_ITEM_PART_ID = 160705
__TEST_USERNAME = "jl"

def setUp(self) -> None:
# sleep before each test to avoid hitting rate limits.
Expand Down Expand Up @@ -56,3 +68,62 @@ def test_get_item_by_id_item_part(self):
resp = get_item_by_id(self.__TEST_ITEM_PART_ID)
self.assertIsInstance(resp, dict)
self.assertTrue(self.__required_keys_in_response(resp))

def test_get_user_by_username(self):
resp = get_user_by_username(self.__TEST_USERNAME)
self.assertIsInstance(resp, dict)
self.assertTrue(self.__required_keys_in_response(resp))

def test_get_max_item_id(self):
resp = get_max_item_id()
self.assertIsInstance(resp, int)

def test_get_top_stories(self):
resp = get_top_stories()
self.assertIsInstance(resp, list)
# NOTE: can be up to 500
self.assertTrue(len(resp) >= 1)
self.assertIsInstance(resp[0], int)

def test_get_new_stories(self):
resp = get_new_stories()
self.assertIsInstance(resp, list)
# NOTE: can be up to 500
self.assertTrue(len(resp) >= 1)
self.assertIsInstance(resp[0], int)

def test_get_best_stories(self):
resp = get_best_stories()
self.assertIsInstance(resp, list)
# NOTE: can be up to 500
self.assertTrue(len(resp) >= 1)
self.assertIsInstance(resp[0], int)

def test_get_ask_stories(self):
resp = get_ask_stories()
self.assertIsInstance(resp, list)
# NOTE: can be up to 200
self.assertTrue(len(resp) >= 1)
self.assertIsInstance(resp[0], int)

def test_get_show_stories(self):
resp = get_show_stories()
self.assertIsInstance(resp, list)
# NOTE: can be up to 200
self.assertTrue(len(resp) >= 1)
self.assertIsInstance(resp[0], int)

def test_get_job_stories(self):
resp = get_job_stories()
self.assertIsInstance(resp, list)
# NOTE: can be up to 200
self.assertTrue(len(resp) >= 1)
self.assertIsInstance(resp[0], int)

def test_get_updates(self):
resp = get_updates()
self.assertIsInstance(resp, dict)
self.assertTrue("items" in resp.keys())
self.assertIsInstance(resp["items"], list)
self.assertTrue("profiles" in resp.keys())
self.assertIsInstance(resp["profiles"], list)

0 comments on commit 1066b2e

Please sign in to comment.