summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/api/controllers/v1/test_volume.py
blob: 16752fe0908ef779a48697a1d63d07f2d1b80ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
"""
Tests for the API /volume/ methods.
"""

from six.moves import http_client

from ironic.api.controllers import base as api_base
from ironic.api.controllers import v1 as api_v1
from ironic.tests.unit.api import base as test_api_base


class TestGetVolume(test_api_base.BaseApiTest):

    def _test_links(self, data, key, headers):
        self.assertIn(key, data)
        self.assertEqual(2, len(data[key]))
        for l in data[key]:
            bookmark = (l['rel'] == 'bookmark')
            self.assertTrue(self.validate_link(l['href'],
                                               bookmark=bookmark,
                                               headers=headers))

    def test_get_volume(self):
        headers = {api_base.Version.string: str(api_v1.MAX_VER)}
        data = self.get_json('/volume/', headers=headers)
        for key in ['links', 'connectors', 'targets']:
            self._test_links(data, key, headers)
        self.assertIn('/volume/connectors',
                      data['connectors'][0]['href'])
        self.assertIn('/volume/connectors',
                      data['connectors'][1]['href'])
        self.assertIn('/volume/targets',
                      data['targets'][0]['href'])
        self.assertIn('/volume/targets',
                      data['targets'][1]['href'])

    def test_get_volume_invalid_api_version(self):
        headers = {api_base.Version.string: str(api_v1.MIN_VER)}
        response = self.get_json('/volume/', headers=headers,
                                 expect_errors=True)
        self.assertEqual(http_client.NOT_FOUND, response.status_int)