forked from abrinsmead/hackernews-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
50 lines (35 loc) · 1.4 KB
/
Copy pathtests.py
File metadata and controls
50 lines (35 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime
import unittest
from requests.exceptions import ConnectTimeout
from hackernews import HackerNews, Item, User
class HackerNewsTestCase(unittest.TestCase):
def setUp(self):
self.hn = HackerNews()
def test_top_story_count(self):
top_stories = self.hn.top_stories()
self.assertEqual(len(top_stories), 100)
def test_max_item_positive_integer(self):
max_item = self.hn.max_item()
self.assertGreaterEqual(max_item, 0)
def test_updates_result_is_dict(self):
updates = self.hn.updates()
self.assertIsInstance(updates, dict)
def test_item_result_is_dict(self):
item = self.hn.item(1)
self.assertIsInstance(item, Item)
def test_user_result_is_dict(self):
item = self.hn.user('pg')
self.assertIsInstance(item, User)
def test_user_created_is_datetime(self):
item = self.hn.user('pg')
self.assertIsInstance(item.created, datetime)
def test_item_time_is_datetime(self):
item = self.hn.item('1')
self.assertIsInstance(item.time, datetime)
def test_raises_connection_timeout(self):
hn = HackerNews(timeout=1)
hn.url = "http://192.0.2.0" # RFC 5735 TEST-NET-1
self.assertRaises(ConnectTimeout, hn.top_stories)
def test_object_to_dict(self):
item = self.hn.item('1')
self.assertIsInstance(item.__dict__, dict)