'Check the members of a collection of dicts.
:param collection: an iterable of dicts
:param attribute_or_list: an attribute or list of attributes to read.
the results will be sorted and compared with expected_list. if
a list of attributes is given, the attributes will be read
hierarchically, i.e. item[attribute1][attribute2]...
:param expected_list: list of expected values
:param check_number: if given, only check this number of entries
:param length: expected length of list, only necessary if check_number
is given'

def check_collection(self, collection, attribute_or_list, expected_list, length=None, check_number=None):

    actual_list = sorted((self._read_attribute(item, attribute_or_list) for item in collection['members']))
    if ((length is None) and (check_number is None)):
        length = len(expected_list)
    if (length is not None):
        self.assertEquals(len(actual_list), length, ('Expected    %s,    got    %s:    %s' % (length, len(actual_list), ',    '.join((str(item) for item in actual_list)))))
    if check_number:
        actual_list = actual_list[:check_number]
    self.assertEquals(actual_list, expected_list)
