Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_convert_options_get_request_with_dictionary_params_and_array_values(self):
options = {'params': {'foo': {'bar': ['baz', 'bax']}}}
expected_result = {'params': {'foo.bar[]': ['baz', 'bax']}}
result = Util.convert_options(request_type='get', **options)
self.assertEqual(cmp(result, expected_result), 0)
def test_convert_options_post_request_all_param_types(self):
options = {'params': {'foo': 'bar',
'ticker': ['AAPL', 'MSFT'],
'per_end_date': {'gte': '2015-01-01'},
'qopts': {'columns': ['ticker', 'per_end_date'],
'per_page': 5}}}
expected_result = {'json': {'foo': 'bar',
'qopts.per_page': 5,
'per_end_date.gte': '2015-01-01',
'ticker': ['AAPL', 'MSFT'],
'qopts.columns': ['ticker', 'per_end_date']}}
result = Util.convert_options(request_type='post', **options)
self.assertEqual(cmp(result, expected_result), 0)
def test_convert_options_post_request_with_dictionary_params_and_array_values(self):
options = {'params': {'foo': {'bar': ['baz', 'bax']}}}
expected_result = {'json': {'foo.bar': ['baz', 'bax']}}
result = Util.convert_options(request_type='post', **options)
self.assertEqual(cmp(result, expected_result), 0)
def test_convert_options_get_request_with_empty_params(self):
options = {'params': {}}
expected_result = options
result = Util.convert_options(request_type='get', **options)
self.assertEqual(cmp(result, expected_result), 0)
def test_convert_options_post_request_with_empty_params(self):
options = {'params': {}}
expected_result = {'json': {}}
result = Util.convert_options(request_type='post', **options)
self.assertEqual(cmp(result, expected_result), 0)
def test_convert_options_get_request_with_simple_params(self):
options = {'params': {'foo': 'bar'}}
expected_result = options
result = Util.convert_options(request_type='get', **options)
self.assertEqual(cmp(result, expected_result), 0)
def _request_file_info(self, file_or_folder_path, **options):
url = self._download_request_path()
code_name = self.code
options['params']['qopts.export'] = 'true'
request_type = RequestType.get_request_type(url, **options)
updated_options = Util.convert_options(request_type=request_type, **options)
r = Connection.request(request_type, url, **updated_options)
response_data = r.json()
file_info = response_data['datatable_bulk_download']['file']
status = file_info['status']
if status == 'fresh':
file_link = file_info['link']
self._download_file_with_link(file_or_folder_path, file_link, code_name)
return True
else:
return False
def page(cls, datatable, **options):
params = {'id': str(datatable.code)}
path = Util.constructed_path(datatable.default_path(), params)
request_type = RequestType.get_request_type(path, **options)
updated_options = Util.convert_options(request_type=request_type, **options)
r = Connection.request(request_type, path, **updated_options)
response_data = r.json()
Util.convert_to_dates(response_data)
resource = cls.create_datatable_list_from_response(response_data)
return resource