blob: 501f954d09446b617980d60784c5b315e96fd9c1 [file] [log] [blame]
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +00001# Copyright 2015 NEC Corporation. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +000015import testtools
16
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +000017from tempest.common import api_version_utils
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +000018from tempest import exceptions
19from tempest.tests import base
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +000020
21
22class TestVersionSkipLogic(base.TestCase):
23
24 def _test_version(self, test_min_version, test_max_version,
25 cfg_min_version, cfg_max_version, expected_skip=False):
26 try:
27 api_version_utils.check_skip_with_microversion(test_min_version,
28 test_max_version,
29 cfg_min_version,
30 cfg_max_version)
31 except testtools.TestCase.skipException as e:
32 if not expected_skip:
33 raise testtools.TestCase.failureException(e.message)
34
35 def test_version_min_in_range(self):
36 self._test_version('2.2', '2.10', '2.1', '2.7')
37
38 def test_version_max_in_range(self):
39 self._test_version('2.1', '2.3', '2.2', '2.7')
40
41 def test_version_cfg_in_range(self):
42 self._test_version('2.2', '2.9', '2.3', '2.7')
43
44 def test_version_equal(self):
45 self._test_version('2.2', '2.2', '2.2', '2.2')
46
47 def test_version_below_cfg_min(self):
48 self._test_version('2.2', '2.4', '2.5', '2.7', expected_skip=True)
49
50 def test_version_above_cfg_max(self):
51 self._test_version('2.8', '2.9', '2.3', '2.7', expected_skip=True)
52
53 def test_version_min_greater_than_max(self):
Ghanshyamd2e7a0a2016-02-02 10:53:33 +090054 self.assertRaises(exceptions.InvalidAPIVersionRange,
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +000055 self._test_version, '2.8', '2.7', '2.3', '2.7')
56
57 def test_cfg_version_min_greater_than_max(self):
Ghanshyamd2e7a0a2016-02-02 10:53:33 +090058 self.assertRaises(exceptions.InvalidAPIVersionRange,
Ken'ichi Ohmichi4d237e72015-11-05 06:32:33 +000059 self._test_version, '2.2', '2.7', '2.9', '2.7')
ghanshyam4e2be342015-11-27 18:07:46 +090060
61
62class TestSelectRequestMicroversion(base.TestCase):
63
64 def _test_request_version(self, test_min_version,
65 cfg_min_version, expected_version):
66 selected_version = api_version_utils.select_request_microversion(
67 test_min_version, cfg_min_version)
68 self.assertEqual(expected_version, selected_version)
69
70 def test_cfg_min_version_greater(self):
71 self._test_request_version('2.1', '2.3', expected_version='2.3')
72
73 def test_class_min_version_greater(self):
74 self._test_request_version('2.5', '2.3', expected_version='2.5')
75
76 def test_cfg_min_version_none(self):
77 self._test_request_version('2.5', None, expected_version='2.5')
78
79 def test_class_min_version_none(self):
80 self._test_request_version(None, '2.3', expected_version='2.3')
81
82 def test_both_min_version_none(self):
83 self._test_request_version(None, None, expected_version=None)
84
85 def test_both_min_version_equal(self):
86 self._test_request_version('2.3', '2.3', expected_version='2.3')
Ghanshyambbdb33b2016-01-08 11:51:07 +090087
88
89class TestMicroversionHeaderMatches(base.TestCase):
90
91 def test_header_matches(self):
92 microversion_header_name = 'x-openstack-xyz-api-version'
93 request_microversion = '2.1'
94 test_respose = {microversion_header_name: request_microversion}
95 api_version_utils.assert_version_header_matches_request(
96 microversion_header_name, request_microversion, test_respose)
97
98 def test_header_does_not_match(self):
99 microversion_header_name = 'x-openstack-xyz-api-version'
100 request_microversion = '2.1'
101 test_respose = {microversion_header_name: '2.2'}
102 self.assertRaises(
103 exceptions.InvalidHTTPResponseHeader,
104 api_version_utils.assert_version_header_matches_request,
105 microversion_header_name, request_microversion, test_respose)
106
107 def test_header_not_present(self):
108 microversion_header_name = 'x-openstack-xyz-api-version'
109 request_microversion = '2.1'
110 test_respose = {}
111 self.assertRaises(
112 exceptions.InvalidHTTPResponseHeader,
113 api_version_utils.assert_version_header_matches_request,
114 microversion_header_name, request_microversion, test_respose)