def test_iterable_func(self):
        """
        Gets the generator from a PaginatedResource's iterable_func,
        sanity checks usage
        """
        pr = PaginatedResource(self.simulator.simulate_get,
                               "path", {"params": {}},
                               max_results_per_call=10,
                               num_results=None)

        generator = pr.iterable_func()
        for i in range(self.n):
            self.assertEqual(six.next(generator)["value"], i)

        with self.assertRaises(StopIteration):
            six.next(generator)
def test_data(paging_simulator):
    """
    Gets data from PaginatedResource objects based on paging_simulator,
    confirms data is the expected range of numbers
    tests num_results < n, num_results > n, num_results = None,
    """
    # num_results < n
    less_results = N - 7
    pr_less = PaginatedResource(
        paging_simulator.simulate_get,
        "path",
        {"params": {}},
        max_results_per_call=10,
        num_results=less_results,
    )
    # confirm results
    for item, expected in zip(pr_less.data, range(less_results)):
        assert item["value"] == expected

    assert pr_less.num_results_fetched == less_results

    # num_results > n
    more_results = N + 7
    pr_more = PaginatedResource(
        paging_simulator.simulate_get,
        "path",
        {"params": {}},
        max_results_per_call=10,
        num_results=more_results,
    )
    # confirm results
    for item, expected in zip(pr_more.data, range(N)):
        assert item["value"] == expected
    assert pr_more.num_results_fetched == N

    # num_results = None (fetch all)
    pr_none = PaginatedResource(
        paging_simulator.simulate_get,
        "path",
        {"params": {}},
        max_results_per_call=10,
        num_results=None,
    )
    # confirm results
    for item, expected in zip(pr_none.data, range(N)):
        assert item["value"] == expected
    assert pr_none.num_results_fetched == N
Exemple #3
0
    def endpoint_search(self,
                        filter_fulltext=None,
                        filter_scope=None,
                        num_results=25,
                        **params):
        r"""
        .. parsed-literal::

            GET /endpoint_search\
            ?filter_fulltext=<filter_fulltext>&filter_scope=<filter_scope>

        :rtype: iterable of :class:`GlobusResponse
                <globus_sdk.response.GlobusResponse>`

        Search for a given string as a fulltext search:

        >>> tc = globus_sdk.TransferClient()
        >>> for ep in tc.endpoint_search('String to search for!'):
        >>>     print(ep['display_name'])

        Search for a given string, but only on endpoints that you own:

        >>> for ep in tc.endpoint_search('foo', filter_scope='my-endpoints'):
        >>>     print('{} has ID {}'.format(ep['display_name'], ep['id']))

        Search results are capped at a number of elements equal to the
        ``num_results`` parameter.
        If you want more than the default, 25, elements, do like so:

        >>> for ep in tc.endpoint_search('String to search for!',
        >>>                             num_results=120):
        >>>     print(ep['display_name'])

        It is important to be aware that the Endpoint Search API limits
        you to 1000 results for any search query.
        If you attempt to exceed this limit, you will trigger a
        :class:`PaginationOverrunError <globus_sdk.exc.PaginationOverrunError>`

        >>> for ep in tc.endpoint_search('globus', # a very common string
        >>>                             num_results=1200): # num too large!
        >>>     print(ep['display_name'])

        will trigger this error.

        For additional information, see `Endpoint Search
        <https://docs.globus.org/api/transfer/endpoint_search>`_.
        in the REST documentation for details.
        """
        merge_params(params,
                     filter_scope=filter_scope,
                     filter_fulltext=filter_fulltext)
        return PaginatedResource(self.get,
                                 "endpoint_search", {'params': params},
                                 num_results=num_results,
                                 max_results_per_call=100,
                                 max_total_results=1000)
Exemple #4
0
def test_iterable_func(paging_simulator):
    """
    Gets the generator from a PaginatedResource's iterable_func,
    sanity checks usage
    """
    pr = PaginatedResource(
        paging_simulator.simulate_get,
        "path",
        {"params": {}},
        max_results_per_call=10,
        num_results=None,
    )

    generator = pr.iterable_func()
    for i in range(N):
        assert next(generator)["value"] == i

    with pytest.raises(StopIteration):
        next(generator)
def test_iterable_func(paging_simulator):
    """
    Gets the generator from a PaginatedResource's iterable_func,
    sanity checks usage
    """
    pr = PaginatedResource(
        paging_simulator.simulate_get,
        "path",
        {"params": {}},
        max_results_per_call=10,
        num_results=None,
    )

    generator = pr.iterable_func()
    for i in range(N):
        assert six.next(generator)["value"] == i

    with pytest.raises(StopIteration):
        six.next(generator)
Exemple #6
0
    def task_list(self, num_results=10, **params):
        """
        ``GET /task_list``

        :rtype: iterable of :class:`GlobusResponse
                <globus_sdk.response.GlobusResponse>`
        """
        return PaginatedResource(
            self.get,
            'task_list', {'params': params},
            num_results=num_results,
            max_results_per_call=1000,
            paging_style=PaginatedResource.PAGING_STYLE_TOTAL)
Exemple #7
0
    def task_event_list(self, task_id, num_results=10, **params):
        """
        ``GET /task/<task_id>/event_list``

        :rtype: iterable of :class:`GlobusResponse
                <globus_sdk.response.GlobusResponse>`
        """
        path = self.qjoin_path('task', task_id, 'event_list')
        return PaginatedResource(
            self.get,
            path, {'params': params},
            num_results=num_results,
            max_results_per_call=1000,
            paging_style=PaginatedResource.PAGING_STYLE_TOTAL)
Exemple #8
0
    def endpoint_manager_task_list(self, num_results=10, **params):
        """
        ``GET endpoint_manager/task_list``

        :rtype: iterable of :class:`GlobusResponse
                <globus_sdk.response.GlobusResponse>`
        """
        path = self.qjoin_path('endpoint_manager', 'task_list')
        return PaginatedResource(
            self.get,
            path, {'params': params},
            num_results=num_results,
            max_results_per_call=1000,
            paging_style=PaginatedResource.PAGING_STYLE_HAS_NEXT)
    def test_data(self):
        """
        Gets data from PaginatedResource objects based on paging_simulator,
        confirms data is the expected range of numbers
        tests num_results < n, num_results > n, num_results = None,
        """
        # num_results < n
        less_results = self.n - 7
        pr_less = PaginatedResource(self.simulator.simulate_get,
                                    "path", {"params": {}},
                                    max_results_per_call=10,
                                    num_results=less_results)
        # confirm results
        for item, expected in zip(pr_less.data, range(less_results)):
            self.assertEqual(item["value"], expected)
        self.assertEqual(pr_less.num_results_fetched, less_results)

        # num_results > n
        more_results = self.n + 7
        pr_more = PaginatedResource(self.simulator.simulate_get,
                                    "path", {"params": {}},
                                    max_results_per_call=10,
                                    num_results=more_results)
        # confirm results
        for item, expected in zip(pr_more.data, range(self.n)):
            self.assertEqual(item["value"], expected)
        self.assertEqual(pr_more.num_results_fetched, self.n)

        # num_results = None (fetch all)
        pr_none = PaginatedResource(self.simulator.simulate_get,
                                    "path", {"params": {}},
                                    max_results_per_call=10,
                                    num_results=None)
        # confirm results
        for item, expected in zip(pr_none.data, range(self.n)):
            self.assertEqual(item["value"], expected)
        self.assertEqual(pr_none.num_results_fetched, self.n)