Example #1
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 #2
0
    def test_draft_label_is_deleted(self):
        """Check draft label is deleted for message"""
        with app.app_context():
            with current_app.test_request_context():
                self.test_message = {
                    'msg_id': 'test123',
                    'urn_to': 'richard',
                    'urn_from': 'respondent.richard',
                    'subject': 'MyMessage',
                    'body': 'hello',
                    'thread_id': '',
                    'collection_case': 'ACollectionCase',
                    'reporting_unit': 'AReportingUnit',
                    'survey': 'ACollectionInstrument'
                }

                modifier = Modifier()
                with self.engine.connect() as con:
                    add_draft = (
                        "INSERT INTO status (label, msg_id, actor) "
                        "VALUES ('{0}', 'test123', 'respondent.richard')"
                    ).format(Labels.DRAFT.value)
                    con.execute(add_draft)
                modifier.del_draft(self.test_message['msg_id'])

                with self.engine.connect() as con:
                    request = con.execute(
                        "SELECT * FROM status WHERE msg_id='{0}' AND actor='{1}'"
                        .format('test123', 'respondent.richard'))
                    for row in request:
                        self.assertTrue(row is None)
                        break
                    else:
                        pass
Example #3
0
 def modify_label(action, message, user_urn, label):
     """Adds or deletes a label"""
     label_exists = label in message
     if action == 'add' and not label_exists:
         return Modifier.add_label(label, message, user_urn)
     if label_exists:
         return Modifier.remove_label(label, message, user_urn)
     else:
         return False
Example #4
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 #5
0
 def test_unread_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, 'internal.21345')
             modifier = Modifier()
             modifier.del_unread(message, 'internal.21345')
             message = message_service.retrieve_message(
                 msg_id, 'internal.21345')
             self.assertCountEqual(message['labels'], ['INBOX'])
Example #6
0
 def test_archived_label_is_added_to_message(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()
             # pass msg_id and user urn
             message = message_service.retrieve_message(
                 msg_id, 'respondent.21345')
             Modifier.add_archived(
                 message,
                 'respondent.21345',
             )
             message = message_service.retrieve_message(
                 msg_id, 'respondent.21345')
             self.assertCountEqual(message['labels'], ['SENT', 'ARCHIVE'])
Example #7
0
 def modify_unread(action, message, user_urn):
     if action == 'add':
         return Modifier.add_unread(message, user_urn)
     return Modifier.del_unread(message, user_urn)
Example #8
0
 def del_draft_labels(draft_id):
     modifier = Modifier()
     modifier.del_draft(draft_id)