blob: 0b4318205e1f8aabb27f649d2539a3abdaa15dc9 [file] [log] [blame]
Soren Hansenbc1d3a02011-09-08 13:33:17 +02001import json
2import os
3
Soren Hansenbc1d3a02011-09-08 13:33:17 +02004from kong import openstack
Soren Hansen6adacc82011-09-09 13:34:35 +02005from kong import tests
Soren Hansenbc1d3a02011-09-08 13:33:17 +02006
7
Soren Hansen6adacc82011-09-09 13:34:35 +02008class ImagesTest(tests.FunctionalTest):
Soren Hansenbc1d3a02011-09-08 13:33:17 +02009
10 def setUp(self):
Soren Hansen6adacc82011-09-09 13:34:35 +020011 super(ImagesTest, self).setUp()
Soren Hansend6b047a2011-09-09 13:39:32 +020012 self.os = openstack.Manager(self.nova)
Soren Hansenbc1d3a02011-09-08 13:33:17 +020013
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)