Ejemplo n.º 1
0
    def get(self, url: str, params=None, _items=None):
        """GET operation with pagination support. If multiple requests are required to
        get all items responses are squashed a single response

        :param url: path to resource that will be queried
        :type url: str
        :param params: dict of parameters for http request. Defaults to `None`
        :type params: dict, optional
        :param _items: list of items if response includes multiple pages. Used internally for recursion
        :type _items: list, optional
        :return: dictionary or list of returned api objects
        :rtype: Union[dict, list]
        """
        if not utils.is_getbyid_operation(url) and _items is None:
            if params is None:
                params = {}
            if 'limit' not in params:
                params['limit'] = defaults.API_PAGING_LIMIT
            if 'expanded' not in params:
                params['expanded'] = defaults.API_EXPANSION_MODE

        response = self._request('get', url, params=params)
        payload = response.json()

        if 'paging' in payload:
            if _items is None:
                _items = []
            if 'items' in payload:
                _items.extend(payload['items'])
                if 'next' in payload['paging']:
                    _items = self.get(payload['paging']['next'][0], params=None, _items=_items)
            return _items
        return payload
Ejemplo n.º 2
0
def test_is_getbyid_operation_with_invalid_getbyid_operation():
    valid_getbyid_operation = 'https://localhost' \
                              '/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f' \
                              '/object/networkgroups/A09351F4-691E-0ed3-0000-034359739130/overrides'
    expected_result = False

    actual_result = utils.is_getbyid_operation(valid_getbyid_operation)

    assert expected_result == actual_result
Ejemplo n.º 3
0
def test_is_getbyid_operation_with_valid_getbyid_operation_with_params():
    valid_getbyid_operation = (
        'https://localhost'
        '/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f'
        '/object/networkgroups/A09351F4-691E-0ed3-0000-034359739130?expanded=True'
    )
    expected_result = True

    actual_result = utils.is_getbyid_operation(valid_getbyid_operation)

    assert expected_result == actual_result