Add ut for list attribute client api
Change-Id: I74263294cb4138e2145f3384aad0f0c8aade68b2
This commit is contained in:
parent
b841f546b0
commit
bf9579eb24
|
@ -108,6 +108,24 @@ ACCELERATOR_REQUEST = {
|
|||
'attach_handle_info': accelerator_request_attach_handle_info,
|
||||
}
|
||||
|
||||
attribute_created_at = '2023-05-17T00:00:00.000000+00:00'
|
||||
attribute_updated_at = '2023-05-17T11:11:11.111111+11:11'
|
||||
attribute_id = 1
|
||||
attribute_uuid = uuid.uuid4().hex
|
||||
attribute_deployable_id = 'fake_attribute_name'
|
||||
attribute_key = 'traits1'
|
||||
attribute_value = 'CUSTOM_FAKE_DEVICE'
|
||||
|
||||
ATTRIBUTE = {
|
||||
'created_at': attribute_created_at,
|
||||
'updated_at': attribute_updated_at,
|
||||
'id': attribute_id,
|
||||
'uuid': attribute_uuid,
|
||||
'deployable_id': attribute_deployable_id,
|
||||
'key': attribute_key,
|
||||
'value': attribute_value,
|
||||
}
|
||||
|
||||
|
||||
class TestAccelerator(utils.TestCommand):
|
||||
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
# 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 copy
|
||||
|
||||
from cyborgclient.osc.v2 import attribute as osc_attribute
|
||||
from cyborgclient.tests.unit.osc.v2 import fakes as acc_fakes
|
||||
|
||||
|
||||
class TestAttribute(acc_fakes.TestAccelerator):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAttribute, self).setUp()
|
||||
|
||||
self.mock_acc_client = self.app.client_manager.accelerator
|
||||
self.mock_acc_client.reset_mock()
|
||||
|
||||
|
||||
class TestAttributeList(TestAttribute):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAttributeList, self).setUp()
|
||||
|
||||
self.mock_acc_client.attributes.return_value = [
|
||||
acc_fakes.FakeAcceleratorResource(
|
||||
None,
|
||||
copy.deepcopy(acc_fakes.ATTRIBUTE),
|
||||
loaded=True)
|
||||
]
|
||||
|
||||
self.cmd = osc_attribute.ListAttribute(self.app, None)
|
||||
|
||||
def test_device_profile_list(self):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
kwargs = {}
|
||||
|
||||
self.mock_acc_client.attributes.assert_called_with(**kwargs)
|
||||
|
||||
collist = (
|
||||
'uuid',
|
||||
'deployable_id',
|
||||
'key',
|
||||
'value'
|
||||
)
|
||||
self.assertEqual(collist, columns)
|
||||
|
||||
datalist = [(
|
||||
acc_fakes.attribute_uuid,
|
||||
acc_fakes.attribute_deployable_id,
|
||||
acc_fakes.attribute_key,
|
||||
acc_fakes.attribute_value,
|
||||
), ]
|
||||
self.assertEqual(datalist, list(data))
|
||||
|
||||
def test_device_profile_list_long(self):
|
||||
arglist = ['--long']
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
kwargs = {}
|
||||
|
||||
self.mock_acc_client.attributes.assert_called_with(**kwargs)
|
||||
|
||||
collist = (osc_attribute.ListAttribute.columns +
|
||||
osc_attribute.ListAttribute.detail_cols)
|
||||
self.assertEqual(list(collist), list(columns))
|
||||
|
||||
datalist = [(
|
||||
acc_fakes.attribute_uuid,
|
||||
acc_fakes.attribute_deployable_id,
|
||||
acc_fakes.attribute_key,
|
||||
acc_fakes.attribute_value,
|
||||
acc_fakes.attribute_created_at,
|
||||
acc_fakes.attribute_updated_at,
|
||||
), ]
|
||||
self.assertEqual(datalist, list(data))
|
Loading…
Reference in New Issue