'Tests that the /images/detail API returns list of
images that changed since the time defined by changes-since'

def test_get_details_filter_changes_since(self):

    dt1 = (timeutils.utcnow() - datetime.timedelta(1))
    iso1 = timeutils.isotime(dt1)
    date_only1 = dt1.strftime('%Y-%m-%d')
    date_only2 = dt1.strftime('%Y%m%d')
    date_only3 = dt1.strftime('%Y-%m%d')
    dt2 = (timeutils.utcnow() + datetime.timedelta(1))
    iso2 = timeutils.isotime(dt2)
    image_ts = (timeutils.utcnow() + datetime.timedelta(2))
    hour_before = image_ts.strftime('%Y-%m-%dT%H:%M:%S%%2B01:00')
    hour_after = image_ts.strftime('%Y-%m-%dT%H:%M:%S-01:00')
    dt4 = (timeutils.utcnow() + datetime.timedelta(3))
    iso4 = timeutils.isotime(dt4)
    UUID3 = _gen_uuid()
    extra_fixture = {'id': UUID3, 'status': 'active', 'is_public': True, 'disk_format': 'vhd', 'container_format': 'ovf', 'name': 'fake    image    #3', 'size': 18, 'checksum': None}
    db_api.image_create(self.context, extra_fixture)
    db_api.image_destroy(self.context, UUID3)
    UUID4 = _gen_uuid()
    extra_fixture = {'id': UUID4, 'status': 'active', 'is_public': True, 'disk_format': 'ami', 'container_format': 'ami', 'name': 'fake    image    #4', 'size': 20, 'checksum': None, 'created_at': image_ts, 'updated_at': image_ts}
    db_api.image_create(self.context, extra_fixture)
    req = webob.Request.blank('/images/detail')
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    res_dict = jsonutils.loads(res.body)
    images = res_dict['images']
    self.assertEqual(2, len(images))
    self.assertEqual(UUID4, images[0]['id'])
    self.assertEqual(UUID2, images[1]['id'])
    req = webob.Request.blank(('/images/detail?changes-since=%s' % iso1))
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    res_dict = jsonutils.loads(res.body)
    images = res_dict['images']
    self.assertEqual(3, len(images))
    self.assertEqual(UUID4, images[0]['id'])
    self.assertEqual(UUID3, images[1]['id'])
    self.assertEqual(UUID2, images[2]['id'])
    req = webob.Request.blank(('/images/detail?changes-since=%s' % iso2))
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    res_dict = jsonutils.loads(res.body)
    images = res_dict['images']
    self.assertEqual(1, len(images))
    self.assertEqual(UUID4, images[0]['id'])
    req = webob.Request.blank(('/images/detail?changes-since=%s' % hour_before))
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    res_dict = jsonutils.loads(res.body)
    images = res_dict['images']
    self.assertEqual(1, len(images))
    self.assertEqual(UUID4, images[0]['id'])
    req = webob.Request.blank(('/images/detail?changes-since=%s' % hour_after))
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    res_dict = jsonutils.loads(res.body)
    images = res_dict['images']
    self.assertEqual(0, len(images))
    req = webob.Request.blank(('/images/detail?changes-since=%s' % iso4))
    res = req.get_response(self.api)
    self.assertEqual(http_client.OK, res.status_int)
    res_dict = jsonutils.loads(res.body)
    images = res_dict['images']
    self.assertEqual(0, len(images))
    for param in [date_only1, date_only2, date_only3]:
        req = webob.Request.blank(('/images/detail?changes-since=%s' % param))
        res = req.get_response(self.api)
        self.assertEqual(http_client.OK, res.status_int)
        res_dict = jsonutils.loads(res.body)
        images = res_dict['images']
        self.assertEqual(3, len(images))
        self.assertEqual(UUID4, images[0]['id'])
        self.assertEqual(UUID3, images[1]['id'])
        self.assertEqual(UUID2, images[2]['id'])
    req = webob.Request.blank('/images/detail?changes-since=')
    res = req.get_response(self.api)
    self.assertEqual(http_client.BAD_REQUEST, res.status_int)
