def test_get_blocks_timerange(self): """Test validity of block data from a selected time range.""" db = rocksdb.DB(DB_PATH, rocksdb.Options(create_if_missing=True, max_open_files=10000), read_only=True) with open('tests/resources/block_data_timerange.txt', 'r') as f: compare_data = json.loads(f.read()) time_start = 1479653257 time_end = 1479653542 gatherer = DatabaseGatherer(db) gathered_data = gatherer.get_blocks_by_datetime( 100000, time_start, time_end) self.assertEqual(compare_data, gathered_data)
def get_blocks_by_time(limit: str = '0', block_start: str = '0', block_end: str = '', db: Any = None) -> None: """ Get multiple blocks by datetime range. Args: limit: Maximum blocks to gether. block_start: Beginning datetime. block_end: End datetime. db: Read-only database instance. """ if block_end == '': block_end = str(int(time.time()) + 1000000) try: int_limit = int(limit) except ValueError: return 'Limit {} couldn\'t be parsed'.format(limit), 400 try: int_block_start = int(block_start) except ValueError: return 'Start datetime {} couldn\'t be parsed'.format(block_start), 400 try: int_block_end = int(block_end) except ValueError: return 'Start datetime {} couldn\'t be parsed'.format(block_end), 400 if int_block_start > int_block_end: return 'Start datetime larger than end datetime.', 400 gatherer = DatabaseGatherer(db) blocks = gatherer.get_blocks_by_datetime(int_limit, int_block_start, int_block_end) if blocks is None: return 'No blocks in timeframe {} - {} have been found'.format( block_start, block_end), 404 return blocks