Exemplo n.º 1
0
    def list_all_my_groups(self, group_name_filter=None, **kwargs):
        """
        Retrieve all my groups, paging through the results until exhausted

        :param group_name_filter: only returns groups whose names contain filter string
        :return: the content of the response
        """
        groups = []
        args = []
        if group_name_filter:
            args.append(u'groupNameFilter={0}'.format(group_name_filter))

        url = urljoin(self.index_url, u'/groups') + u'?' + u'&'.join(args)
        response, data = self.__make_request(url, u'GET', self.headers, **kwargs)
        groups.extend(data[u'groups'])

        while u'nextId' in data and data[u'nextId']:
            next_args = args[:]
            next_args.append(u'startFrom={0}'.format(data['nextId']))
            url = urljoin(self.index_url, u'/groups') + u'?' + u'&'.join(next_args)
            response, data = self.__make_request(url, u'GET', self.headers, **kwargs)
            groups.extend(data[u'groups'])

        g = [Group.from_dict(elem) for elem in groups]
        return ListGroupsResponse(groups=g, group_name_filter=group_name_filter)
Exemplo n.º 2
0
def test_list_all_my_groups(mocked_responses, vinyldns_client):
    sample_list_groups1 = ListGroupsResponse([sample_group], 1, '*', 'start-from', 'next-id')

    # Set next id to None to indicate end of list
    sample_list_groups2 = ListGroupsResponse([sample_group2], 1, '*', 'start-from', next_id=None)
    mocked_responses.add(
        responses.GET, 'http://test.com/groups?groupNameFilter=*',
        body=to_json_string(sample_list_groups1), status=200)

    # list all puts the next id from the first response into the startFrom for the next request
    mocked_responses.add(
        responses.GET, 'http://test.com/groups?groupNameFilter=*&startFrom=next-id',
        body=to_json_string(sample_list_groups2), status=200)
    r = vinyldns_client.list_all_my_groups('*')

    assert r.start_from is None
    assert r.next_id is None
    assert sample_list_groups1.group_name_filter == r.group_name_filter

    for l, r in zip([sample_group, sample_group2], r.groups):
        check_groups_are_same(l, r)
Exemplo n.º 3
0
def test_list_my_groups(mocked_responses, vinyldns_client):
    sample_list_groups = ListGroupsResponse([sample_group, sample_group2], 5, '*', 'start-from', 'next-id')
    mocked_responses.add(
        responses.GET, 'http://test.com/groups?groupNameFilter=*&startFrom=start-from&maxItems=5',
        body=to_json_string(sample_list_groups), status=200)
    r = vinyldns_client.list_my_groups('*', 'start-from', 5)
    assert sample_list_groups.start_from == r.start_from
    assert sample_list_groups.group_name_filter == r.group_name_filter
    assert sample_list_groups.next_id == r.next_id

    for l, r in zip(sample_list_groups.groups, r.groups):
        check_groups_are_same(l, r)