commit
a97dbb768c
@ -25,6 +25,11 @@ class ClientTest(tutils.TestCase):
|
||||
self.assertEqual("RackManager",
|
||||
self.client.racks.__class__.__name__)
|
||||
self.assertEqual(self.client, self.client.racks.api)
|
||||
|
||||
self.assertEqual("ResourceClassManager",
|
||||
self.client.resource_classes.__class__.__name__)
|
||||
self.assertEqual(self.client, self.client.resource_classes.api)
|
||||
|
||||
self.assertEqual("FlavorManager",
|
||||
self.client.flavors.__class__.__name__)
|
||||
self.assertEqual(self.client, self.client.flavors.api)
|
||||
|
64
tuskarclient/tests/v1/test_flavors.py
Normal file
64
tuskarclient/tests/v1/test_flavors.py
Normal file
@ -0,0 +1,64 @@
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
|
||||
from tuskarclient.v1 import flavors
|
||||
import tuskarclient.tests.utils as tutils
|
||||
|
||||
|
||||
class FlavorManagerTest(tutils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(FlavorManagerTest, self).setUp()
|
||||
self.api = mock.Mock()
|
||||
self.fm = flavors.FlavorManager(self.api)
|
||||
|
||||
def test_get(self):
|
||||
self.fm._get = mock.Mock(return_value='fake_flavor')
|
||||
|
||||
self.assertEqual('fake_flavor', self.fm.get(5, 42))
|
||||
self.fm._get.assert_called_with('/v1/resource_classes/5/flavors/42')
|
||||
|
||||
def test_list(self):
|
||||
self.fm._list = mock.Mock(return_value=['fake_flavor'])
|
||||
|
||||
self.assertEqual(['fake_flavor'], self.fm.list(5))
|
||||
self.fm._list.assert_called_with('/v1/resource_classes/5/flavors')
|
||||
|
||||
def test_create(self):
|
||||
self.fm._create = mock.Mock(return_value=['fake_flavor'])
|
||||
|
||||
self.assertEqual(
|
||||
['fake_flavor'],
|
||||
self.fm.create(5, dummy='dummy flavor data'))
|
||||
|
||||
self.fm._create.assert_called_with(
|
||||
'/v1/resource_classes/5/flavors',
|
||||
{'dummy': 'dummy flavor data'})
|
||||
|
||||
def test_update(self):
|
||||
self.fm._update = mock.Mock(return_value=['fake_flavor'])
|
||||
|
||||
self.assertEqual(
|
||||
['fake_flavor'],
|
||||
self.fm.update(5, 42, dummy='dummy flavor data'))
|
||||
|
||||
self.fm._update.assert_called_with(
|
||||
'/v1/resource_classes/5/flavors/42',
|
||||
{'dummy': 'dummy flavor data'})
|
||||
|
||||
def test_delete(self):
|
||||
self.fm._delete = mock.Mock(return_value=None)
|
||||
|
||||
self.assertEqual(None, self.fm.delete(5, 42))
|
||||
self.fm._delete.assert_called_with('/v1/resource_classes/5/flavors/42')
|
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
from tuskarclient.common import http
|
||||
from tuskarclient.v1 import flavors
|
||||
from tuskarclient.v1 import racks
|
||||
from tuskarclient.v1 import resource_classes
|
||||
|
||||
@ -27,3 +28,4 @@ class Client(http.HTTPClient):
|
||||
super(Client, self).__init__(*args, **kwargs)
|
||||
self.racks = racks.RackManager(self)
|
||||
self.resource_classes = resource_classes.ResourceClassManager(self)
|
||||
self.flavors = flavors.FlavorManager(self)
|
||||
|
54
tuskarclient/v1/flavors.py
Normal file
54
tuskarclient/v1/flavors.py
Normal file
@ -0,0 +1,54 @@
|
||||
# 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 tuskarclient.common import base
|
||||
|
||||
|
||||
class Flavor(base.Resource):
|
||||
|
||||
def __repr__(self):
|
||||
return "<Flavor {0}>".format(self._info)
|
||||
|
||||
|
||||
class FlavorManager(base.Manager):
|
||||
|
||||
resource_class = Flavor
|
||||
|
||||
@staticmethod
|
||||
def _path(resource_class_id, flavor_id=None):
|
||||
if flavor_id:
|
||||
return ('/v1/resource_classes/{0}/flavors/{1}'
|
||||
.format(resource_class_id, flavor_id))
|
||||
else:
|
||||
return '/v1/resource_classes/{0}/flavors'.format(resource_class_id)
|
||||
|
||||
def _single_path(self, resource_class_id, flavor_id):
|
||||
if not flavor_id:
|
||||
raise ValueError("{0} flavor_id must not be null."
|
||||
.format(self.resource_class))
|
||||
return self._path(resource_class_id, flavor_id)
|
||||
|
||||
def get(self, resource_class_id, flavor_id):
|
||||
return self._get(self._single_path(resource_class_id, flavor_id))
|
||||
|
||||
def list(self, resource_class_id):
|
||||
return self._list(self._path(resource_class_id))
|
||||
|
||||
def create(self, resource_class_id, **kwargs):
|
||||
return self._create(self._path(resource_class_id), kwargs)
|
||||
|
||||
def update(self, resource_class_id, flavor_id, **kwargs):
|
||||
return self._update(self._single_path(resource_class_id, flavor_id),
|
||||
kwargs)
|
||||
|
||||
def delete(self, resource_class_id, flavor_id):
|
||||
return self._delete(self._single_path(resource_class_id, flavor_id))
|
Loading…
x
Reference in New Issue
Block a user