Example #1
0
 def test_archived_label_is_removed_from_message(self):
     """testing message is added to database with archived label removed and inbox and read is added instead"""
     self.populate_database(1)
     with self.engine.connect() as con:
         query = 'SELECT msg_id FROM secure_message LIMIT 1'
         query_x = con.execute(query)
         names = []
         for row in query_x:
             names.append(row[0])
     with app.app_context():
         with current_app.test_request_context():
             msg_id = str(names[0])
             message_service = Retriever()
             message = message_service.retrieve_message(
                 msg_id, 'respondent.21345')
             modifier = Modifier()
             modifier.add_archived(message, 'respondent.21345')
             message = message_service.retrieve_message(
                 msg_id, 'respondent.21345')
             modifier.del_archived(
                 message,
                 'respondent.21345',
             )
             message = message_service.retrieve_message(
                 msg_id, 'respondent.21345')
             self.assertCountEqual(message['labels'], ['SENT'])
Example #2
0
 def test_read_date_is_not_reset(self):
     """testing message read_date is not reset when unread label is removed again"""
     self.populate_database(1)
     with self.engine.connect() as con:
         query = 'SELECT msg_id FROM secure_message LIMIT 1'
         query_x = con.execute(query)
         names = []
         for row in query_x:
             names.append(row[0])
     with app.app_context():
         with current_app.test_request_context():
             msg_id = str(names[0])
             message_service = Retriever()
             modifier = Modifier()
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             modifier.del_unread(message, 'internal.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             read_date_set = message['read_date']
             modifier.add_unread(message, 'internal.21345')
             modifier.del_unread(message, 'internal.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             self.assertEqual(message['read_date'], read_date_set)
Example #3
0
 def get(message_id):
     """Get message by id"""
     # res = authenticate(request)
     user_urn = request.headers.get(
         'user_urn')  # getting user urn from header request
     # check user is authorised to view message
     message_service = Retriever()
     # pass msg_id and user urn
     resp = message_service.retrieve_message(message_id, user_urn)
     return jsonify(resp)
Example #4
0
 def test_archive_is_removed_for_both_respondent_and_internal(self):
     """testing archive label is removed after being added to both respondent and internal"""
     self.populate_database(2)
     with self.engine.connect() as con:
         query = 'SELECT msg_id FROM secure_message LIMIT 1'
         query_x = con.execute(query)
         names = []
         for row in query_x:
             names.append(row[0])
     with app.app_context():
         with current_app.test_request_context():
             msg_id = str(names[0])
             message_service = Retriever()
             modifier = Modifier()
             message = message_service.retrieve_message(
                 msg_id, 'respondent.21345')
             modifier.add_archived(message, 'respondent.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             modifier.add_archived(message, 'internal.21345')
             message = message_service.retrieve_message(
                 msg_id, 'respondent.21345')
             modifier.del_archived(message, 'respondent.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             modifier.del_archived(message, 'internal.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             self.assertCountEqual(message['labels'], ['UNREAD', 'INBOX'])
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             self.assertCountEqual(message['labels'], ['UNREAD', 'INBOX'])
Example #5
0
 def test_add_archive_is_added_to_internal(self):
     """testing message is added to database with archived label attached"""
     self.populate_database(1)
     with self.engine.connect() as con:
         query = 'SELECT msg_id FROM secure_message LIMIT 1'
         query_x = con.execute(query)
         names = []
         for row in query_x:
             names.append(row[0])
     with app.app_context():
         with current_app.test_request_context():
             msg_id = str(names[0])
             message_service = Retriever()
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             Modifier.del_archived(message, 'internal.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             Modifier.add_archived(message, 'internal.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             self.assertCountEqual(message['labels'],
                                   ['UNREAD', 'INBOX', 'ARCHIVE'])