Files
python-cratonclient/cratonclient/tests/integration/v1/test_devices.py
Ian Cordasco a510d64cec Add Betamax for testing
Use keystoneauth1's Betamax test fixture to start recording
request-response interaction pairs in files. I'm starting this bit of
work with our hosts API module.

As a result of this testing, I discovered that we were not handling
keystoneauth1 exceptions inside of our session. This adds handling for
that with a new function for finding the right cratonclient exception to
raise in cratonclient.exceptions. Thus, this also includes testing for
the convenience functions in that module.

Users need only setup 4 environment variables for testing:

* CRATON_DEMO_USERNAME
* CRATON_DEMO_PROJECT
* CRATON_DEMO_TOKEN
* CRATON_DEMO_URL

Depends-On: I45de545b040d2b99ac8f3f4d3c81359615d328e8
Change-Id: Ib69d825a50a7e4179aefd11bcbfbed39c27c7fbe
Partially-implements: bp testing-plan
2017-03-21 10:27:33 -05:00

80 lines
2.8 KiB
Python

# -*- coding: utf-8 -*-
# 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.
"""The integration tests for the cratonclient.v1.devices."""
from cratonclient.tests.integration import base
class TestDevices(base.BetamaxTestCase):
"""DevicesManager integration tests."""
def cleanupCloud(self, cloud):
"""Add a cleanup task for this cloud."""
self.addCleanup(self.client.clouds.delete, cloud.id)
return cloud
def cleanupRegion(self, region):
"""Add a cleanup task for this region."""
self.addCleanup(self.client.regions.delete, region.id)
return region
def cleanupCell(self, cell):
"""Add a cleanup task for this cell."""
self.addCleanup(self.client.cells.delete, cell.id)
return cell
def cleanupHost(self, host):
"""Add a cleanup task for this host."""
self.addCleanup(self.client.hosts.delete, host.id)
return host
def setUp(self):
"""Set up our demo user client."""
super(TestDevices, self).setUp()
self.create_demo_client()
test_name = self.cassette_name.split('-', 1)[-1]
self.cloud = self.cleanupCloud(self.client.clouds.create(
name='cloud_{}'.format(test_name),
))
self.region = self.cleanupRegion(self.client.regions.create(
name='region_{}'.format(test_name),
cloud_id=self.cloud.id,
))
self.cells = [
self.cleanupCell(self.client.cells.create(
name='cell_{}_{}'.format(test_name, i),
region_id=self.region.id,
cloud_id=self.cloud.id,
))
for i in range(4)
]
self.hosts = [
self.cleanupHost(self.client.hosts.create(
name='host_{}_{}'.format(test_name, i),
cell_id=self.cells[i % 4].id,
region_id=self.region.id,
cloud_id=self.cloud.id,
device_type='server',
ip_address='127.0.1.{}'.format(i),
))
for i in range(35)
]
# NOTE(sigmavirus24): The API does not presently support
# /v1/network-devices
# self.network_devices = [
# self.cleanupNetworkDevice(self.client.network_devices.create(
# ))
# for i in range(35)
# ]