Ejemplo n.º 1
0
 def test_send_smtp_called(self):
     '''
     swap IMG `src` by cid when `_content_html_file` is set
     '''
     with mock.patch('pyhtmlmail.mail.EmailMsg.smtp') as smtp_patched:
         emsg = EmailMsg()  # I believe this make one call to setter
         emsg.send()
         emsg.content_html_file = self.temp_file_path
         smtp_patched.assert_called()
Ejemplo n.º 2
0
 def test_mailtolistfile_setter_is_called(self):
     '''
     Check mailtolistfile SETTER is called when mailtolistfile is set
     '''
     with mock.patch(
             'pyhtmlmail.mail.EmailMsg.mailtolistfile',
             new_callable=mock.PropertyMock) as mailtolistfile_patched:
         emsg = EmailMsg()
         mailtolistfile_patched.reset_mock()
         emsg.mailtolistfile = 'temp.txt'
         mailtolistfile_patched.assert_called()
Ejemplo n.º 3
0
 def test_content_html_setter_is_called(self):
     '''
     swap IMG `src` by cid when `_content_html_file` is set
     '''
     with mock.patch(
             'pyhtmlmail.mail.EmailMsg.content_html',
             new_callable=mock.PropertyMock) as content_html_patched:
         emsg = EmailMsg()  # I believe this make one call to setter
         content_html_patched.reset_mock(
         )  # ... so  <<<< todo: check TRICKY! ?!?!
         emsg.content_html_file = self.temp_file_path
         content_html_patched.assert_called()
Ejemplo n.º 4
0
 def test_content_html_parsed_on_set_content_html_file(self):
     '''Check images parsed when `content_html_file` is set'''
     em = EmailMsg()
     em.content_html_file = self.temp_file_path
     images = [
         'pyhtmlmail/images/feliz_aniversario_cartao.png',
         'pyhtmlmail/images/feliz_aniversario_code.png'
     ]
     check = [img for cid, img in em._images_cids]
     self.assertTrue(
         all([
             images[0] in check, images[1] in check,
             len(em._images_cids) == 2
         ]))
Ejemplo n.º 5
0
 def test_content_html_parsed_on_set_content_html(self):
     '''
     Check images parsed when `content_html` is set
     '''
     em = EmailMsg()
     em.content_html = CONTENT_HTML
     images = [
         'pyhtmlmail/images/feliz_aniversario_cartao.png',
         'pyhtmlmail/images/feliz_aniversario_code.png'
     ]
     check = [img for cid, img in em._images_cids]
     # self.assertIn(images[0], check)
     # self.assertIn(images[1], check)
     # self.assertEqual(len(em._images_cids), 2)
     self.assertTrue(
         all([
             images[0] in check, images[1] in check,
             len(em._images_cids) == 2
         ]))
Ejemplo n.º 6
0
    def test_recipients_list_file_parser(self):
        '''
        Recipients list read from file

        # csv File ...
            [email protected]
            [email protected]
            ...
            [email protected]
        '''
        temp_csv_file = path.join(self.temp_dir, 'temp_addresses.csv')
        with open(temp_csv_file, mode='w') as csv_file:
            csv_writer = csv.writer(csv_file, delimiter=' ', quotechar='"')
            for item in RECIPENTS_LIST:
                csv_writer.writerow([
                    item,
                ])  # csv writer, writes lists
        em = EmailMsg()
        em.mailtolistfile = temp_csv_file
        self.assertListEqual(em.to_recipient, RECIPENTS_LIST)
Ejemplo n.º 7
0
def main(sys_args):

    args = command_line_parser(sys_args)
    email = EmailMsg()
    email.host = args.host
    email.port = args.port
    email.from_sender = args.mailfrom
    email.to_recipient = args.mailto
    email.subject = args.subject
    email.password = args.password
    email.content_html = args.contenthtml  # args.content_html
    email.content_text = args.contenttext  # args.content_text
    email.content_html_file = args.contenthtmlfile

    email.send()
Ejemplo n.º 8
0
 def test_instantiate(self):
     '''
     Instance is initialize correctly
     '''
     em = EmailMsg()
     self.assertIsInstance(em._msg, MIMEMultipart)