def setUp(self):
     super(MongoDataRangesIntegrationTestCase, self).setUp()
     self.mock_getter = mock.Mock()
     self.mongo_db = MongoIntervalseries(mongo_collection=self.collection,
                                         metric=self.metric)
     self.cache = FinancialIntervalCache(get_data=self.mock_getter,
                                         database=self.mongo_db)
示例#2
0
def mongo_fundamentals_cache(metric, mongo_host='localhost', mongo_port=27017,
                             filing_getter=HTMLEdgarDriver):
    mongo_client = pymongo.MongoClient(mongo_host, mongo_port)
    mongo_collection = mongo_client.fundamentals.fundamentals
    db = MongoIntervalseries(mongo_collection=mongo_collection, 
                         metric=metric.name)
    metric_getter = AccountingMetricGetter(metric=metric,
                                           filing_getter=filing_getter)
    cache = FinancialIntervalCache(get_data=metric_getter.get_data, database=db)
    return cache
示例#3
0
def sqlite_fundamentals_cache(metric, 
                              db_file_path=DEFAULT_FUNDAMENTALS_PATH, 
                              filing_getter=HTMLEdgarDriver):
    connection = sqlite_drivers.SQLiteIntervalseries.connect(db_file_path)
    driver = sqlite_drivers.SQLiteIntervalseries(connection=connection,
                                                 table='fundamentals',
                                                 metric=metric.name)
    metric_getter = AccountingMetricGetter(metric=metric, 
                                           filing_getter=filing_getter)
    
    cache = FinancialIntervalCache(get_data=metric_getter.get_data, 
                                     database=driver)
    return cache
示例#4
0
 def test_border_behavior(self):
     '''Fundamentals were being inserted twice because of an off by one error.'''
     metric = accounting_metrics.QuarterlyEPS
     symbol = 'CSCO'
     connection = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES)
     driver = SQLiteIntervalseries(connection=connection,
                                  table='fundamentals',
                                  metric=metric.name)
     metric_getter = AccountingMetricGetter(metric=metric, 
                                        filing_getter=HTMLEdgarDriver)
     cache = FinancialIntervalCache(get_data=metric_getter.get_data, database=driver)
     dates = {datetime.datetime(2010, 2, 17)}
     list(cache.get(symbol, dates=dates))
     
     count_query = "SELECT COUNT(*)  AS count FROM fundamentals WHERE symbol = '{}'".format(symbol)
     count = connection.execute(count_query).next()['count']
     self.assertEqual(count, 1)
     list(cache.get(symbol, dates=dates))
     count = connection.execute(count_query).next()['count']
     self.assertEqual(count, 1)
 def setUp(self):
     self.mock_data_getter = mock.Mock()
     self.mock_db = mock.Mock()
     self.date_range_cache = FinancialIntervalCache(
         get_data=self.mock_data_getter, database=self.mock_db)