本文整理匯總了Python中pyon.ion.resource.ExtendedResourceContainer.create_extended_resource_container_list方法的典型用法代碼示例。如果您正苦於以下問題:Python ExtendedResourceContainer.create_extended_resource_container_list方法的具體用法?Python ExtendedResourceContainer.create_extended_resource_container_list怎麽用?Python ExtendedResourceContainer.create_extended_resource_container_list使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyon.ion.resource.ExtendedResourceContainer
的用法示例。
在下文中一共展示了ExtendedResourceContainer.create_extended_resource_container_list方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_resource_extension
# 需要導入模塊: from pyon.ion.resource import ExtendedResourceContainer [as 別名]
# 或者: from pyon.ion.resource.ExtendedResourceContainer import create_extended_resource_container_list [as 別名]
def get_resource_extension(self, resource_id='', resource_extension='', ext_associations=None, ext_exclude=None):
"""Returns any ExtendedResource object containing additional related information derived from associations
@param resource_id str
@param resource_extension str
@param ext_associations dict
@param ext_exclude list
@retval actor_identity ExtendedResource
@throws BadRequest A parameter is missing
@throws NotFound An object with the specified resource_id does not exist
"""
if not resource_id:
raise BadRequest("The resource_id parameter is empty")
if not resource_extension:
raise BadRequest("The extended_resource parameter not set")
extended_resource_handler = ExtendedResourceContainer(self, self)
#Handle differently if the resource_id parameter is a list of ids
if resource_id.find('[') > -1:
res_input = eval(resource_id)
extended_resource_list = extended_resource_handler.create_extended_resource_container_list(resource_extension,
res_input, computed_resource_type=None, origin_resource_type=None, ext_associations=ext_associations, ext_exclude=ext_exclude)
return extended_resource_list
extended_resource = extended_resource_handler.create_extended_resource_container(resource_extension,
resource_id, computed_resource_type=None, ext_associations=ext_associations, ext_exclude=ext_exclude)
return extended_resource
示例2: test_create_extended_resource_container
# 需要導入模塊: from pyon.ion.resource import ExtendedResourceContainer [as 別名]
# 或者: from pyon.ion.resource.ExtendedResourceContainer import create_extended_resource_container_list [as 別名]
#.........這裏部分代碼省略.........
actor_identity = Mock()
actor_identity._id = '111'
actor_identity.name = "Foo"
actor_identity.type_ = RT.ActorIdentity
user_info = Mock()
user_info._id = '444'
user_info.name = "John Doe"
user_info.email = "[email protected]"
user_info.phone = "555-555-5555"
user_info.variables = [{"name": "subscribeToMailingList", "value": "False"}]
user_info2 = Mock()
user_info2._id = '445'
user_info2.name = "aka Evil Twin"
user_info2.email = "[email protected]"
user_info2.phone = "555-555-5555"
user_info2.variables = [{"name": "subscribeToMailingList", "value": "False"}]
# ActorIdentity to UserInfo association
actor_identity_to_info_association = Mock()
actor_identity_to_info_association._id = '555'
actor_identity_to_info_association.s = "111"
actor_identity_to_info_association.st = RT.ActorIdentity
actor_identity_to_info_association.p = PRED.hasInfo
actor_identity_to_info_association.o = "444"
actor_identity_to_info_association.ot = RT.UserInfo
# ActorIdentity to UserInfo association
actor_identity_to_info_association2 = Mock()
actor_identity_to_info_association2._id = '556'
actor_identity_to_info_association2.s = "111"
actor_identity_to_info_association2.st = RT.ActorIdentity
actor_identity_to_info_association2.p = PRED.hasInfo
actor_identity_to_info_association2.o = "445"
actor_identity_to_info_association2.ot = RT.UserInfo
# ActorIdentity to Instrument Device association
Instrument_device_to_actor_identity_association = Mock()
Instrument_device_to_actor_identity_association._id = '666'
Instrument_device_to_actor_identity_association.s = "123"
Instrument_device_to_actor_identity_association.st = RT.InstumentDevice
Instrument_device_to_actor_identity_association.p = PRED.hasOwner
Instrument_device_to_actor_identity_association.o = "111"
Instrument_device_to_actor_identity_association.ot = RT.ActorIdentity
# ActorIdentity to Instrument Device association
Instrument_device_to_actor_identity_association2 = Mock()
Instrument_device_to_actor_identity_association2._id = '667'
Instrument_device_to_actor_identity_association2.s = "456"
Instrument_device_to_actor_identity_association2.st = RT.InstumentDevice
Instrument_device_to_actor_identity_association2.p = PRED.hasOwner
Instrument_device_to_actor_identity_association2.o = "111"
Instrument_device_to_actor_identity_association2.ot = RT.ActorIdentity
with self.assertRaises(BadRequest) as cm:
extended_user = extended_resource_handler.create_extended_resource_container(RT.ActorIdentity, '111')
self.assertIn( 'The requested resource ActorIdentity is not extended from ResourceContainer',cm.exception.message)
obj = IonObject(OT.TestExtendedResource)
list_objs = ['123', '456', '789']
extended_resource_handler.set_field_associations(obj, 'policies', list_objs)
extended_resource_handler.set_field_associations(obj, 'policy_count', list_objs)
extended_resource_handler.set_field_associations(obj, 'resource_object', list_objs)
self.assertEquals(obj.policies, list_objs)
self.assertEquals(obj.policy_count, 3)
self.assertEquals(obj.resource_object, '123')
mock_clients.resource_registry.read.return_value = instrument_device
mock_clients.resource_registry.find_objects.return_value = ([actor_identity], [Instrument_device_to_actor_identity_association])
mock_clients.resource_registry.find_subjects.return_value = (None,None)
extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123')
self.assertEquals(extended_res.resource, instrument_device)
self.assertEquals(len(extended_res.owners),1)
self.assertEquals(extended_res.resource_object.type_, RT.SystemResource)
self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
#Test field exclusion
extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123',ext_exclude=['owners'])
self.assertEquals(extended_res.resource, instrument_device)
self.assertEquals(len(extended_res.owners),0)
self.assertEquals(extended_res.resource_object.type_, RT.SystemResource)
self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
#Test the list of ids interface
extended_res_list = extended_resource_handler.create_extended_resource_container_list(OT.TestExtendedResource, ['123','456'])
self.assertEqual(len(extended_res_list), 2)
self.assertEquals(extended_res_list[0].resource, instrument_device)
self.assertEquals(len(extended_res_list[0].owners),1)
self.assertEquals(extended_res_list[0].resource_object.type_, RT.SystemResource)
self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
示例3: test_create_extended_resource_container
# 需要導入模塊: from pyon.ion.resource import ExtendedResourceContainer [as 別名]
# 或者: from pyon.ion.resource.ExtendedResourceContainer import create_extended_resource_container_list [as 別名]
#.........這裏部分代碼省略.........
actor_identity_to_info_association = Mock()
actor_identity_to_info_association._id = '555'
actor_identity_to_info_association.s = "111"
actor_identity_to_info_association.st = RT.ActorIdentity
actor_identity_to_info_association.p = PRED.hasInfo
actor_identity_to_info_association.o = "444"
actor_identity_to_info_association.ot = RT.UserInfo
# ActorIdentity to UserInfo association
actor_identity_to_info_association2 = Mock()
actor_identity_to_info_association2._id = '556'
actor_identity_to_info_association2.s = "1112"
actor_identity_to_info_association2.st = RT.ActorIdentity
actor_identity_to_info_association2.p = PRED.hasInfo
actor_identity_to_info_association2.o = "445"
actor_identity_to_info_association2.ot = RT.UserInfo
# ActorIdentity to Instrument Device association
Instrument_device_to_actor_identity_association = Mock()
Instrument_device_to_actor_identity_association._id = '666'
Instrument_device_to_actor_identity_association.s = "123"
Instrument_device_to_actor_identity_association.st = RT.InstrumentDevice
Instrument_device_to_actor_identity_association.p = PRED.hasOwner
Instrument_device_to_actor_identity_association.o = "111"
Instrument_device_to_actor_identity_association.ot = RT.ActorIdentity
# ActorIdentity to Instrument Device association
Instrument_device_to_actor_identity_association2 = Mock()
Instrument_device_to_actor_identity_association2._id = '667'
Instrument_device_to_actor_identity_association2.s = "456"
Instrument_device_to_actor_identity_association2.st = RT.InstrumentDevice
Instrument_device_to_actor_identity_association2.p = PRED.hasOwner
Instrument_device_to_actor_identity_association2.o = "111"
Instrument_device_to_actor_identity_association2.ot = RT.ActorIdentity
with self.assertRaises(BadRequest) as cm:
extended_user = extended_resource_handler.create_extended_resource_container(RT.ActorIdentity, '111')
self.assertIn( 'The requested resource ActorIdentity is not extended from ResourceContainer',cm.exception.message)
mock_clients.resource_registry.read.return_value = instrument_device
mock_clients.resource_registry.find_objects.return_value = ([actor_identity], [Instrument_device_to_actor_identity_association])
mock_clients.resource_registry.find_subjects.return_value = (None,None)
mock_clients.resource_registry.find_associations.return_value = [actor_identity_to_info_association, Instrument_device_to_actor_identity_association]
mock_clients.resource_registry.read_mult.return_value = [user_info]
extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123')
self.assertEquals(extended_res.resource, instrument_device)
self.assertEquals(len(extended_res.owners),2)
self.assertEquals(extended_res.resource_object.type_, RT.SystemResource)
self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
self.assertEquals(extended_res.resource_object.name, 'TestSystem_Resource')
self.assertEquals(extended_res.owner_count, 2)
self.assertEquals(extended_res.single_owner.name, user_info.name)
self.assertEquals(len(extended_res.lcstate_transitions), 6)
self.assertEquals(set(extended_res.lcstate_transitions.keys()), set(['develop', 'deploy', 'retire', 'plan', 'integrate', 'delete']))
self.assertEquals(len(extended_res.availability_transitions), 2)
self.assertEquals(set(extended_res.availability_transitions.keys()), set(['enable', 'announce']))
extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResourceDevice, '123')
self.assertEquals(extended_res.resource, instrument_device)
self.assertEquals(len(extended_res.owners),2)
with self.assertRaises(Inconsistent) as cm:
extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResourceBad, '123')
#Test adding extra paramaters to methods
extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123', resource_name='AltSystem_Resource')
self.assertEquals(extended_res.resource, instrument_device)
self.assertEquals(len(extended_res.owners),2)
self.assertEquals(extended_res.resource_object.type_, RT.SystemResource)
self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
self.assertEquals(extended_res.resource_object.name, 'AltSystem_Resource')
#Test field exclusion
extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123',ext_exclude=['owners'])
self.assertEquals(extended_res.resource, instrument_device)
self.assertEquals(len(extended_res.owners),0)
self.assertEquals(extended_res.resource_object.type_, RT.SystemResource)
self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
#Test the list of ids interface
extended_res_list = extended_resource_handler.create_extended_resource_container_list(OT.TestExtendedResource, ['123','456'])
self.assertEqual(len(extended_res_list), 2)
self.assertEquals(extended_res_list[0].resource, instrument_device)
self.assertEquals(len(extended_res_list[0].owners),2)
self.assertEquals(extended_res_list[0].resource_object.type_, RT.SystemResource)
self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
#Test create_prepare_update_resource
prepare_create = extended_resource_handler.create_prepare_resource_support(prepare_resource_type=OT.TestPrepareUpdateResource)
self.assertEqual(prepare_create.type_, OT.TestPrepareUpdateResource)
self.assertEqual(prepare_create._id, '')
prepare_update = extended_resource_handler.create_prepare_resource_support(resource_id='123',prepare_resource_type=OT.TestPrepareUpdateResource)
self.assertEqual(prepare_update.type_, OT.TestPrepareUpdateResource)
self.assertEqual(prepare_update._id, '123')