'Set up four test images and ensure each query param filter works'

def test_filtered_images(self):

    path = '/v1/images'
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    self.assertEqual('{"images":    []}', content)
    image_ids = []
    headers = {'Content-Type': 'application/octet-stream', 'X-Image-Meta-Name': 'Image1', 'X-Image-Meta-Status': 'active', 'X-Image-Meta-Container-Format': 'ovf', 'X-Image-Meta-Disk-Format': 'vdi', 'X-Image-Meta-Size': '19', 'X-Image-Meta-Is-Public': 'True', 'X-Image-Meta-Protected': 'True', 'X-Image-Meta-Property-pants': 'are    on'}
    path = '/v1/images'
    (response, content) = self.http.request(path, 'POST', headers=headers)
    self.assertEqual(http_client.CREATED, response.status)
    data = jsonutils.loads(content)
    self.assertEqual('are    on', data['image']['properties']['pants'])
    self.assertTrue(data['image']['is_public'])
    image_ids.append(data['image']['id'])
    headers = {'Content-Type': 'application/octet-stream', 'X-Image-Meta-Name': 'My    Image!', 'X-Image-Meta-Status': 'active', 'X-Image-Meta-Container-Format': 'ovf', 'X-Image-Meta-Disk-Format': 'vhd', 'X-Image-Meta-Size': '20', 'X-Image-Meta-Is-Public': 'True', 'X-Image-Meta-Protected': 'False', 'X-Image-Meta-Property-pants': 'are    on'}
    path = '/v1/images'
    (response, content) = self.http.request(path, 'POST', headers=headers)
    self.assertEqual(http_client.CREATED, response.status)
    data = jsonutils.loads(content)
    self.assertEqual('are    on', data['image']['properties']['pants'])
    self.assertTrue(data['image']['is_public'])
    image_ids.append(data['image']['id'])
    headers = {'Content-Type': 'application/octet-stream', 'X-Image-Meta-Name': 'My    Image!', 'X-Image-Meta-Status': 'saving', 'X-Image-Meta-Container-Format': 'ami', 'X-Image-Meta-Disk-Format': 'ami', 'X-Image-Meta-Size': '21', 'X-Image-Meta-Is-Public': 'True', 'X-Image-Meta-Protected': 'False', 'X-Image-Meta-Property-pants': 'are    off'}
    path = '/v1/images'
    (response, content) = self.http.request(path, 'POST', headers=headers)
    self.assertEqual(http_client.CREATED, response.status)
    data = jsonutils.loads(content)
    self.assertEqual('are    off', data['image']['properties']['pants'])
    self.assertTrue(data['image']['is_public'])
    image_ids.append(data['image']['id'])
    headers = {'Content-Type': 'application/octet-stream', 'X-Image-Meta-Name': 'My    Private    Image', 'X-Image-Meta-Status': 'active', 'X-Image-Meta-Container-Format': 'ami', 'X-Image-Meta-Disk-Format': 'ami', 'X-Image-Meta-Size': '22', 'X-Image-Meta-Is-Public': 'False', 'X-Image-Meta-Protected': 'False'}
    path = '/v1/images'
    (response, content) = self.http.request(path, 'POST', headers=headers)
    self.assertEqual(http_client.CREATED, response.status)
    data = jsonutils.loads(content)
    self.assertFalse(data['image']['is_public'])
    image_ids.append(data['image']['id'])
    path = '/v1/images'
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(3, len(data['images']))
    params = 'name=My%20Image!'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(2, len(data['images']))
    for image in data['images']:
        self.assertEqual('My    Image!', image['name'])
    params = 'status=queued'
    path = ('/v1/images/detail?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(3, len(data['images']))
    for image in data['images']:
        self.assertEqual('queued', image['status'])
    params = 'status=active'
    path = ('/v1/images/detail?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(0, len(data['images']))
    params = 'container_format=ovf'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(2, len(data['images']))
    for image in data['images']:
        self.assertEqual('ovf', image['container_format'])
    params = 'disk_format=vdi'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(1, len(data['images']))
    for image in data['images']:
        self.assertEqual('vdi', image['disk_format'])
    params = 'size_max=20'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(2, len(data['images']))
    for image in data['images']:
        self.assertLessEqual(image['size'], 20)
    params = 'size_min=20'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(2, len(data['images']))
    for image in data['images']:
        self.assertGreaterEqual(image['size'], 20)
    params = 'is_public=None'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(4, len(data['images']))
    params = 'is_public=False'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(1, len(data['images']))
    for image in data['images']:
        self.assertEqual('My    Private    Image', image['name'])
    params = 'is_public=True'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(3, len(data['images']))
    for image in data['images']:
        self.assertNotEqual(image['name'], 'My    Private    Image')
    params = 'protected=False'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(2, len(data['images']))
    for image in data['images']:
        self.assertNotEqual(image['name'], 'Image1')
    params = 'protected=True'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(1, len(data['images']))
    for image in data['images']:
        self.assertEqual('Image1', image['name'])
    params = 'property-pants=are%20on'
    path = ('/v1/images/detail?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(2, len(data['images']))
    for image in data['images']:
        self.assertEqual('are    on', image['properties']['pants'])
    params = 'name=My%20Image!&property-pants=are%20on'
    path = ('/v1/images/detail?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(1, len(data['images']))
    for image in data['images']:
        self.assertEqual('are    on', image['properties']['pants'])
        self.assertEqual('My    Image!', image['name'])
    yesterday = timeutils.isotime((timeutils.utcnow() - datetime.timedelta(1)))
    params = ('changes-since=%s' % yesterday)
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(3, len(data['images']))
    now = timeutils.utcnow()
    hour_ago = now.strftime('%Y-%m-%dT%H:%M:%S%%2B01:00')
    params = ('changes-since=%s' % hour_ago)
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(3, len(data['images']))
    tomorrow = timeutils.isotime((timeutils.utcnow() + datetime.timedelta(1)))
    params = ('changes-since=%s' % tomorrow)
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(0, len(data['images']))
    now = timeutils.utcnow()
    hour_hence = now.strftime('%Y-%m-%dT%H:%M:%S-01:00')
    params = ('changes-since=%s' % hour_hence)
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.OK, response.status)
    data = jsonutils.loads(content)
    self.assertEqual(0, len(data['images']))
    params = 'size_min=-1'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.BAD_REQUEST, response.status)
    self.assertIn('filter    size_min    got    -1', content)
    params = 'size_max=-1'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.BAD_REQUEST, response.status)
    self.assertIn('filter    size_max    got    -1', content)
    params = 'min_ram=-1'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.BAD_REQUEST, response.status)
    self.assertIn('Bad    value    passed    to    filter    min_ram    got    -1', content)
    params = 'protected=imalittleteapot'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.BAD_REQUEST, response.status)
    self.assertIn('protected    got    imalittleteapot', content)
    params = 'is_public=imalittleteapot'
    path = ('/v1/images?%s' % params)
    (response, content) = self.http.request(path, 'GET')
    self.assertEqual(http_client.BAD_REQUEST, response.status)
    self.assertIn('is_public    got    imalittleteapot', content)
