Add basic api version test coverage

Change-Id: Idb04e81ce5954ca8b5e387dc7c0776fdf7d08779
This commit is contained in:
Erik Olof Gunnar Andersson 2022-10-08 13:40:23 -07:00
parent 0b162a4c48
commit fb876d0ddc
1 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,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']
)