-
Notifications
You must be signed in to change notification settings - Fork 339
add exporting table files #120
Changes from 10 commits
319e032
d3c4e58
87ff77a
ff664a8
debf27c
57aa3b9
5ca5c98
c5e998b
7c35fd4
1c94ae3
f2e219f
63eb730
c713f0c
3d8ea55
c681509
87b1a14
4c2924e
1bbf98e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,24 @@ The following are instructions for running our tests: | |
`python setup.py install` | ||
4. Run the following command to test the plugin in all versions of python we support: | ||
`tox` | ||
|
||
Once you have all required package installed, you can run tests locally with: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
|
||
```ptyhon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spelling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😂 |
||
|
||
# running all tests locally | ||
|
||
python -W always setup.py -q test | ||
|
||
# runnging an individual test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo. |
||
|
||
python -m unittest test.[test file name].[class name].[individual test name]` | ||
|
||
# such as | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all updated |
||
|
||
python -m unittest -v test.test_datatable.ExportDataTableTest.test_download_get_file_info | ||
|
||
``` | ||
|
||
## Recommended Usage | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from quandl.errors.quandl_error import InvalidRequestError | ||
from .utils.api_key_util import ApiKeyUtil | ||
from .model.datatable import Datatable | ||
from .message import Message | ||
|
||
|
||
def export_table(datatable_code, **kwargs): | ||
"""Downloads an entire table as a zip file. | ||
:param str datatable_code: The datatable code to download, such as MER/F1 | ||
:param str filename: The filename for the download. \ | ||
If not specified, will download to the current working directory | ||
:param str api_key: Most databases require api_key for bulk download | ||
""" | ||
|
||
# discourage users from using authtoken | ||
if 'authtoken' in kwargs: | ||
raise InvalidRequestError(Message.ERROR_AUTHTOKEN_NOT_SUPPORTED) | ||
|
||
ApiKeyUtil.init_api_key_from_args(kwargs) | ||
|
||
filename = kwargs.pop('filename', '.') | ||
return Datatable(datatable_code).download_file(filename, params=kwargs) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
try: | ||
from urllib.parse import urlparse | ||
from urllib.parse import parse_qs | ||
except ImportError: | ||
from urlparse import urlparse | ||
from cgi import parse_qs | ||
|
||
import re | ||
import unittest | ||
import httpretty | ||
|
@@ -6,6 +13,8 @@ | |
from quandl.model.datatable import Datatable | ||
from mock import patch, call | ||
from test.factories.datatable import DatatableFactory | ||
from quandl.api_config import ApiConfig | ||
from quandl.errors.quandl_error import (InternalServerError, QuandlError) | ||
|
||
|
||
class GetDatatableDatasetTest(unittest.TestCase): | ||
|
@@ -48,3 +57,52 @@ def test_dataset_column_names_match_expected(self): | |
metadata = Datatable('ZACKS/FC').data_fields() | ||
six.assertCountEqual(self, | ||
metadata, [u'datatable_code', u'id', u'name', u'vendor_code']) | ||
|
||
|
||
class ExportDataTableTest(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
httpretty.enable() | ||
datatable = {'datatable': DatatableFactory.build( | ||
vendor_code='AUSBS', datatable_code='D')} | ||
httpretty.register_uri(httpretty.GET, | ||
re.compile( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason for such formatting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure, I was looking at the old tests... |
||
'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() | ||
|
||
def setUp(self): | ||
datatable = {'datatable': DatatableFactory.build( | ||
vendor_code='AUSBS', datatable_code='D')} | ||
self.datatable = Datatable(datatable['datatable']['vendor_code'] + '/' + | ||
datatable['datatable']['datatable_code'], datatable['datatable']) | ||
ApiConfig.api_key = 'api_token' | ||
ApiConfig.api_version = '2015-04-09' | ||
|
||
def test_download_get_file_info(self): | ||
url = self.datatable._download_request_path() | ||
parsed_url = urlparse(url) | ||
self.assertEqual(parsed_url.path, 'datatables/AUSBS/D.json') | ||
self.assertDictEqual(parse_qs(parsed_url.query), { | ||
'qopts.export': ['true']}) | ||
|
||
def test_bulk_download_raises_exception_when_no_path(self): | ||
self.assertRaises( | ||
QuandlError, lambda: self.datatable.download_file(None)) | ||
|
||
def test_bulk_download_table_raises_exception_when_error_response(self): | ||
httpretty.register_uri(httpretty.GET, | ||
re.compile( | ||
'https://www.quandl.com/api/v3/datatables/*'), | ||
body=json.dumps( | ||
{'quandl_error': | ||
{'code': 'QEMx01', 'message': 'something went wrong'}}), | ||
status=500) | ||
self.assertRaises( | ||
InternalServerError, lambda: self.datatable.download_file('.')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you still returning the filename? I think you changed the method to only print the filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated