This repository has been archived by the owner on Sep 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
89 lines (70 loc) · 2.46 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
from django.conf import settings
from django.core.mail import EmailMessage
from django.test import SimpleTestCase as TestCase
from sgbackend import SendGridBackend
settings.configure(SENDGRID_API_KEY=os.environ.get('SENDGRID_API_KEY'))
RECIPIENT=os.environ.get('TEST_RECIPIENT', '[email protected]')
class Issue61Tests(TestCase):
def test_attachment_binary_type(self):
backend = SendGridBackend()
attachments = (
('file.txt', b'File content', 'text/plain'),
)
mail = EmailMessage(
subject='Email subject',
body='Email body',
from_email='[email protected]',
to=(RECIPIENT, ),
attachments=attachments,
)
# Replicate backend sending
prepared_mail = backend._build_sg_mail(mail)
# Send to SendGrid
response = backend.sg.client.mail.send.post(request_body=prepared_mail)
self.assertEqual(
response.status_code,
202
)
def test_attachment_string_type(self):
backend = SendGridBackend()
attachments = (
('file.txt', 'File content', 'text/plain'),
)
mail = EmailMessage(
subject='Email subject',
body='Email body',
from_email='[email protected]',
to=(RECIPIENT, ),
attachments=attachments,
)
# Replicate backend sending
prepared_mail = backend._build_sg_mail(mail)
# Send to SendGrid
response = backend.sg.client.mail.send.post(request_body=prepared_mail)
self.assertEqual(
response.status_code,
202
)
def test_attachment_image_type(self):
backend = SendGridBackend()
with open(os.path.join(os.path.dirname(__file__), 'octocat.png'), 'rb') as f:
img = f.read()
attachments = (
('octocat.png', img, 'image/png'),
)
mail = EmailMessage(
subject='Email subject',
body='Email body',
from_email='[email protected]',
to=(RECIPIENT, ),
attachments=attachments,
)
# Replicate backend sending
prepared_mail = backend._build_sg_mail(mail)
# Send to SendGrid
response = backend.sg.client.mail.send.post(request_body=prepared_mail)
self.assertEqual(
response.status_code,
202
)