'Tests that the registry API returns list of public images.
Use a specific user-defined properties.'

def test_get_index_filter_on_user_defined_properties(self):

    properties = {'distro': 'ubuntu', 'arch': 'i386', 'type': 'kernel'}
    extra_id = _gen_uuid()
    extra_fixture = {'id': extra_id, 'status': 'active', 'visibility': 'public', 'disk_format': 'vhd', 'container_format': 'ovf', 'name': 'image-extra-1', 'size': 19, 'properties': properties, 'checksum': None}
    db_api.image_create(self.context, extra_fixture)
    req = webob.Request.blank('/rpc')
    req.method = 'POST'
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'type': 'kernel'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(2, len(images))
    self.assertEqual(extra_id, images[0]['id'])
    self.assertEqual(UUID1, images[1]['id'])
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'type': 'random'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(0, len(images))
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'type': 'random'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(0, len(images))
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'poo': 'random'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(0, len(images))
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'type': 'kernel', 'distro': 'ubuntu'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(1, len(images))
    self.assertEqual(extra_id, images[0]['id'])
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'type': 'random', 'distro': 'random'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(0, len(images))
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'typo': 'random', 'poo': 'random'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(0, len(images))
    cmd = [{'command': 'image_get_all', 'kwargs': {'filters': {'type': 'kernel', 'poo': 'random'}}}]
    req.body = jsonutils.dump_as_bytes(cmd)
    res = req.get_response(self.api)
    self.assertEqual(http.OK, res.status_int)
    images = jsonutils.loads(res.body)[0]
    self.assertEqual(0, len(images))
