barbican/functionaltests/api/v1/smoke/test_versions.py
Juan Antonio Osorio Robles 3b20d84312 Display all versions info in versions controller
This patch enables the "versions controller" or "/" resource to display
information relevant to all the versions of the Barbican API (which is
only v1 at the moment). This is done in the same fashion Keystone
displays it, and it has the purpose of enabling more automatic discovery
as described in the blueprint.

Accessing the root resource with the "build" query parameter, such as:

    $ curl http://localhost:9311/?build

will display the build information.

On the other hand, this introduces the V1Controller, which is now the
root controller (which requires authentication) for Barbican.

Accessing the "/v1" resource will display the version information in the
way it's required by keystone.

The json-home implementation is left for a subsequent CR.

Partially implements blueprint fix-version-api
Change-Id: Ie7e706adcf1b5d74f64776b888a06638247b4e87
2015-06-18 05:21:10 +03:00

48 lines
1.9 KiB
Python

# Copyright (c) 2014 Rackspace, Inc.
#
# 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 functionaltests.api import base
class VersionDiscoveryTestCase(base.TestCase):
def test_version_get_as_unauthenticated(self):
"""Covers retrieving version as unauthenticated user."""
self._do_version_test(use_auth=False)
def test_version_get_as_authenticated(self):
"""Covers retrieving version as authenticated user."""
self._do_version_test(use_auth=True)
def _do_version_test(self, use_auth=False):
"""Get version string with or without authentication.
:param use_auth: True to use authentication, False otherwise. Default
is False
"""
url_without_version = self.client.get_base_url(include_version=False)
resp = self.client.get(url_without_version, use_auth=use_auth)
body = resp.json()
self.assertEqual(resp.status_code, 300)
versions_response = body['versions']['values']
v1_info = versions_response[0]
# NOTE(jaosorior): I used assertIn instead of assertEqual because we
# might start using decimal numbers in the future. So when that happens
# this test will still be valid.
self.assertIn('v1', v1_info['id'])
self.assertEqual(len(v1_info['media-types']), 1)
self.assertEqual(v1_info['media-types'][0]['base'], 'application/json')