1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from yardstick.tests.unit.apiserver import APITestCase
14 from api.resources.v2.images import format_image_info
17 class V2ImagesTestCase(APITestCase):
18 @mock.patch('yardstick.common.openstack_utils.list_images')
19 @mock.patch('yardstick.common.utils.source_env')
20 def test_get(self, _, mock_list_images):
22 unittest.skip('host config error')
25 single_image = mock.MagicMock()
26 single_image.name = 'yardstick-image'
27 single_image.size = 16384
28 single_image.status = 'active'
29 single_image.updated_at = '2018-04-08'
31 mock_list_images.return_value = [single_image]
32 url = 'api/v2/yardstick/images'
34 self.assertEqual(resp.get('status'), 1)
37 class FormatImageInfoTestCase(unittest.TestCase):
38 def test_format_image_info(self):
39 image = mock.MagicMock()
40 image.name = 'yardstick-image'
42 image.status = 'active'
43 image.updated_at = '2018-04-08'
45 image_dict = format_image_info(image)
46 self.assertEqual(image_dict.get('size'), 1)