Esempio n. 1
0
    def test_empty(self):
        """ Test iterating over empty results. """

        # Specify two thing that we happen to know will return 0 results
        def pretend_fetcher(page, per_page):
            return []

        ri = BatchedResultsIterator(entity=model.Shoe,
                                    result_fetcher=pretend_fetcher)
        results = list(ri)
        self.assertEqual(0, len(results))
Esempio n. 2
0
    def test_limit_call(self):
        """ Test setting the limit in method call. """

        result_fetcher = functools.partial(self.protocol.get,
                                           '/athlete/activities')
        results = BatchedResultsIterator(entity=model.Activity,
                                         result_fetcher=result_fetcher,
                                         limit=10,
                                         per_page=2)
        results = list(results)
        self.assertEqual(10, len(results))
Esempio n. 3
0
    def test_multiple_iterator_calls(self):
        """ Test multiple calls of the iterator. """

        result_fetcher = functools.partial(self.protocol.get,
                                           '/athlete/activities')
        results = BatchedResultsIterator(entity=model.Activity,
                                         result_fetcher=result_fetcher,
                                         limit=10,
                                         per_page=2)
        results.limit = 10
        results1 = list(results)
        results2 = list(results)

        self.assertEqual(10, len(results1))
        self.assertEqual(len(results1), len(results2))
    def get_activities(self, before=None, after=None, limit=None):
        """
        Overriding oStravaClient.get_activities because all of the attributes
        get set on the object and make it way harder to serialize
        """

        if before:
            before = self._utc_datetime_to_epoch(before)

        if after:
            after = self._utc_datetime_to_epoch(after)

        params = dict(before=before, after=after)
        result_fetcher = functools.partial(self.protocol.get,
                                           '/athlete/activities',
                                           **params)

        return BatchedResultsIterator(entity=Activity,
                                      bind_client=self,
                                      result_fetcher=result_fetcher,
                                      limit=limit)