Example #1
0
 def test_save_message_with_roles(self):
     role = Role('some role')
     db.session.add(role)
     user1 = User('aaaaa', 'passssss', roles=[role.id])
     user2 = User('bbbbb', 'passs', roles=[role.id])
     db.session.add(user1)
     db.session.add(user2)
     db.session.commit()
     message_data = {
         'users': [user1.id],
         'roles': [role.id],
         'subject': 'Re: This thing',
         'requires_reauth': False
     }
     workflow_execution_id = uuid4()
     body = [{
         'text': 'Here is something to look at'
     }, {
         'url': 'look.here.com'
     }]
     save_message(body, message_data, workflow_execution_id, False)
     messages = Message.query.all()
     self.assertEqual(len(messages), 1)
     message = messages[0]
     self.assertEqual(len(message.users), 2)
     for user in message.users:
         self.assertIn(user, [user1, user2])
Example #2
0
 def test_save_message(self):
     user1 = User('aaaaa', 'passssss')
     user2 = User('bbbbb', 'passs')
     db.session.add(user1)
     db.session.add(user2)
     db.session.commit()
     message_data = {
         'users': [user1.id, user2.id],
         'roles': [],
         'subject': 'Re: This thing',
         'requires_reauth': False
     }
     workflow_execution_uid = 'workflow_uid1'
     body = [{
         'text': 'Here is something to look at'
     }, {
         'url': 'look.here.com'
     }]
     save_message(body, message_data, workflow_execution_uid, False)
     messages = Message.query.all()
     self.assertEqual(len(messages), 1)
     message = messages[0]
     self.assertEqual(message.subject, message_data['subject'])
     self.assertEqual(len(message.users), 2)
     for user in message.users:
         self.assertIn(user, [user1, user2])
     self.assertEqual(message.body, json.dumps(body))
Example #3
0
 def test_save_message_no_valid_users(self):
     message_data = {'users': [10, 20],
                     'roles': [],
                     'subject': 'Re: This a thing',
                     'requires_reauth': False}
     workflow_execution_id = 'workflow_uid4'
     body = {'body': [{'text': 'Here is something to look at'}, {'url': 'look.here.com'}]}
     save_message(body, message_data, workflow_execution_id, False)
     messages = Message.query.all()
     self.assertEqual(len(messages), 0)
Example #4
0
 def test_save_message_no_valid_users(self):
     message_data = {
         'users': [10, 20],
         'roles': [],
         'subject': 'Re: This a thing',
         'requires_reauth': False
     }
     workflow_execution_id = 'workflow_uid4'
     body = {
         'body': [{
             'text': 'Here is something to look at'
         }, {
             'url': 'look.here.com'
         }]
     }
     save_message(body, message_data, workflow_execution_id, False)
     messages = Message.query.all()
     self.assertEqual(len(messages), 0)
Example #5
0
 def test_save_message_with_roles(self):
     role = Role('some role')
     db.session.add(role)
     user1 = User('aaaaa', 'passssss', roles=[role.id])
     user2 = User('bbbbb', 'passs', roles=[role.id])
     db.session.add(user1)
     db.session.add(user2)
     db.session.commit()
     message_data = {'users': [user1.id],
                     'roles': [role.id],
                     'subject': 'Re: This thing',
                     'requires_reauth': False}
     workflow_execution_id = uuid4()
     body = [{'text': 'Here is something to look at'}, {'url': 'look.here.com'}]
     save_message(body, message_data, workflow_execution_id, False)
     messages = Message.query.all()
     self.assertEqual(len(messages), 1)
     message = messages[0]
     self.assertEqual(len(message.users), 2)
     for user in message.users:
         self.assertIn(user, [user1, user2])