Пример #1
0
class TestPolicyManagementServiceInt(IonIntegrationTestCase):
    def setUp(self):

        # Start container
        self._start_container()
        self.container.start_rel_from_url('res/deploy/r2coi.yml')

        self.convo_management_service = ConversationManagementServiceClient(
            node=self.container.node)

        self.resource_registry = ResourceRegistryServiceClient(
            node=self.container.node)

        self.rpc_scribble_protocol = \
            '''global protocol RPC (role provider, role requester)
            {
                request from requester to provider;
            choice at provider {
                accept from provider to requester;
            choice at provider {
                (inform) from provider to requester;
            } or {
                (failure) from provider to requester;}
            } or {
                reject from provider to requester;}}'''

    def test_conversation_type_crud(self):
        bad_obj = IonObject('ConversationType',
                            name='bad name',
                            definition=self.rpc_scribble_protocol)
        with self.assertRaises(BadRequest):
            self.convo_management_service.create_conversation_type(bad_obj)

        convo_type_obj = IonObject('ConversationType',
                                   name='RPC',
                                   definition=self.rpc_scribble_protocol)
        convo_type_id = self.convo_management_service.create_conversation_type(
            convo_type_obj)
        self.assertNotEqual(convo_type_id, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.read_conversation_type()

        convo_type = None
        convo_type = self.convo_management_service.read_conversation_type(
            convo_type_id)
        self.assertNotEqual(convo_type, None)

        convo_type.name = 'RPC_2'
        self.convo_management_service.update_conversation_type(convo_type)

        convo_type = None
        convo_type = self.convo_management_service.read_conversation_type(
            convo_type_id)
        self.assertNotEqual(convo_type, None)
        self.assertEqual(convo_type.name, 'RPC_2')

        self.convo_management_service.delete_conversation_type(convo_type_id)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.read_conversation_type(convo_type_id)
        self.assertIn("does not exist", cm.exception.message)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.delete_conversation_type(
                convo_type_id)
        self.assertIn("does not exist", cm.exception.message)
        with self.assertRaises(BadRequest):
            self.convo_management_service.delete_conversation_type()

    def test_conversation_role_crud(self):
        bad_obj = IonObject("ConversationRole", {"name": "bad name"})
        with self.assertRaises(BadRequest):
            self.convo_management_service.create_conversation_role(bad_obj)
        convo_role_obj = IonObject("ConversationRole", {"name": "provider"})
        convo_role_id = self.convo_management_service.create_conversation_role(
            convo_role_obj)
        self.assertNotEqual(convo_role_id, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.read_conversation_role()
        convo_role = None
        convo_role = self.convo_management_service.read_conversation_role(
            convo_role_id)
        self.assertNotEqual(convo_role, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.update_conversation_type(bad_obj)
        convo_role.name = 'requester'
        self.convo_management_service.update_conversation_type(convo_role)

        convo_role = None
        convo_role = self.convo_management_service.read_conversation_role(
            convo_role_id)
        self.assertNotEqual(convo_role, None)
        self.assertEqual(convo_role.name, 'requester')

        with self.assertRaises(BadRequest):
            self.convo_management_service.delete_conversation_role()
        self.convo_management_service.delete_conversation_role(convo_role_id)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.read_conversation_role(convo_role_id)
        self.assertIn("does not exist", cm.exception.message)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.delete_conversation_role(
                convo_role_id)
        self.assertIn("does not exist", cm.exception.message)

    def test_conversation_type_role_binding(self):

        convo_type_obj = IonObject('ConversationType',
                                   name='RPC',
                                   definition=self.rpc_scribble_protocol)
        convo_type_id = self.convo_management_service.create_conversation_type(
            convo_type_obj)
        self.assertNotEqual(convo_type_id, None)

        convo_role_obj = IonObject("ConversationRole", {"name": "provider"})
        convo_role_id = self.convo_management_service.create_conversation_role(
            convo_role_obj)
        self.assertNotEqual(convo_role_id, None)

        self.convo_management_service.bind_conversation_type_to_role(
            convo_type_id, convo_role_id)

        convo_role_obj = IonObject("ConversationRole", {"name": "requester"})
        convo_role_id = self.convo_management_service.create_conversation_role(
            convo_role_obj)
        self.assertNotEqual(convo_role_id, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.bind_conversation_type_to_role()
        self.convo_management_service.bind_conversation_type_to_role(
            convo_type_id, convo_role_id)

        assoc, _ = self.resource_registry.find_objects(convo_type_id,
                                                       PRED.hasRole,
                                                       RT.ConversationRole)
        self.assertEqual(len(assoc), 2)

        with self.assertRaises(BadRequest):
            self.convo_management_service.unbind_conversation_type_to_role()
        self.convo_management_service.unbind_conversation_type_to_role(
            convo_type_id, convo_role_id)

        assoc, _ = self.resource_registry.find_objects(convo_type_id,
                                                       PRED.hasRole,
                                                       RT.ConversationRole)
        self.assertEqual(len(assoc), 1)
class TestPolicyManagementServiceInt(IonIntegrationTestCase):

    def setUp(self):

        # Start container
        self._start_container()
        self.container.start_rel_from_url('res/deploy/r2coi.yml')

        self.convo_management_service = ConversationManagementServiceClient(node=self.container.node)

        self.resource_registry = ResourceRegistryServiceClient(node=self.container.node)

        self.rpc_scribble_protocol = \
            '''global protocol RPC (role provider, role requester)
            {
                request from requester to provider;
            choice at provider {
                accept from provider to requester;
            choice at provider {
                (inform) from provider to requester;
            } or {
                (failure) from provider to requester;}
            } or {
                reject from provider to requester;}}'''


    def test_conversation_type_crud(self):
        bad_obj = IonObject('ConversationType', name='bad name', definition=self.rpc_scribble_protocol)
        with self.assertRaises(BadRequest):
            self.convo_management_service.create_conversation_type(bad_obj)

        convo_type_obj = IonObject('ConversationType', name='RPC', definition=self.rpc_scribble_protocol)
        convo_type_id = self.convo_management_service.create_conversation_type(convo_type_obj)
        self.assertNotEqual(convo_type_id, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.read_conversation_type()

        convo_type = None
        convo_type = self.convo_management_service.read_conversation_type(convo_type_id)
        self.assertNotEqual(convo_type, None)

        convo_type.name = 'RPC_2'
        self.convo_management_service.update_conversation_type(convo_type)

        convo_type = None
        convo_type = self.convo_management_service.read_conversation_type(convo_type_id)
        self.assertNotEqual(convo_type, None)
        self.assertEqual(convo_type.name, 'RPC_2')

        self.convo_management_service.delete_conversation_type(convo_type_id)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.read_conversation_type(convo_type_id)
        self.assertIn("does not exist", cm.exception.message)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.delete_conversation_type(convo_type_id)
        self.assertIn("does not exist", cm.exception.message)
        with self.assertRaises(BadRequest):
            self.convo_management_service.delete_conversation_type()

    def test_conversation_role_crud(self):
        bad_obj = IonObject("ConversationRole", {"name": "bad name"})
        with self.assertRaises(BadRequest):
            self.convo_management_service.create_conversation_role(bad_obj)
        convo_role_obj = IonObject("ConversationRole", {"name": "provider"})
        convo_role_id = self.convo_management_service.create_conversation_role(convo_role_obj)
        self.assertNotEqual(convo_role_id, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.read_conversation_role()
        convo_role = None
        convo_role = self.convo_management_service.read_conversation_role(convo_role_id)
        self.assertNotEqual(convo_role, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.update_conversation_type(bad_obj)
        convo_role.name = 'requester'
        self.convo_management_service.update_conversation_type(convo_role)

        convo_role = None
        convo_role = self.convo_management_service.read_conversation_role(convo_role_id)
        self.assertNotEqual(convo_role, None)
        self.assertEqual(convo_role.name, 'requester')

        with self.assertRaises(BadRequest):
            self.convo_management_service.delete_conversation_role()
        self.convo_management_service.delete_conversation_role(convo_role_id)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.read_conversation_role(convo_role_id)
        self.assertIn("does not exist", cm.exception.message)

        with self.assertRaises(NotFound) as cm:
            self.convo_management_service.delete_conversation_role(convo_role_id)
        self.assertIn("does not exist", cm.exception.message)

    def test_conversation_type_role_binding(self):

        convo_type_obj = IonObject('ConversationType', name='RPC', definition=self.rpc_scribble_protocol)
        convo_type_id = self.convo_management_service.create_conversation_type(convo_type_obj)
        self.assertNotEqual(convo_type_id, None)

        convo_role_obj = IonObject("ConversationRole", {"name": "provider"})
        convo_role_id = self.convo_management_service.create_conversation_role(convo_role_obj)
        self.assertNotEqual(convo_role_id, None)

        self.convo_management_service.bind_conversation_type_to_role(convo_type_id, convo_role_id)

        convo_role_obj = IonObject("ConversationRole", {"name": "requester"})
        convo_role_id = self.convo_management_service.create_conversation_role(convo_role_obj)
        self.assertNotEqual(convo_role_id, None)

        with self.assertRaises(BadRequest):
            self.convo_management_service.bind_conversation_type_to_role()
        self.convo_management_service.bind_conversation_type_to_role(convo_type_id, convo_role_id)

        assoc,_ = self.resource_registry.find_objects(convo_type_id, PRED.hasRole, RT.ConversationRole)
        self.assertEqual(len(assoc),2)

        with self.assertRaises(BadRequest):
            self.convo_management_service.unbind_conversation_type_to_role()
        self.convo_management_service.unbind_conversation_type_to_role(convo_type_id, convo_role_id)

        assoc,_ = self.resource_registry.find_objects(convo_type_id, PRED.hasRole, RT.ConversationRole)
        self.assertEqual(len(assoc),1)