Пример #1
0
    def test_email_notifier__build_name_with_no_user(self):
        config = CFG.get_instance()
        config.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = 'Robot'
        config.EMAIL_NOTIFICATION_FROM_EMAIL = '*****@*****.**'

        notifier = EmailNotifier(smtp_config=None, global_config=config)
        email = notifier._get_sender()
        eq_('Robot <*****@*****.**>', email)
Пример #2
0
    def test_email_notifier__build_name_with_no_user(self):
        config = CFG.get_instance()
        config.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = 'Robot'
        config.EMAIL_NOTIFICATION_FROM_EMAIL = '*****@*****.**'

        notifier = EmailNotifier(smtp_config=None, global_config=config)
        email = notifier._get_sender()
        eq_('Robot <*****@*****.**>', email)
Пример #3
0
    def test_email_notifier__build_name_without_user_id(self):
        u = User()
        u.user_id = 3
        u.display_name = 'François Michâlié'

        config = CFG.get_instance()
        config.EMAIL_NOTIFICATION_FROM_EMAIL = '*****@*****.**'

        notifier = EmailNotifier(smtp_config=None, global_config=config)
        email = notifier._get_sender(user=u)
        eq_('=?utf-8?q?Fran=C3=A7ois_Mich=C3=A2li=C3=A9_via_Tracim?= <*****@*****.**>', email)  # nopep8
Пример #4
0
 def send_mail(self, message: MIMEMultipart):
     if not self._is_active:
         log = 'Not sending email to {} (service disabled)'
         logger.info(self, log.format(message['To']))
     else:
         self.connect()  # Actually, this connects to SMTP only if required
         logger.info(self, 'Sending email to {}'.format(message['To']))
         self._smtp_connection.send_message(message)
         from tracim.lib.notifications import EmailNotifier
         EmailNotifier.log_notification(
             action='   SENT',
             recipient=message['To'],
             subject=message['Subject'],
         )
Пример #5
0
 def send_mail(self, message: MIMEMultipart):
     if not self._is_active:
         log = 'Not sending email to {} (service disabled)'
         logger.info(self, log.format(message['To']))
     else:
         self.connect()  # Actually, this connects to SMTP only if required
         logger.info(self, 'Sending email to {}'.format(message['To']))
         self._smtp_connection.send_message(message)
         from tracim.lib.notifications import EmailNotifier
         EmailNotifier.log_notification(
             action='   SENT',
             recipient=message['To'],
             subject=message['Subject'],
         )
Пример #6
0
 def test_unit__log_notification(self):
     """Check file and format of notification log."""
     log_path = CFG.get_instance().EMAIL_NOTIFICATION_LOG_FILE_PATH
     pattern = '\|{act}\|{rec}\|{subj}$\\n'
     line_1_act = 'CREATED'
     line_1_rec = 'user 1 <*****@*****.**>'
     line_1_subj = 'notification 1'
     line_1_pattern = pattern.format(
         act=line_1_act,
         rec=line_1_rec,
         subj=line_1_subj,
     )
     line_2_act = '   SENT'
     line_2_rec = 'user 2 <*****@*****.**>'
     line_2_subj = 'notification 2'
     line_2_pattern = pattern.format(
         act=line_2_act,
         rec=line_2_rec,
         subj=line_2_subj,
     )
     EmailNotifier.log_notification(
         action=line_1_act,
         recipient=line_1_rec,
         subject=line_1_subj,
     )
     EmailNotifier.log_notification(
         action=line_2_act,
         recipient=line_2_rec,
         subject=line_2_subj,
     )
     with open(log_path, 'rt') as log_file:
         line_1 = log_file.readline()
         line_2 = log_file.readline()
     os.remove(path=log_path)
     ok_(re.search(pattern=line_1_pattern, string=line_1))
     ok_(re.search(pattern=line_2_pattern, string=line_2))