File: test_availability_zones.py

package info (click to toggle)
python-manilaclient 5.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,768 kB
  • sloc: python: 49,541; makefile: 99; sh: 2
file content (56 lines) | stat: -rw-r--r-- 2,129 bytes parent folder | download | duplicates (3)
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
53
54
55
56
# Copyright 2016 Mirantis, Inc.
# All Rights Reserved.
#
#    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.

from unittest import mock

import ddt

from manilaclient import api_versions
from manilaclient.tests.unit import utils
from manilaclient.v2 import availability_zones


@ddt.ddt
class AvailabilityZoneTest(utils.TestCase):

    def _get_manager(self, microversion):
        version = api_versions.APIVersion(microversion)
        mock_microversion = mock.Mock(api_version=version)
        return availability_zones.AvailabilityZoneManager(
            api=mock_microversion)

    def _get_resource_path(self, microversion):
        if (api_versions.APIVersion(microversion) >
                api_versions.APIVersion("2.6")):
            return availability_zones.RESOURCE_PATH
        return availability_zones.RESOURCE_PATH_LEGACY

    @ddt.data("2.6", "2.7", api_versions.MIN_VERSION, api_versions.MAX_VERSION)
    def test_list(self, microversion):
        manager = self._get_manager(microversion)
        resource_path = self._get_resource_path(microversion)
        self.mock_object(manager, "_list")

        result = manager.list()

        manager._list.assert_called_once_with(
            resource_path, availability_zones.RESOURCE_NAME)
        self.assertEqual(manager._list.return_value, result)

    def test_representation(self):
        resource = availability_zones.AvailabilityZone(None, {})
        resource.id = "9d21a755-b5ca-453e-a155-ee9c9066d909"
        expected = "<AvailabilityZone: 9d21a755-b5ca-453e-a155-ee9c9066d909>"
        self.assertEqual(repr(resource), expected)