forked from quandl/quandl-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_get_table.py
44 lines (38 loc) · 1.57 KB
/
test_get_table.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
import re
import unittest2
import httpretty
import json
from quandl.model.datatable import Datatable
import pandas
from mock import patch
from test.factories.datatable import DatatableFactory
from test.factories.datatable_data import DatatableDataFactory
from test.factories.datatable_meta import DatatableMetaFactory
import quandl
class GetDataTableTest(unittest2.TestCase):
@classmethod
def setUpClass(cls):
httpretty.enable()
datatable = {'datatable': DatatableFactory.build(
vendor_code='ZACKS', datatable_code='FC')}
data = DatatableDataFactory.build()
datatable['datatable'].update(data)
meta = {'meta': DatatableMetaFactory.build()}
datatable.update(meta)
httpretty.register_uri(httpretty.GET,
re.compile(
'https://www.quandl.com/api/v3/datatables*'),
body=json.dumps(datatable))
cls.datatable_instance = Datatable(datatable['datatable'])
@classmethod
def tearDownClass(cls):
httpretty.disable()
httpretty.reset()
@patch('quandl.connection.Connection.request')
def test_datatable_returns_datatable_object(self, mock):
df = quandl.get_table('ZACKS/FC', params={})
self.assertIsInstance(df, pandas.core.frame.DataFrame)
@patch('quandl.connection.Connection.request')
def test_datatable_with_code_returns_datatable_object(self, mock):
df = quandl.get_table('AR/MWCF', code="ICEP_WAC_Z2017_S")
self.assertIsInstance(df, pandas.core.frame.DataFrame)