add yardstick iruya 9.0.0 release notes
[yardstick.git] / yardstick / tests / unit / apiserver / resources / v2 / test_images.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd.
3 #
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 ##############################################################################
9 import mock
10
11 import unittest
12
13 from yardstick.tests.unit.apiserver import APITestCase
14 from api.resources.v2.images import format_image_info
15
16
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):
21         if self.app is None:
22             unittest.skip('host config error')
23             return
24
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'
30
31         mock_list_images.return_value = [single_image]
32         url = 'api/v2/yardstick/images'
33         resp = self._get(url)
34         self.assertEqual(resp.get('status'), 1)
35
36
37 class FormatImageInfoTestCase(unittest.TestCase):
38     def test_format_image_info(self):
39         image = mock.MagicMock()
40         image.name = 'yardstick-image'
41         image.size = 1048576
42         image.status = 'active'
43         image.updated_at = '2018-04-08'
44
45         image_dict = format_image_info(image)
46         self.assertEqual(image_dict.get('size'), 1)