當前位置: 首頁>>代碼示例>>Python>>正文


Python ExtendedResourceContainer.create_prepare_resource_support方法代碼示例

本文整理匯總了Python中pyon.ion.resource.ExtendedResourceContainer.create_prepare_resource_support方法的典型用法代碼示例。如果您正苦於以下問題:Python ExtendedResourceContainer.create_prepare_resource_support方法的具體用法?Python ExtendedResourceContainer.create_prepare_resource_support怎麽用?Python ExtendedResourceContainer.create_prepare_resource_support使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyon.ion.resource.ExtendedResourceContainer的用法示例。


在下文中一共展示了ExtendedResourceContainer.create_prepare_resource_support方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: prepare_resource_support

# 需要導入模塊: from pyon.ion.resource import ExtendedResourceContainer [as 別名]
# 或者: from pyon.ion.resource.ExtendedResourceContainer import create_prepare_resource_support [as 別名]
    def prepare_resource_support(self, resource_type='', resource_id=''):
        """Returns a structured dict with information to help create/update a resource

        @param resource_type    str
        @param resource_id    str
        @retval resource_data    GenericPrepareSupport
        @throws BadRequest    A parameter is missing
        @throws NotFound    An object with the specified resource_id does not exist
        """

        if not resource_type:
            raise BadRequest("The resource_type parameter is required")

        extended_resource_handler = ExtendedResourceContainer(self, self)

        resource_data = extended_resource_handler.create_prepare_resource_support(resource_id=resource_id, prepare_resource_type=OT.GenericPrepareSupport, origin_resource_type=resource_type)

        #Fill out service request information for creating a instrument device
        extended_resource_handler.set_service_requests(resource_data.create_request, 'resource_registry',
            'create', { "object":  "$(object)" })

        #Fill out service request information for creating a instrument device
        extended_resource_handler.set_service_requests(resource_data.update_request, 'resource_registry',
            'update', { "object":  "$(object)" })

        return resource_data
開發者ID:caseybryant,項目名稱:pyon,代碼行數:28,代碼來源:resregistry.py

示例2: prepare_user_info_support

# 需要導入模塊: from pyon.ion.resource import ExtendedResourceContainer [as 別名]
# 或者: from pyon.ion.resource.ExtendedResourceContainer import create_prepare_resource_support [as 別名]
    def prepare_user_info_support(self, user_info_id=''):
        """
        Returns the object containing the data to create/update a user info resource
        """

        # TODO: Precondition or check: only the actor identity associated with this user or an ORG_MANAGER/ION_MANAGER
        # can edit this user info resource

        extended_resource_handler = ExtendedResourceContainer(self)

        resource_data = extended_resource_handler.create_prepare_resource_support(user_info_id, OT.UserInfoPrepareSupport)

        return resource_data
開發者ID:ednad,項目名稱:coi-services,代碼行數:15,代碼來源:identity_management_service.py

示例3: test_create_extended_resource_container

# 需要導入模塊: from pyon.ion.resource import ExtendedResourceContainer [as 別名]
# 或者: from pyon.ion.resource.ExtendedResourceContainer import create_prepare_resource_support [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')
開發者ID:j2project,項目名稱:pyon,代碼行數:104,代碼來源:test_resource.py


注:本文中的pyon.ion.resource.ExtendedResourceContainer.create_prepare_resource_support方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。