def test_incremental_older_fetch(self):
        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])))

        # Normal, forward fetch shouldn't affect from and to

        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[0]])
        self.assertFalse(response['has_more'])
        self.assertEqual(response['to'], total_len)
        self.assertEqual(response['from'], 0)
Commands to manage DB
dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/test/unit/test_logs_handlers.py/TestLogs.test_incremental_older_fetch--crossover with--dataset/ETHPy150Open mrgambal/vulyk/vulyk/control.py/db