'Verifies that all filtering is done at the DB layer.'

def test_volume_get_by_filter(self):

    vols = []
    vols.extend([db.volume_create(self.ctxt, {'project_id': 'g1', 'display_name': ('name_%d' % i), 'size': 1}) for i in range(2)])
    vols.extend([db.volume_create(self.ctxt, {'project_id': 'g1', 'display_name': ('name_%d' % i), 'size': 2}) for i in range(2)])
    vols.extend([db.volume_create(self.ctxt, {'project_id': 'g1', 'display_name': ('name_%d' % i)}) for i in range(2)])
    vols.extend([db.volume_create(self.ctxt, {'project_id': 'g2', 'display_name': ('name_%d' % i), 'size': 1}) for i in range(2)])
    filters = {'size': '1'}
    correct_order = [vols[1], vols[0]]
    self._assertEqualsVolumeOrderResult(correct_order, filters=filters, project_id='g1')
    filters = {'size': '1', 'display_name': 'name_1'}
    correct_order = [vols[1]]
    self._assertEqualsVolumeOrderResult(correct_order, filters=filters, project_id='g1')
    filters = {'size': '1'}
    correct_order = [vols[7], vols[6], vols[1], vols[0]]
    self._assertEqualsVolumeOrderResult(correct_order, filters=filters)
    filters = {'size': '1', 'display_name': 'name_1'}
    correct_order = [vols[7], vols[1]]
    self._assertEqualsVolumeOrderResult(correct_order, filters=filters)
    filters = {'display_name': 'name_1'}
    correct_order = [vols[5], vols[3], vols[1]]
    self._assertEqualsVolumeOrderResult(correct_order, filters=filters, project_id='g1')
    correct_order = [vols[7], vols[5], vols[3], vols[1]]
    self._assertEqualsVolumeOrderResult(correct_order, filters=filters)
    filters = {'display_name': 'name_1', 'bogus_value': 'foo'}
    self._assertEqualsVolumeOrderResult([], filters=filters, project_id='g1')
    self._assertEqualsVolumeOrderResult([], project_id='bogus')
    self._assertEqualsVolumeOrderResult([], filters=filters)
    self._assertEqualsVolumeOrderResult([], filters={'metadata': 'not    valid'})
    self._assertEqualsVolumeOrderResult([], filters={'metadata': ['not', 'valid']})
    filters = {'volume_type': 'bogus_type'}
    self._assertEqualsVolumeOrderResult([], filters=filters)
