-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_dj_email_url.py
169 lines (137 loc) · 6.05 KB
/
test_dj_email_url.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2013-2022 Miguel Gonzalez <[email protected]>
#
# SPDX-License-Identifier: BSD-2-Clause
# -*- coding: utf-8 -*-
import os
import unittest
import dj_email_url
class EmailTestSuite(unittest.TestCase):
def test_smtps_parsing(self):
url = 'smtps://[email protected]:[email protected]:587'
url = dj_email_url.parse(url)
assert url['EMAIL_BACKEND'] == \
'django.core.mail.backends.smtp.EmailBackend'
assert url['EMAIL_HOST'] == 'smtp.example.com'
assert url['EMAIL_HOST_PASSWORD'] == 'password'
assert url['EMAIL_HOST_USER'] == '[email protected]'
assert url['EMAIL_PORT'] == 587
assert url['EMAIL_USE_TLS'] is True
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_TIMEOUT'] is None
def test_console_parsing(self):
url = 'console://'
url = dj_email_url.parse(url)
assert url['EMAIL_BACKEND'] == \
'django.core.mail.backends.console.EmailBackend'
assert url['EMAIL_HOST'] is None
assert url['EMAIL_HOST_PASSWORD'] is None
assert url['EMAIL_HOST_USER'] is None
assert url['EMAIL_PORT'] is None
assert url['EMAIL_USE_TLS'] is False
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_TIMEOUT'] is None
def test_email_url(self):
a = dj_email_url.config()
assert not a
os.environ['EMAIL_URL'] = \
'smtps://[email protected]:[email protected]:587'
url = dj_email_url.config()
assert url['EMAIL_BACKEND'] == \
'django.core.mail.backends.smtp.EmailBackend'
assert url['EMAIL_HOST'] == 'smtp.example.com'
assert url['EMAIL_HOST_PASSWORD'] == 'password'
assert url['EMAIL_HOST_USER'] == '[email protected]'
assert url['EMAIL_PORT'] == 587
assert url['EMAIL_USE_TLS'] is True
assert url['EMAIL_USE_SSL'] is False
def test_smtp_backend_smtp_scheme_default_port(self):
url = 'smtp://[email protected]:[email protected]'
url = dj_email_url.parse(url)
assert url['EMAIL_PORT'] == 25
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is False
def test_smtp_backend_submit_scheme_default_port(self):
# Included in README
url = 'submit://[email protected]:[email protected]'
url = dj_email_url.parse(url)
assert url['EMAIL_PORT'] == 587
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is True
def test_smtp_backend_submission_scheme_default_port(self):
# Included in README
url = 'submission://[email protected]:[email protected]'
url = dj_email_url.parse(url)
assert url['EMAIL_PORT'] == 587
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is True
def test_smtp_backend_with_smtp_over_ssl(self):
url = 'smtp://[email protected]:[email protected]:465/?ssl=True'
url = dj_email_url.parse(url)
assert url['EMAIL_PORT'] == 465
assert url['EMAIL_USE_SSL'] is True
assert url['EMAIL_USE_TLS'] is False
def test_smtp_backend_local_mta(self):
# Included in README
url = 'smtp://'
url = dj_email_url.parse(url)
assert url['EMAIL_HOST'] == 'localhost'
assert url['EMAIL_PORT'] == 25
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is False
def test_smtp_backend_without_ssl(self):
url = 'smtp://[email protected]:[email protected]:465/?ssl=False'
url = dj_email_url.parse(url)
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is False
def test_smtps_backend_with_ssl(self):
url = 'smtps://[email protected]:[email protected]:465/?ssl=True'
url = dj_email_url.parse(url)
assert url['EMAIL_USE_SSL'] is True
assert url['EMAIL_USE_TLS'] is False
def test_smtp_backend_with_tls(self):
url = 'smtp://[email protected]:[email protected]:587/?tls=True'
url = dj_email_url.parse(url)
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is True
def test_smtp_backend_without_tls(self):
url = 'smtp://[email protected]:[email protected]:587/?tls=False'
url = dj_email_url.parse(url)
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is False
def test_smtp_backend_with_timeout(self):
url = 'smtp://[email protected]:[email protected]:587/?timeout=10'
url = dj_email_url.parse(url)
assert url['EMAIL_TIMEOUT'] == 10
def test_special_chars(self):
url = 'smtp://user%21%40%23%245678:pass%25%5E%26%2A%28%29123@' \
'smtp.example.com:587'
url = dj_email_url.parse(url)
assert url['EMAIL_HOST_PASSWORD'] == 'pass%^&*()123'
assert url['EMAIL_HOST_USER'] == 'user!@#$5678'
def test_file_path(self):
url = 'smtp://[email protected]:[email protected]:587' \
'//tmp/app-messages?tls=True'
url = dj_email_url.parse(url)
assert url['EMAIL_FILE_PATH'] == "/tmp/app-messages"
assert url['EMAIL_USE_SSL'] is False
assert url['EMAIL_USE_TLS'] is True
class EmailExtraParamsTestSuite(unittest.TestCase):
def test_server_email_undefined(self):
url = 'console:'
url = dj_email_url.parse(url)
assert 'SERVER_EMAIL' not in url
def test_server_email_parsed(self):
url = 'console://[email protected]'
url = dj_email_url.parse(url)
assert url['SERVER_EMAIL'] == '[email protected]'
def test_default_from_email_undefined(self):
url = 'console:'
url = dj_email_url.parse(url)
assert 'DEFAULT_FROM_EMAIL' not in url
def test_default_from_email_parsed(self):
url = 'console://[email protected]'
url = dj_email_url.parse(url)
assert url['DEFAULT_FROM_EMAIL'] == '[email protected]'
if __name__ == '__main__': # pragma: no cover
unittest.main()