'Tests that /images registry API returns list of public images based
a filter on user-defined properties.'

def test_get_index_filter_on_user_defined_properties(self):

    image1_id = _gen_uuid()
    properties = {'distro': 'ubuntu', 'arch': 'i386'}
    extra_fixture = self.get_fixture(id=image1_id, name='image-extra-1', properties=properties)
    db_api.image_create(self.context, extra_fixture)
    image2_id = _gen_uuid()
    properties = {'distro': 'ubuntu', 'arch': 'x86_64', 'foo': 'bar'}
    extra_fixture = self.get_fixture(id=image2_id, name='image-extra-2', properties=properties)
    db_api.image_create(self.context, extra_fixture)
    res = self.get_api_response_ext(http.OK, url='/images?property-distro=ubuntu')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(2, len(images))
    self.assertEqual(image2_id, images[0]['id'])
    self.assertEqual(image1_id, images[1]['id'])
    res = self.get_api_response_ext(http.OK, url='/images?property-distro=fedora')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(0, len(images))
    res = self.get_api_response_ext(http.OK, url='/images?property-arch=i386')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(1, len(images))
    self.assertEqual(image1_id, images[0]['id'])
    res = self.get_api_response_ext(http.OK, url='/images?property-arch=x86_64')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(1, len(images))
    self.assertEqual(image2_id, images[0]['id'])
    res = self.get_api_response_ext(http.OK, url='/images?property-foo=bar')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(1, len(images))
    self.assertEqual(image2_id, images[0]['id'])
    res = self.get_api_response_ext(http.OK, url='/images?property-foo=baz')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(0, len(images))
    res = self.get_api_response_ext(http.OK, url='/images?property-arch=x86_64&property-distro=ubuntu')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(1, len(images))
    self.assertEqual(image2_id, images[0]['id'])
    res = self.get_api_response_ext(http.OK, url='/images?property-arch=i386&property-distro=ubuntu')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(1, len(images))
    self.assertEqual(image1_id, images[0]['id'])
    res = self.get_api_response_ext(http.OK, url='/images?property-arch=random&property-distro=ubuntu')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(0, len(images))
    res = self.get_api_response_ext(http.OK, url='/images?property-arch=random&property-distro=random')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(0, len(images))
    res = self.get_api_response_ext(http.OK, url='/images?property-boo=far&property-poo=far')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(0, len(images))
    res = self.get_api_response_ext(http.OK, url='/images?property-foo=bar&property-poo=far')
    images = jsonutils.loads(res.body)['images']
    self.assertEqual(0, len(images))
