Exemplo n.º 1
0
    def test_add_attachments_path_wrong_dict_data(self):
        # Setup
        service = BaseEmailService()
        service.template_name = 'test_email.html'
        msg_obj = service._build_mail_object()

        filename = 'awesome_file.txt'
        service.attachment_list = [{'filename': filename}]

        with self.assertRaises(EmailServiceAttachmentError):
            service._add_attachments(msg_obj)
Exemplo n.º 2
0
    def test_add_attachments_path_as_str(self):
        # Setup
        service = BaseEmailService()
        service.template_name = 'test_email.html'
        msg_obj = service._build_mail_object()

        file_path = settings.BASE_PATH / 'tests/files/testfile.txt'
        service.attachment_list = [file_path]
        msg_obj = service._add_attachments(msg_obj)

        self.assertEqual(len(msg_obj.attachments), 1)
        self.assertEqual(msg_obj.attachments[0][0], basename(file_path))
Exemplo n.º 3
0
    def test_add_attachments_path_as_dict(self):
        # Setup
        service = BaseEmailService()
        service.template_name = 'test_email.html'
        msg_obj = service._build_mail_object()

        filename = 'awesome_file.txt'
        file_path = settings.BASE_PATH / 'tests/files/testfile.txt'
        service.attachment_list = [{
            'filename': filename,
            'file': file_path,
            'mimetype': 'text/text'
        }]
        msg_obj = service._add_attachments(msg_obj)

        self.assertEqual(len(msg_obj.attachments), 1)
        self.assertEqual(msg_obj.attachments[0][0], filename)