コード例 #1
0
    def test_trigger_action_taken_workflow_sends_responded_message(self):
        uid = str(uuid4())
        message = Message('subject',
                          'body',
                          uid,
                          users=[self.user, self.user2],
                          requires_response=True)
        db.session.add(message)
        db.session.commit()
        walkoff.messaging.workflow_authorization_cache.add_authorized_users(
            uid, users=[1, 2])
        walkoff.messaging.workflow_authorization_cache.add_user_in_progress(
            uid, self.user.id)

        res = {'called': False}

        @walkoff.messaging.MessageActionEvent.responded.connect
        def connected(message_in, **data):
            res['called'] = True
            self.assertEqual(message_in.id, message.id)
            self.assertEqual(data['data']['user'], self.user)

        WalkoffEvent.TriggerActionTaken.send(
            self.construct_mock_trigger_sender(uid),
            data={'workflow_execution_id': uid})
        self.assertTrue(res['called'])
コード例 #2
0
 def make_message(users, requires_reauth=False, requires_action=False):
     message = Message('subject here',
                       json.dumps({'message': 'some message'}),
                       uuid4(),
                       users,
                       requires_reauth=requires_reauth,
                       requires_response=requires_action)
     db.session.add(message)
     return message
コード例 #3
0
 def test_log_action_taken_on_message_invalid_user(self):
     uid = uuid4()
     message = Message('subject',
                       'body',
                       uid,
                       users=[self.user, self.user2],
                       requires_response=True)
     db.session.add(message)
     log_action_taken_on_message(1000, uid)
     self.assertEqual(len(list(message.history)), 0)
コード例 #4
0
    def create_messages(self, auths):
        if self.uid1 in auths:
            message = Message('subject here', json.dumps({'message': 'some message'}), self.uid1,
                              users=auths[self.uid1][0], roles=auths[self.uid1][1],
                              requires_reauth=True, requires_response=True)
            db.session.add(message)

        if self.uid2 in auths:
            message = Message('subject here', json.dumps({'message': 'some message'}), self.uid2,
                              users=auths[self.uid2][0], roles=auths[self.uid2][1],
                              requires_reauth=True, requires_response=True)
            db.session.add(message)

        if self.uid3 in auths:
            message = Message('subject here', json.dumps({'message': 'some message'}), self.uid3,
                              users=auths[self.uid3][0], roles=auths[self.uid3][1],
                              requires_reauth=True, requires_response=True)
            db.session.add(message)
        db.session.commit()
コード例 #5
0
 def test_log_action_taken_on_message(self):
     uid = uuid4()
     message = Message('subject',
                       'body',
                       uid,
                       users=[self.user, self.user2],
                       requires_response=True)
     db.session.add(message)
     log_action_taken_on_message(self.user.id, uid)
     self.assertEqual(len(list(message.history)), 1)
     self.assertEqual(message.history[0].action, MessageAction.respond)
コード例 #6
0
 def get_default_message(self,
                         commit=False,
                         requires_reauth=False,
                         requires_response=False):
     uid = uuid4()
     message = Message('subject here',
                       json.dumps({'message': 'some message'}),
                       uid, [self.user, self.user2],
                       requires_reauth=requires_reauth,
                       requires_response=requires_response)
     db.session.add(message)
     if commit:
         db.session.commit()
     return message, uid
コード例 #7
0
 def test_trigger_action_taken_workflow(self):
     uid = str(uuid4())
     message = Message('subject',
                       'body',
                       uid,
                       users=[self.user, self.user2],
                       requires_response=True)
     db.session.add(message)
     db.session.commit()
     log_action_taken_on_message(self.user.id, uid)
     message = Message.query.filter(
         Message.workflow_execution_id == uid).first()
     self.assertEqual(len(list(message.history)), 1)
     self.assertEqual(message.history[0].action, MessageAction.respond)
コード例 #8
0
 def test_init(self):
     uid = uuid4()
     message = Message('subject here', 'body goes here', uid,
                       [self.user, self.user2])
     self.assertEqual(message.subject, 'subject here')
     self.assertEqual(message.body, 'body goes here')
     self.assertEqual(message.workflow_execution_id, uid)
     self.assertListEqual(list(message.users), [self.user, self.user2])
     self.assertFalse(message.requires_reauth)
     self.assertFalse(message.requires_response)
     db.session.add(message)
     db.session.commit()
     self.assertIsNotNone(message.id)
     self.assertLess(
         (datetime.utcnow() - message.created_at).total_seconds(), 5)
     self.assertEqual(len(list(self.user.messages)), 1)
コード例 #9
0
ファイル: utils.py プロジェクト: sunilpentapati/WALKOFF
def save_message(body, message_data, workflow_execution_id, requires_action):
    users = get_all_matching_users_for_message(message_data['users'],
                                               message_data['roles'])
    if users:
        subject = message_data.get('subject', '')
        message_entry = Message(
            subject,
            json.dumps(body),
            workflow_execution_id,
            users,
            requires_reauth=message_data['requires_reauth'],
            requires_response=requires_action)
        db.session.add(message_entry)
        db.session.commit()
        walkoff.messaging.MessageActionEvent.created.send(message_entry)
    else:
        logger.error(
            'Cannot send message. Users {0} or roles {1} do not exist'.format(
                message_data['users'], message_data['roles']))
コード例 #10
0
    def test_trigger_action_taken_workflow_sends_responded_message(self):
        uid = str(uuid4())
        message = Message('subject',
                          'body',
                          uid,
                          users=[self.user, self.user2],
                          requires_response=True)
        db.session.add(message)
        db.session.commit()

        res = {'called': False}

        @walkoff.messaging.MessageActionEvent.responded.connect
        def connected(message_in, **data):
            res['called'] = True
            self.assertEqual(message_in.id, message.id)
            self.assertEqual(data['data']['user'], self.user)

        log_action_taken_on_message(self.user.id, uid)
        self.assertTrue(res['called'])
コード例 #11
0
 def test_trigger_action_taken_workflow(self):
     uid = str(uuid4())
     message = Message('subject',
                       'body',
                       uid,
                       users=[self.user, self.user2],
                       requires_response=True)
     db.session.add(message)
     db.session.commit()
     walkoff.messaging.workflow_authorization_cache.add_authorized_users(
         uid, users=[1, 2])
     walkoff.messaging.workflow_authorization_cache.add_user_in_progress(
         uid, self.user.id)
     WalkoffEvent.TriggerActionTaken.send(
         self.construct_mock_trigger_sender(uid),
         data={'workflow_execution_id': uid})
     message = Message.query.filter(
         Message.workflow_execution_id == uid).first()
     self.assertEqual(len(list(message.history)), 1)
     self.assertEqual(message.history[0].action, MessageAction.respond)
     self.assertFalse(
         walkoff.messaging.workflow_authorization_cache.
         workflow_requires_authorization(uid))
コード例 #12
0
 def test_init_message_requires_action(self):
     message = Message('subject here',
                       'body goes here',
                       uuid4(), [self.user],
                       requires_response=True)
     self.assertTrue(message.requires_response)