def setupDatasetsTest(unit_test, httpretty):
    httpretty.reset()
    httpretty.enable()

    unit_test.dataset_data = {'dataset_data': DatasetDataFactory.build()}

    # mock out calls with column_index query param
    # NOTE: this will always return 'column.1' as the column name
    single_col_data = DatasetDataFactory.build(column_names=[six.u('Date'), six.u('column.1')],
                                               data=[['2015-07-11', 444.3], ['2015-07-13', 433.3],
                                                     ['2015-07-14', 437.5], ['2015-07-15', 440.0]])
    unit_test.single_dataset_data = {'dataset_data': single_col_data}

    dataset_data = DatasetDataFactory.build()
    d_values = dataset_data.pop('data')
    d_metadata = dataset_data
    unit_test.data_list_obj = DataList(Data, d_values, d_metadata)

    unit_test.nse_oil = {'dataset': DatasetFactory.build(
        database_code='NSE', dataset_code='OIL')}

    unit_test.wiki_aapl = {'dataset': DatasetFactory.build(
        database_code='WIKI', dataset_code='AAPL')}

    unit_test.wiki_msft = {'dataset': DatasetFactory.build(
        database_code='WIKI', dataset_code='MSFT',
        newest_available_date='2015-07-30', oldest_available_date='2013-01-01')}

    unit_test.single_col = {'dataset': DatasetFactory.build(
        database_code='SINGLE', dataset_code='COLUMN',
        newest_available_date='2015-07-30', oldest_available_date='2013-01-01')}

    unit_test.oil_obj = Dataset('NSE/OIL', unit_test.nse_oil['dataset'])
    unit_test.aapl_obj = Dataset('WIKI/AAPL', unit_test.wiki_aapl['dataset'])
    unit_test.wiki_obj = Dataset('WIKI/MSFT', unit_test.wiki_msft['dataset'])
    unit_test.single_col_obj = Dataset('SINGLE/COLUMN', unit_test.single_col['dataset'])

    httpretty.register_uri(httpretty.GET,
                           re.compile(
                               'https://www.quandl.com/api/v3/datasets/.*/metadata'),
                           responses=[httpretty.Response(body=json.dumps(dataset))
                                      for dataset in
                                      [unit_test.nse_oil, unit_test.wiki_aapl,
                                       unit_test.wiki_msft]])
    # mock our query param column_index request
    httpretty.register_uri(httpretty.GET,
                           "https://www.quandl.com/api/v3/datasets/SINGLE/COLUMN/data",
                           body=json.dumps(unit_test.single_dataset_data))
    httpretty.register_uri(httpretty.GET,
                           "https://www.quandl.com/api/v3/datasets/WIKI/AAPL/data",
                           body=json.dumps(unit_test.dataset_data))
    httpretty.register_uri(httpretty.GET,
                           re.compile(
                               'https://www.quandl.com/api/v3/datasets/NSE/OIL/data'),
                           body=json.dumps(unit_test.dataset_data))
    httpretty.register_uri(httpretty.GET,
                           re.compile(
                               'https://www.quandl.com/api/v3/datasets/WIKI/MSFT/data'),
                           body=json.dumps(unit_test.dataset_data))
Esempio n. 2
0
    def setUpClass(cls):
        httpretty.enable()
        dataset_data = {'dataset_data': DatasetDataFactory.build()}
        httpretty.register_uri(
            httpretty.GET,
            re.compile('https://www.quandl.com/api/v3/datasets*'),
            body=json.dumps(dataset_data))
        cls.expected_raw_data = [{
            'date': datetime.date(2015, 7, 11),
            'column1': 444.3,
            'column2': 10,
            'column3': 3
        }, {
            'date': datetime.date(2015, 7, 13),
            'column1': 433.3,
            'column2': 4,
            'column3': 3
        }, {
            'date': datetime.date(2015, 7, 14),
            'column1': 437.5,
            'column2': 3,
            'column3': 3
        }, {
            'date': datetime.date(2015, 7, 15),
            'column1': 440.0,
            'column2': 2,
            'column3': 3
        }]

        cls.expected_list_values = [[datetime.date(2015, 7, 11), 444.3, 10, 3],
                                    [datetime.date(2015, 7, 13), 433.3, 4, 3],
                                    [datetime.date(2015, 7, 14), 437.5, 3, 3],
                                    [datetime.date(2015, 7, 15), 440.0, 2, 3]]
Esempio n. 3
0
 def test_exception_raised_if_column_and_data_row_mistmatch(self):
     dataset_data = {
         'dataset_data': DatasetDataFactory.build(column_names=['blah'])}
     httpretty.register_uri(httpretty.GET,
                            re.compile(
                                'https://www.quandl.com/api/v3/datasets*'),
                            body=json.dumps(dataset_data))
     self.assertRaises(InvalidDataError, lambda: Data.all())
Esempio n. 4
0
 def test_exception_raised_if_column_and_data_row_mistmatch(self):
     dataset_data = {
         'dataset_data': DatasetDataFactory.build(column_names=['blah'])
     }
     httpretty.register_uri(
         httpretty.GET,
         re.compile('https://www.quandl.com/api/v3/datasets*'),
         body=json.dumps(dataset_data))
     self.assertRaises(InvalidDataError, lambda: Data.all())
Esempio n. 5
0
    def setUpClass(cls):
        httpretty.enable()
        dataset_data = {'dataset_data': DatasetDataFactory.build()}
        httpretty.register_uri(httpretty.GET,
                               re.compile(
                                   'https://www.quandl.com/api/v3/datasets*'),
                               body=json.dumps(dataset_data))
        cls.expected_raw_data = [{'date': datetime.date(2015, 7, 11), 'column1': 444.3,
                                  'column2': 10, 'column3': 3},
                                 {'date': datetime.date(2015, 7, 13), 'column1': 433.3,
                                  'column2': 4, 'column3': 3},
                                 {'date': datetime.date(2015, 7, 14), 'column1': 437.5,
                                  'column2': 3, 'column3': 3},
                                 {'date': datetime.date(2015, 7, 15), 'column1': 440.0,
                                  'column2': 2, 'column3': 3}]

        cls.expected_list_values = [[datetime.date(2015, 7, 11), 444.3, 10, 3],
                                    [datetime.date(2015, 7, 13), 433.3, 4, 3],
                                    [datetime.date(2015, 7, 14), 437.5, 3, 3],
                                    [datetime.date(2015, 7, 15), 440.0, 2, 3]]
def setupDatasetsTest(unit_test, httpretty):
    httpretty.reset()
    httpretty.enable()

    unit_test.dataset_data = {'dataset_data': DatasetDataFactory.build()}

    # mock out calls with column_index query param
    # NOTE: this will always return 'column.1' as the column name
    single_col_data = DatasetDataFactory.build(
        column_names=[six.u('Date'), six.u('column.1')],
        data=[['2015-07-11', 444.3], ['2015-07-13', 433.3],
              ['2015-07-14', 437.5], ['2015-07-15', 440.0]])
    unit_test.single_dataset_data = {'dataset_data': single_col_data}

    dataset_data = DatasetDataFactory.build()
    d_values = dataset_data.pop('data')
    d_metadata = dataset_data
    unit_test.data_list_obj = DataList(Data, d_values, d_metadata)

    unit_test.nse_oil = {
        'dataset': DatasetFactory.build(database_code='NSE',
                                        dataset_code='OIL')
    }

    unit_test.goog_aapl = {
        'dataset':
        DatasetFactory.build(database_code='GOOG', dataset_code='NASDAQ_AAPL')
    }

    unit_test.goog_msft = {
        'dataset':
        DatasetFactory.build(database_code='GOOG',
                             dataset_code='NASDAQ_MSFT',
                             newest_available_date='2015-07-30',
                             oldest_available_date='2013-01-01')
    }

    unit_test.single_col = {
        'dataset':
        DatasetFactory.build(database_code='SINGLE',
                             dataset_code='COLUMN',
                             newest_available_date='2015-07-30',
                             oldest_available_date='2013-01-01')
    }

    unit_test.oil_obj = Dataset('NSE/OIL', unit_test.nse_oil['dataset'])
    unit_test.aapl_obj = Dataset('GOOG/AAPL', unit_test.goog_aapl['dataset'])
    unit_test.goog_obj = Dataset('GOOG/MSFT', unit_test.goog_msft['dataset'])
    unit_test.single_col_obj = Dataset('SINGLE/COLUMN',
                                       unit_test.single_col['dataset'])

    httpretty.register_uri(
        httpretty.GET,
        re.compile('https://www.quandl.com/api/v3/datasets/.*/metadata'),
        responses=[
            httpretty.Response(body=json.dumps(dataset)) for dataset in
            [unit_test.nse_oil, unit_test.goog_aapl, unit_test.goog_msft]
        ])
    # mock our query param column_index request
    httpretty.register_uri(
        httpretty.GET,
        "https://www.quandl.com/api/v3/datasets/SINGLE/COLUMN/data",
        body=json.dumps(unit_test.single_dataset_data))
    httpretty.register_uri(
        httpretty.GET,
        "https://www.quandl.com/api/v3/datasets/GOOG/NASDAQ_AAPL/data",
        body=json.dumps(unit_test.dataset_data))
    httpretty.register_uri(
        httpretty.GET,
        re.compile('https://www.quandl.com/api/v3/datasets/NSE/OIL/data'),
        body=json.dumps(unit_test.dataset_data))
    httpretty.register_uri(
        httpretty.GET,
        re.compile(
            'https://www.quandl.com/api/v3/datasets/GOOG/NASDAQ_MSFT/data'),
        body=json.dumps(unit_test.dataset_data))