blob: 2b8c19e6e8b549fed577fed423d5180783c6f188 [file] [log] [blame]
Soren Hansenbc1d3a02011-09-08 13:33:17 +02001import json
2import os
3
4import unittest2 as unittest
5
6from kong import openstack
7
8
9class ImagesTest(unittest.TestCase):
10
11 def setUp(self):
12 self.os = openstack.Manager()
13
14 host = self.os.config.nova.host
15 port = self.os.config.nova.port
16 self.base_url = '%s:%s' % (host, port)
17 self.api_url = os.path.join(self.base_url, self.os.config.nova.base_url)
18
19 def tearDown(self):
20 pass
21
22 def _assert_image_links(self, image):
23 image_id = str(image['id'])
24
25 self_link = 'http://' + os.path.join(self.api_url,
26 self.os.config.nova.project_id,
27 'images', image_id)
28 bookmark_link = 'http://' + os.path.join(self.base_url,
29 self.os.config.nova.project_id,
30 'images', image_id)
31
32 expected_links = [
33 {
34 'rel': 'self',
35 'href': self_link,
36 },
37 {
38 'rel': 'bookmark',
39 'href': bookmark_link,
40 },
41 ]
42
43 self.assertEqual(image['links'], expected_links)
44
45 def _assert_image_entity_basic(self, image):
46 actual_keys = set(image.keys())
47 expected_keys = set((
48 'id',
49 'name',
50 'links',
51 ))
52 self.assertEqual(actual_keys, expected_keys)
53
54 self._assert_image_links(image)
55
56 def _assert_image_entity_detailed(self, image):
57 keys = image.keys()
58 if 'server' in keys:
59 keys.remove('server')
60 actual_keys = set(keys)
61 expected_keys = set((
62 'id',
63 'name',
64 'progress',
65 'created',
66 'updated',
67 'status',
68 'metadata',
69 'links',
70 ))
71 self.assertEqual(actual_keys, expected_keys)
72
73 self._assert_image_links(image)
74
75 def test_index(self):
76 """List all images"""
77
78 response, body = self.os.nova.request('GET', '/images')
79
80 self.assertEqual(response['status'], '200')
81 resp_body = json.loads(body)
82 self.assertEqual(resp_body.keys(), ['images'])
83
84 for image in resp_body['images']:
85 self._assert_image_entity_basic(image)
86
87 def test_detail(self):
88 """List all images in detail"""
89
90 response, body = self.os.nova.request('GET', '/images/detail')
91
92 self.assertEqual(response['status'], '200')
93 resp_body = json.loads(body)
94 self.assertEqual(resp_body.keys(), ['images'])
95
96 for image in resp_body['images']:
97 self._assert_image_entity_detailed(image)