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_to_csv_returns_expected_csv(self):
results = Data.all(
params={'database_code': 'NSE', 'dataset_code': 'OIL'})
data = results.to_csv()
expected = "Date,column.1,column.2,column.3\n2015-07-11,444.3,10,3\n" + \
"2015-07-13,433.3,4,3\n2015-07-14,437.5,3,3\n2015-07-15,440.0,2,3\n"
self.assertEqual(data, expected)
def test_data_to_list(self):
list_data = Data.all(
params={'database_code': 'NSE', 'dataset_code': 'OIL'}).to_list()
six.assertCountEqual(self, list_data[0], self.expected_list_values[0])
six.assertCountEqual(self, list_data[1], self.expected_list_values[1])
six.assertCountEqual(self, list_data[2], self.expected_list_values[2])
six.assertCountEqual(self, list_data[3], self.expected_list_values[3])
self.assertRaises(InvalidDataError, lambda: Data.all())
def test_pandas_dataframe_index_is_datetime(self):
results = Data.all(
params={'database_code': 'NSE', 'dataset_code': 'OIL'})
df = results.to_pandas()
self.assertEqual(df.index.name, 'Date')
self.assertIsInstance(df.index, pandas.DatetimeIndex)
def test_raw_data_is_zip_of_column_names_and_data(self):
results = Data.all(
params={'database_code': 'NSE', 'dataset_code': 'OIL'})
six.assertCountEqual(self, results[0].__get_raw_data__(), self.expected_list_values[0])
six.assertCountEqual(self, results[1].__get_raw_data__(), self.expected_list_values[1])
six.assertCountEqual(self, results[2].__get_raw_data__(), self.expected_list_values[2])
six.assertCountEqual(self, results[3].__get_raw_data__(), self.expected_list_values[3])
def test_values_and_meta_exist(self):
results = Data.all(
params={'database_code': 'NSE', 'dataset_code': 'OIL'})
self.assertIsNotNone(results.values)
self.assertIsNotNone(results.meta)
def test_data_calls_connection(self, mock):
Data.all(params={'database_code': 'NSE', 'dataset_code': 'OIL'})
expected = call('get', 'datasets/NSE/OIL/data', params={})
self.assertEqual(mock.call_args, expected)