File tree Expand file tree Collapse file tree 2 files changed +22
-16
lines changed Expand file tree Collapse file tree 2 files changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -45,9 +45,14 @@ def __init__(self, message):
45
45
)
46
46
47
47
if message .attachments :
48
- raise UnsupportedContent (
49
- 'The SparkPost Django email backend does not '
50
- 'currently support attachment.'
51
- )
48
+ formatted ['attachments' ] = []
49
+ for attachment in message .attachments :
50
+ filename , content , mimetype = attachment
51
+ formatted ['attachments' ].append ({
52
+ 'name' : filename ,
53
+ 'data' : content ,
54
+ 'type' : mimetype
55
+ })
56
+ print (message .attachments )
52
57
53
58
return super (SparkPostMessage , self ).__init__ (formatted )
Original file line number Diff line number Diff line change 1
- try :
2
- from StringIO import StringIO
3
- except ImportError :
4
- from io import StringIO
5
-
6
- import pytest
7
1
from django .core .mail import EmailMultiAlternatives
8
2
from django .core .mail .message import EmailMessage
9
3
10
- from sparkpost .django .exceptions import UnsupportedContent
11
4
from sparkpost .django .message import SparkPostMessage
12
5
from .utils import at_least_version
13
6
@@ -66,13 +59,21 @@ def test_cc_bcc():
66
59
67
60
68
61
def test_attachment ():
69
- attachment = StringIO ()
70
- attachment .write ('hello file' )
71
62
email_message = EmailMessage (** base_options )
72
- email_message .attach ('file.txt' , attachment , 'text/plain' )
63
+ email_message .attach ('file.txt' , 'test content' , 'text/plain' )
73
64
74
- with pytest .raises (UnsupportedContent ):
75
- SparkPostMessage (email_message )
65
+ actual = SparkPostMessage (email_message )
66
+ expected = dict (
67
+ attachments = [
68
+ {
69
+ 'name' : 'file.txt' ,
70
+ 'data' : 'test content' ,
71
+ 'type' : 'text/plain'
72
+ }
73
+ ]
74
+ )
75
+ expected .update (base_expected )
76
+ assert actual == expected
76
77
77
78
if at_least_version ('1.8' ):
78
79
def test_reply_to ():
You can’t perform that action at this time.
0 commit comments