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 | |
| 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) |