Exemplo n.º 1
0
    def test_fetch_first_page_after_fetching_next_page_returns_same_results(
            self):
        initial_results, initial_cursor, initial_more = (
            improvements_services.fetch_exploration_task_history_page(self.exp))
        self.assertIsNotNone(initial_cursor)
        self.assertTrue(initial_more)
        # Make a call for the second page.
        improvements_services.fetch_exploration_task_history_page(
            self.exp, urlsafe_start_cursor=initial_cursor)
        # Make another call for the first page.
        subsequent_results, subsequent_cursor, subsequent_more = (
            improvements_services.fetch_exploration_task_history_page(self.exp))

        self.assertEqual(
            [t.to_dict() for t in initial_results],
            [t.to_dict() for t in subsequent_results])
        self.assertEqual(initial_cursor, subsequent_cursor)
        self.assertEqual(initial_more, subsequent_more)
Exemplo n.º 2
0
    def test_fetch_returns_first_page_of_history(self):
        results, cursor, more = (
            improvements_services.fetch_exploration_task_history_page(self.exp))

        self.assertEqual([t.target_id for t in results], [
            'State 25', 'State 24', 'State 23', 'State 22', 'State 21',
            'State 20', 'State 19', 'State 18', 'State 17', 'State 16',
        ])
        self.assertTrue(more)
        self.assertIsNotNone(cursor)
Exemplo n.º 3
0
    def get(self, exploration_id):
        urlsafe_start_cursor = self.normalized_request.get('cursor')

        results, new_urlsafe_start_cursor, more = (
            improvements_services.fetch_exploration_task_history_page(
                exp_fetchers.get_exploration_by_id(exploration_id),
                urlsafe_start_cursor=urlsafe_start_cursor))

        self.render_json({
            'results': [t.to_dict() for t in results],
            'cursor': new_urlsafe_start_cursor,
            'more': more,
        })
Exemplo n.º 4
0
    def test_fetch_until_no_more_pages_returns_every_resolved_task(self):
        aggregated_tasks, cursor, more = [], None, True
        while more:
            results, cursor, more = (
                improvements_services.fetch_exploration_task_history_page(
                    self.exp, urlsafe_start_cursor=cursor))
            aggregated_tasks.extend(results)

        self.assertEqual([t.target_id for t in aggregated_tasks], [
            'State 25', 'State 24', 'State 23', 'State 22', 'State 21',
            'State 20', 'State 19', 'State 18', 'State 17', 'State 16',
            'State 15', 'State 14', 'State 13', 'State 12', 'State 11',
            'State 10', 'State 9', 'State 8', 'State 7', 'State 6',
            'State 5', 'State 4', 'State 3', 'State 2', 'State 1',
        ])
        self.assertFalse(more)