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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# 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 oslo_config import cfg
from oslo_config import fixture as cfg_fixture
import oslotest.base
import webtest
from designate.api import versions
from designate.common import constants
CONF = cfg.CONF
class TestApiVersion(oslotest.base.BaseTestCase):
def setUp(self):
super(TestApiVersion, self).setUp()
self.useFixture(cfg_fixture.Config(CONF))
def test_add_a_version(self):
api_url = 'http://localhost/v2'
results = []
versions._add_a_version(
results, 'v2.1', api_url, constants.EXPERIMENTAL,
'2022-08-10T00:00:00Z')
self.assertEqual(1, len(results))
self.assertEqual('v2.1', results[0]['id'])
self.assertEqual(constants.EXPERIMENTAL, results[0]['status'])
self.assertEqual('2022-08-10T00:00:00Z', results[0]['updated'])
self.assertEqual(2, len(results[0]['links']))
def test_get_versions(self):
CONF.set_override('enable_host_header', False, 'service:api')
CONF.set_override(
'api_base_uri', 'http://127.0.0.2:9001/', 'service:api'
)
self.app = versions.factory({})
self.client = webtest.TestApp(self.app)
response = self.client.get('/')
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertEqual(2, len(response.json['versions']))
self.assertEqual(
'http://127.0.0.2:9001/v2',
response.json['versions'][0]['links'][0]['href']
)
def test_get_versions_with_enable_host_header(self):
CONF.set_override('enable_host_header', True, 'service:api')
self.app = versions.factory({})
self.client = webtest.TestApp(self.app)
response = self.client.get('/')
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertEqual(2, len(response.json['versions']))
self.assertEqual(
'http://localhost/v2',
response.json['versions'][0]['links'][0]['href']
)
|