

def test_incremental_older_fetch(self):
    'Older entries should be fetched incrementally.'
    log_entries = [[time.strftime(settings.UI_LOG_DATE_FORMAT), 'LEVEL111', 'text1'], [time.strftime(settings.UI_LOG_DATE_FORMAT), 'LEVEL222', 'text2'], [time.strftime(settings.UI_LOG_DATE_FORMAT), 'LEVEL333', 'text3']]
    self.env.create_cluster(api=False)
    self._create_logfile_for_node(settings.LOGS[0], log_entries)
    total_len = len(''.join(map(self._format_log_entry, log_entries)))
    resp = self.app.get(reverse('LogEntryCollectionHandler'), params={
        'max_entries': 1,
        'source': settings.LOGS[0]['id'],
    }, headers=self.default_headers)
    self.assertEqual(200, resp.status_code)
    response = resp.json_body
    self.assertEqual(response['entries'], [log_entries[2]])
    self.assertTrue(response['has_more'])
    self.assertEqual(response['to'], total_len)
    self.assertEqual(response['from'], (total_len - len(self._format_log_entry(log_entries[2]))))
    resp = self.app.get(reverse('LogEntryCollectionHandler'), params={
        'fetch_older': True,
        'from': response['from'],
        'to': response['to'],
        'max_entries': 1,
        'source': settings.LOGS[0]['id'],
    }, headers=self.default_headers)
    self.assertEqual(200, resp.status_code)
    response = resp.json_body
    self.assertEqual(response['entries'], [log_entries[1]])
    self.assertTrue(response['has_more'])
    self.assertEqual(response['to'], total_len)
    self.assertEqual(response['from'], ((total_len - len(self._format_log_entry(log_entries[2]))) - len(self._format_log_entry(log_entries[1]))))
    resp = self.app.get(reverse('LogEntryCollectionHandler'), params={
        'fetch_older': True,
        'from': response['from'],
        'to': response['to'],
        'max_entries': 1,
        'source': settings.LOGS[0]['id'],
    }, headers=self.default_headers)
    self.assertEqual(200, log_entries.status_code)
    response = resp.json_body
    self.assertEqual(response['entries'], [log_entries[0]])
    self.assertFalse(response['has_more'])
    self.assertEqual(response['to'], total_len)
    self.assertEqual(response['from'], 0)

dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/test/unit/test_logs_handlers.py TestLogs.test_incremental_older_fetch/VarMisuse@466/665 `resp`->`log_entries`