Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 1 | import json |
| 2 | import os |
| 3 | |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 4 | from kong import openstack |
Soren Hansen | 6adacc8 | 2011-09-09 13:34:35 +0200 | [diff] [blame] | 5 | from kong import tests |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 6 | |
| 7 | |
Soren Hansen | 6adacc8 | 2011-09-09 13:34:35 +0200 | [diff] [blame] | 8 | class ImagesTest(tests.FunctionalTest): |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 9 | |
| 10 | def setUp(self): |
Soren Hansen | 6adacc8 | 2011-09-09 13:34:35 +0200 | [diff] [blame] | 11 | super(ImagesTest, self).setUp() |
Soren Hansen | d6b047a | 2011-09-09 13:39:32 +0200 | [diff] [blame] | 12 | self.os = openstack.Manager(self.nova) |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 13 | |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 14 | def _assert_image_links(self, image): |
| 15 | image_id = str(image['id']) |
| 16 | |
Soren Hansen | 5f4ad83 | 2011-09-09 14:08:19 +0200 | [diff] [blame^] | 17 | mgmt_url = self.os.nova.management_url |
| 18 | bmk_url = re.sub(r'v1.1\/', r'', mgmt_url) |
| 19 | |
| 20 | self_link = os.path.join(mgmt_url, 'images', image_id) |
| 21 | bookmark_link = os.path.join(bmk_url, 'images', image_id) |
Soren Hansen | bc1d3a0 | 2011-09-08 13:33:17 +0200 | [diff] [blame] | 22 | |
| 23 | expected_links = [ |
| 24 | { |
| 25 | 'rel': 'self', |
| 26 | 'href': self_link, |
| 27 | }, |
| 28 | { |
| 29 | 'rel': 'bookmark', |
| 30 | 'href': bookmark_link, |
| 31 | }, |
| 32 | ] |
| 33 | |
| 34 | self.assertEqual(image['links'], expected_links) |
| 35 | |
| 36 | def _assert_image_entity_basic(self, image): |
| 37 | actual_keys = set(image.keys()) |
| 38 | expected_keys = set(( |
| 39 | 'id', |
| 40 | 'name', |
| 41 | 'links', |
| 42 | )) |
| 43 | self.assertEqual(actual_keys, expected_keys) |
| 44 | |
| 45 | self._assert_image_links(image) |
| 46 | |
| 47 | def _assert_image_entity_detailed(self, image): |
| 48 | keys = image.keys() |
| 49 | if 'server' in keys: |
| 50 | keys.remove('server') |
| 51 | actual_keys = set(keys) |
| 52 | expected_keys = set(( |
| 53 | 'id', |
| 54 | 'name', |
| 55 | 'progress', |
| 56 | 'created', |
| 57 | 'updated', |
| 58 | 'status', |
| 59 | 'metadata', |
| 60 | 'links', |
| 61 | )) |
| 62 | self.assertEqual(actual_keys, expected_keys) |
| 63 | |
| 64 | self._assert_image_links(image) |
| 65 | |
| 66 | def test_index(self): |
| 67 | """List all images""" |
| 68 | |
| 69 | response, body = self.os.nova.request('GET', '/images') |
| 70 | |
| 71 | self.assertEqual(response['status'], '200') |
| 72 | resp_body = json.loads(body) |
| 73 | self.assertEqual(resp_body.keys(), ['images']) |
| 74 | |
| 75 | for image in resp_body['images']: |
| 76 | self._assert_image_entity_basic(image) |
| 77 | |
| 78 | def test_detail(self): |
| 79 | """List all images in detail""" |
| 80 | |
| 81 | response, body = self.os.nova.request('GET', '/images/detail') |
| 82 | |
| 83 | self.assertEqual(response['status'], '200') |
| 84 | resp_body = json.loads(body) |
| 85 | self.assertEqual(resp_body.keys(), ['images']) |
| 86 | |
| 87 | for image in resp_body['images']: |
| 88 | self._assert_image_entity_detailed(image) |