Skip to content

Commit 397fad9

Browse files
committed
tests:: testing the new raw_data rest flag in polygon
1 parent dddb95f commit 397fad9

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

tests/test_polygon/test_rest.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def endpoint(path, params='', api_version='v1'):
2121

2222
def test_polygon(reqmock):
2323
cli = REST('key-id')
24+
cli_raw = REST('key-id', raw_data=True)
2425

2526
# Exchanges
2627
reqmock.get(endpoint('/meta/exchanges'), text='''
@@ -30,6 +31,8 @@ def test_polygon(reqmock):
3031
exchanges = cli.exchanges()
3132
assert exchanges[0].id == 0
3233
assert 'Exchange(' in str(exchanges[0])
34+
assert type(exchanges[0]) == polygon.entity.Exchange
35+
assert type(cli_raw.exchanges()) == list
3336
with pytest.raises(AttributeError):
3437
exchanges[0].foo
3538

@@ -57,6 +60,8 @@ def test_polygon(reqmock):
5760

5861
tmap = cli.symbol_type_map()
5962
assert tmap.cs == 'Common Stock'
63+
assert type(tmap) == polygon.entity.SymbolTypeMap
64+
assert type(cli_raw.symbol_type_map()) == dict
6065

6166
# Historic Aggregates V2
6267
aggs_response = '''
@@ -100,6 +105,12 @@ def test_polygon(reqmock):
100105
assert aggs[0].open == 173.15
101106
assert len(aggs) == 1
102107
assert aggs.df.iloc[0].high == 173.21
108+
assert type(aggs) == polygon.entity.Aggsv2
109+
assert type(cli_raw.historic_agg_v2(
110+
'AAPL', 1, 'day',
111+
_from='2018-2-2',
112+
to='2018-2-5'
113+
)) == dict
103114
with pytest.raises(AttributeError):
104115
aggs[0].foo
105116

@@ -160,6 +171,8 @@ def test_polygon(reqmock):
160171
trade = cli.last_trade('AAPL')
161172
assert trade.price == 159.59
162173
assert trade.timestamp.day == 8
174+
assert type(trade) == polygon.entity.Trade
175+
assert type(cli_raw.last_trade('AAPL')) == dict
163176

164177
# Last Quote
165178
reqmock.get(
@@ -182,6 +195,8 @@ def test_polygon(reqmock):
182195
quote = cli.last_quote('AAPL')
183196
assert quote.askprice == 159.59
184197
assert quote.timestamp.day == 8
198+
assert type(quote) == polygon.entity.Quote
199+
assert type(cli_raw.last_quote('AAPL')) == dict
185200

186201
# Condition Map
187202
reqmock.get(
@@ -196,6 +211,8 @@ def test_polygon(reqmock):
196211

197212
cmap = cli.condition_map()
198213
assert cmap._raw['1'] == 'Regular'
214+
assert type(cmap) == polygon.entity.ConditionMap
215+
assert type(cli_raw.condition_map()) == dict
199216

200217
# Company
201218
reqmock.get(
@@ -205,8 +222,14 @@ def test_polygon(reqmock):
205222

206223
ret = cli.company('AAPL')
207224
assert ret.symbol == 'AAPL'
225+
assert type(ret) == polygon.entity.Company
226+
assert type(cli_raw.company('AAPL')) == dict
208227
ret = cli.company(['AAPL'])
209228
assert ret['AAPL'].symbol == 'AAPL'
229+
assert type(ret) == dict
230+
assert type(ret['AAPL']) == polygon.entity.Company
231+
assert type(cli_raw.company(['AAPL'])) == dict
232+
assert type(cli_raw.company(['AAPL'])['AAPL']) == dict
210233

211234
# Dividends
212235
reqmock.get(
@@ -215,6 +238,8 @@ def test_polygon(reqmock):
215238
)
216239
ret = cli.dividends('AAPL')
217240
assert ret[0].qualified == 'Q'
241+
assert type(ret[0]) == polygon.entity.Dividend
242+
assert type(cli_raw.dividends('AAPL')[0]) == dict
218243
ret = cli.dividends(['AAPL'])
219244
assert ret['AAPL'][0].qualified == 'Q'
220245

@@ -225,6 +250,10 @@ def test_polygon(reqmock):
225250
)
226251
ret = cli.splits('AAPL')
227252
assert ret[0].forfactor == 1
253+
assert type(ret) == polygon.entity.Splits
254+
assert type(ret[0]) == polygon.entity.Split
255+
assert type(cli_raw.splits('AAPL')) == list
256+
assert type(cli_raw.splits('AAPL')[0]) == dict
228257

229258
# Earnings
230259
reqmock.get(
@@ -233,8 +262,15 @@ def test_polygon(reqmock):
233262
)
234263
ret = cli.earnings('AAPL')
235264
assert ret[0].actualEPS == 1
265+
assert type(ret) == polygon.entity.Earnings
266+
assert type(ret[0]) == polygon.entity.Earning
267+
assert type(cli_raw.earnings('AAPL')) == list
236268
ret = cli.earnings(['AAPL'])
237269
assert ret['AAPL'][0].actualEPS == 1
270+
assert type(ret) == dict
271+
assert type(ret['AAPL']) == polygon.entity.Earnings
272+
assert type(cli_raw.earnings(['AAPL'])) == dict
273+
assert type(cli_raw.earnings(['AAPL'])["AAPL"]) == list
238274

239275
# Financials
240276
reqmock.get(
@@ -243,8 +279,13 @@ def test_polygon(reqmock):
243279
)
244280
ret = cli.financials('AAPL')
245281
assert ret[0].reportDateStr == '2018-09-01'
282+
assert type(ret) == polygon.entity.Financials
283+
assert type(cli_raw.financials('AAPL')) == list
246284
ret = cli.financials(['AAPL'])
247285
assert ret['AAPL'][0].reportDateStr == '2018-09-01'
286+
assert type(ret) == dict
287+
assert type(ret['AAPL']) == polygon.entity.Financials
288+
assert type(cli_raw.financials(['AAPL'])) == dict
248289

249290
# Financials v2
250291
reqmock.get(
@@ -318,9 +359,13 @@ def test_polygon(reqmock):
318359
FinancialsSort.CalendarDateDesc)
319360

320361
assert len(ret) == 2
362+
assert ret[0].ticker == "AAPL"
321363
assert type(ret) == polygon.entity.Financials
322364
assert type(ret[0]) == polygon.entity.Financial
323-
assert ret[0].ticker == "AAPL"
365+
assert type(cli_raw.financials_v2('AAPL',
366+
2,
367+
FinancialsReportType.Y,
368+
FinancialsSort.CalendarDateDesc)) == list
324369

325370
# News
326371
reqmock.get(
@@ -329,6 +374,10 @@ def test_polygon(reqmock):
329374
)
330375
ret = cli.news('AAPL')
331376
assert ret[0].title == 'Apple News'
377+
assert type(ret) == polygon.entity.NewsList
378+
assert type(ret[0]) == polygon.entity.News
379+
assert type(cli_raw.news('AAPL')) == list
380+
assert type(cli_raw.news('AAPL')[0]) == dict
332381

333382
with pytest.raises(ValueError):
334383
cli.company(['AAPL'] * 51)
@@ -377,6 +426,9 @@ def test_polygon(reqmock):
377426
"url": "https://api.polygon.io/v2/reference/tickers/GOOG"
378427
}
379428
]}''')
380-
cli.symbol_list_paginated(1, 2)
381-
# nothing to assert in the mock data. jsut checking params are parsed
382-
# correctly
429+
ret = cli.symbol_list_paginated(1, 2)
430+
assert type(ret) == list
431+
assert type(ret[0]) == polygon.entity.Symbol
432+
assert type(ret) == list
433+
assert type(cli_raw.symbol_list_paginated(1, 2)) == list
434+
assert type(cli_raw.symbol_list_paginated(1, 2)[0]) == dict

0 commit comments

Comments
 (0)