1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5#      http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from openstack.compute.v2 import image
14from openstack.tests.unit import base
15
16
17IDENTIFIER = 'IDENTIFIER'
18
19EXAMPLE = {
20    'id': IDENTIFIER,
21    'links': '2',
22    'name': '3',
23    'created': '2015-03-09T12:14:57.233772',
24    'metadata': {'key': '2'},
25    'minDisk': 3,
26    'minRam': 4,
27    'progress': 5,
28    'status': '6',
29    'updated': '2015-03-09T12:15:57.233772',
30    'OS-EXT-IMG-SIZE:size': 8
31}
32
33
34class TestImage(base.TestCase):
35
36    def test_basic(self):
37        sot = image.Image()
38        self.assertEqual('image', sot.resource_key)
39        self.assertEqual('images', sot.resources_key)
40        self.assertEqual('/images', sot.base_path)
41        self.assertFalse(sot.allow_create)
42        self.assertTrue(sot.allow_fetch)
43        self.assertFalse(sot.allow_commit)
44        self.assertTrue(sot.allow_delete)
45        self.assertTrue(sot.allow_list)
46
47        self.assertDictEqual({"server": "server",
48                              "name": "name",
49                              "status": "status",
50                              "type": "type",
51                              "min_disk": "minDisk",
52                              "min_ram": "minRam",
53                              "changes_since": "changes-since",
54                              "limit": "limit",
55                              "marker": "marker"},
56                             sot._query_mapping._mapping)
57
58    def test_make_basic(self):
59        sot = image.Image(**EXAMPLE)
60        self.assertEqual(EXAMPLE['id'], sot.id)
61        self.assertEqual(EXAMPLE['links'], sot.links)
62        self.assertEqual(EXAMPLE['name'], sot.name)
63        self.assertEqual(EXAMPLE['created'], sot.created_at)
64        self.assertEqual(EXAMPLE['id'], sot.id)
65        self.assertEqual(EXAMPLE['links'], sot.links)
66        self.assertEqual(EXAMPLE['metadata'], sot.metadata)
67        self.assertEqual(EXAMPLE['minDisk'], sot.min_disk)
68        self.assertEqual(EXAMPLE['minRam'], sot.min_ram)
69        self.assertEqual(EXAMPLE['name'], sot.name)
70        self.assertEqual(EXAMPLE['progress'], sot.progress)
71        self.assertEqual(EXAMPLE['status'], sot.status)
72        self.assertEqual(EXAMPLE['updated'], sot.updated_at)
73        self.assertEqual(EXAMPLE['OS-EXT-IMG-SIZE:size'], sot.size)
74