Add missing test for "Show API v2 details" action
Add test to cover the request to "Show API v2 details"[0] action. Add the show_version function to the NetworkVersionsClient class. Modify the list_versions function of the NetworkVersionsClient class to use the .get() function instead of the .raw_request() function because using the .get() makes the function simplier and abstracts out the logging and retrying a request for us. Add the unit tests for the show_version function. [0] https://developer.openstack.org/api-ref/network/v2/index.html#show-api-v2-details Change-Id: I7ebea0c53437e929fc613495bcb8a8f8838c2044
This commit is contained in:
parent
7e3c936898
commit
fb4d863703
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``show_version`` function to the ``NetworkVersionsClient`` client. This
|
||||||
|
allows the possibility of getting details for Networking API.
|
||||||
|
|
||||||
|
.. API reference: https://developer.openstack.org/api-ref/network/v2/index.html#show-api-v2-details
|
@ -29,7 +29,7 @@ class NetworksApiDiscovery(base.BaseNetworkTest):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
result = self.network_versions_client.list_versions()
|
result = self.network_versions_client.list_versions()
|
||||||
expected_versions = ('v2.0')
|
expected_versions = ('v2.0',)
|
||||||
expected_resources = ('id', 'links', 'status')
|
expected_resources = ('id', 'links', 'status')
|
||||||
received_list = result.values()
|
received_list = result.values()
|
||||||
|
|
||||||
@ -38,3 +38,14 @@ class NetworksApiDiscovery(base.BaseNetworkTest):
|
|||||||
for resource in expected_resources:
|
for resource in expected_resources:
|
||||||
self.assertIn(resource, version)
|
self.assertIn(resource, version)
|
||||||
self.assertIn(version['id'], expected_versions)
|
self.assertIn(version['id'], expected_versions)
|
||||||
|
|
||||||
|
@decorators.attr(type='smoke')
|
||||||
|
@decorators.idempotent_id('e64b7216-3178-4263-967c-d389290988bf')
|
||||||
|
def test_show_api_v2_details(self):
|
||||||
|
"""Test that GET /v2.0/ returns expected resources."""
|
||||||
|
current_version = 'v2.0'
|
||||||
|
expected_resources = ('subnet', 'network', 'port')
|
||||||
|
result = self.network_versions_client.show_version(current_version)
|
||||||
|
actual_resources = [r['name'] for r in result['resources']]
|
||||||
|
for resource in expected_resources:
|
||||||
|
self.assertIn(resource, actual_resources)
|
||||||
|
@ -12,32 +12,36 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
from oslo_serialization import jsonutils as json
|
from oslo_serialization import jsonutils as json
|
||||||
|
|
||||||
|
from tempest.lib.common import rest_client
|
||||||
from tempest.lib.services.network import base
|
from tempest.lib.services.network import base
|
||||||
|
|
||||||
|
|
||||||
class NetworkVersionsClient(base.BaseNetworkClient):
|
class NetworkVersionsClient(base.BaseNetworkClient):
|
||||||
|
|
||||||
def list_versions(self):
|
def list_versions(self):
|
||||||
"""Do a GET / to fetch available API version information."""
|
"""Do a GET / to fetch available API version information.
|
||||||
|
|
||||||
version_url = self._get_base_version_url()
|
For more information, please refer to the official API reference:
|
||||||
|
https://developer.openstack.org/api-ref/network/v2/index.html#list-api-versions
|
||||||
|
"""
|
||||||
|
|
||||||
# Note: we do a raw_request here because we want to use
|
# Note: we do a self.get('/') here because we want to use
|
||||||
# an unversioned URL, not "v2/$project_id/".
|
# an unversioned URL, not "v2/$project_id/".
|
||||||
# Since raw_request doesn't log anything, we do that too.
|
resp, body = self.get('/')
|
||||||
start = time.time()
|
|
||||||
self._log_request_start('GET', version_url)
|
|
||||||
response, body = self.raw_request(version_url, 'GET')
|
|
||||||
self._error_checker(response, body)
|
|
||||||
end = time.time()
|
|
||||||
self._log_request('GET', version_url, response,
|
|
||||||
secs=(end - start), resp_body=body)
|
|
||||||
|
|
||||||
self.response_checker('GET', response, body)
|
|
||||||
self.expected_success(200, response.status)
|
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
return body
|
self.expected_success(200, resp.status)
|
||||||
|
return rest_client.ResponseBody(resp, body)
|
||||||
|
|
||||||
|
def show_version(self, version):
|
||||||
|
"""Do a GET /<version> to fetch available resources.
|
||||||
|
|
||||||
|
For more information, please refer to the official API reference:
|
||||||
|
https://developer.openstack.org/api-ref/network/v2/index.html#show-api-v2-details
|
||||||
|
"""
|
||||||
|
|
||||||
|
resp, body = self.get(version + '/')
|
||||||
|
body = json.loads(body)
|
||||||
|
self.expected_success(200, resp.status)
|
||||||
|
return rest_client.ResponseBody(resp, body)
|
||||||
|
@ -12,63 +12,92 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
|
||||||
|
|
||||||
from tempest.lib.services.network import versions_client
|
from tempest.lib.services.network import versions_client
|
||||||
from tempest.tests.lib import fake_auth_provider
|
from tempest.tests.lib import fake_auth_provider
|
||||||
from tempest.tests.lib.services import base
|
from tempest.tests.lib.services import base
|
||||||
|
|
||||||
|
|
||||||
class TestNetworkVersionsClient(base.BaseServiceTest):
|
class TestNetworkVersionsClient(base.BaseServiceTest):
|
||||||
|
VERSION = "v2.0"
|
||||||
FAKE_INIT_VERSION = {
|
|
||||||
"version": {
|
|
||||||
"id": "v2.0",
|
|
||||||
"links": [
|
|
||||||
{
|
|
||||||
"href": "http://openstack.example.com/v2.0/",
|
|
||||||
"rel": "self"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"href": "http://docs.openstack.org/",
|
|
||||||
"rel": "describedby",
|
|
||||||
"type": "text/html"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"status": "CURRENT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FAKE_VERSIONS_INFO = {
|
FAKE_VERSIONS_INFO = {
|
||||||
"versions": [FAKE_INIT_VERSION["version"]]
|
"versions": [
|
||||||
}
|
{
|
||||||
|
"id": "v2.0",
|
||||||
FAKE_VERSION_INFO = copy.deepcopy(FAKE_INIT_VERSION)
|
"links": [
|
||||||
|
{
|
||||||
FAKE_VERSION_INFO["version"]["media-types"] = [
|
"href": "http://openstack.example.com/%s/" % VERSION,
|
||||||
{
|
"rel": "self"
|
||||||
"base": "application/json",
|
}
|
||||||
"type": "application/vnd.openstack.network+json;version=2.0"
|
],
|
||||||
}
|
"status": "CURRENT"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
FAKE_VERSION_DETAILS = {
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"collection": "subnets",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"href": "http://openstack.example.com:9696/"
|
||||||
|
"%s/subnets" % VERSION,
|
||||||
|
"rel": "self"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "subnet"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collection": "networks",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"href": "http://openstack.example.com:9696/"
|
||||||
|
"%s/networks" % VERSION,
|
||||||
|
"rel": "self"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "network"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"collection": "ports",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"href": "http://openstack.example.com:9696/"
|
||||||
|
"%s/ports" % VERSION,
|
||||||
|
"rel": "self"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "port"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestNetworkVersionsClient, self).setUp()
|
super(TestNetworkVersionsClient, self).setUp()
|
||||||
fake_auth = fake_auth_provider.FakeAuthProvider()
|
fake_auth = fake_auth_provider.FakeAuthProvider()
|
||||||
self.versions_client = (
|
self.versions_client = versions_client.NetworkVersionsClient(
|
||||||
versions_client.NetworkVersionsClient
|
fake_auth, 'compute', 'regionOne')
|
||||||
(fake_auth, 'compute', 'regionOne'))
|
|
||||||
|
|
||||||
def _test_versions_client(self, bytes_body=False):
|
def _test_versions_client(self, func, body, bytes_body=False, **kwargs):
|
||||||
self.check_service_client_function(
|
self.check_service_client_function(
|
||||||
self.versions_client.list_versions,
|
func, 'tempest.lib.common.rest_client.RestClient.raw_request',
|
||||||
'tempest.lib.common.rest_client.RestClient.raw_request',
|
body, bytes_body, 200, **kwargs)
|
||||||
self.FAKE_VERSIONS_INFO,
|
|
||||||
bytes_body,
|
|
||||||
200)
|
|
||||||
|
|
||||||
def test_list_versions_client_with_str_body(self):
|
def test_list_versions_client_with_str_body(self):
|
||||||
self._test_versions_client()
|
self._test_versions_client(self.versions_client.list_versions,
|
||||||
|
self.FAKE_VERSIONS_INFO)
|
||||||
|
|
||||||
def test_list_versions_client_with_bytes_body(self):
|
def test_list_versions_client_with_bytes_body(self):
|
||||||
self._test_versions_client(bytes_body=True)
|
self._test_versions_client(self.versions_client.list_versions,
|
||||||
|
self.FAKE_VERSIONS_INFO, bytes_body=True)
|
||||||
|
|
||||||
|
def test_show_version_client_with_str_body(self):
|
||||||
|
self._test_versions_client(self.versions_client.show_version,
|
||||||
|
self.FAKE_VERSION_DETAILS,
|
||||||
|
version=self.VERSION)
|
||||||
|
|
||||||
|
def test_show_version_client_with_bytes_body(self):
|
||||||
|
self._test_versions_client(self.versions_client.show_version,
|
||||||
|
self.FAKE_VERSION_DETAILS, bytes_body=True,
|
||||||
|
version=self.VERSION)
|
||||||
|
Loading…
Reference in New Issue
Block a user