-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
87 lines (78 loc) · 2.57 KB
/
test.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import ycnbc
import unittest
import json
class TestData(unittest.TestCase):
def setUp(self):
self.markets = ycnbc.Markets()
self.news = ycnbc.News()
def test_cnbc_news(self):
methods = [
'latest',
'trending',
'economy',
'jobs',
'white_house',
'hospitals',
'transportation',
'media',
'internet',
'congress',
'policy',
'finance',
'life',
'defense',
'europe_politics',
'china_politics',
'asia_politics',
'world_politics',
'equity_opportunity',
'politics',
'wealth',
'world_economy',
'central_banks',
'real_estate',
'health_science',
'small_business',
'lifehealth_insurance',
'business',
'energy',
'industrials',
'retail',
'cybersecurity',
'mobile',
'technology',
'cnbc_disruptors',
'tech_guide',
'social_media',
'climate'
]
for method_name in methods:
with self.subTest(method=method_name):
method = getattr(self.news, method_name)
response = method()
print(json.dumps(response))
self.assertNotIn("error", response, f"{method_name} returned an error")
def test_cnbc_markets(self):
quote_summary = self.markets.quote_summary('AAPL')
pre_markets = self.markets.pre_markets()
us_markets = self.markets.us_markets()
europe_markets = self.markets.europe_markets()
asia_markets = self.markets.asia_markets()
currencies = self.markets.currencies()
cryptocurrencies = self.markets.cryptocurrencies()
futures_and_commodities = self.markets.futures_and_commodities()
bonds = self.markets.bonds()
funds_and_etfs = self.markets.funds_and_etfs()
print(json.dumps(funds_and_etfs))
self.assertIsNotNone(quote_summary)
self.assertIsNotNone(pre_markets)
self.assertIsNotNone(us_markets)
self.assertIsNotNone(europe_markets)
self.assertIsNotNone(asia_markets)
self.assertIsNotNone(currencies)
self.assertIsNotNone(cryptocurrencies)
self.assertIsNotNone(futures_and_commodities)
self.assertIsNotNone(bonds)
self.assertIsNotNone(funds_and_etfs)
if __name__ == '__main__':
unittest.main()