4
4
5
5
6
6
class IsEmailTestCase (TestCase ):
7
+ """
8
+ Definitions:
9
+
10
+ "head" -> the part before "@"
11
+ "tail" -> the part after "@"
12
+ """
13
+
7
14
def test_should_return_false_for_non_string_objects (self ):
8
15
# noinspection PyTypeChecker
9
16
self .assertFalse (is_email (None ))
@@ -24,10 +31,10 @@ def test_string_cannot_be_empty(self):
24
31
self .assertFalse (is_email ('' ))
25
32
self .assertFalse (is_email (' ' ))
26
33
27
- def test_domain_part_is_required (self ):
34
+ def test_tail_is_required (self ):
28
35
self .assertFalse (is_email ('name@' ))
29
36
30
- def test_name_part_is_required (self ):
37
+ def test_head_is_required (self ):
31
38
self .assertFalse (is_email ('@foo.com' ))
32
39
33
40
def test_at_sign_is_required (self ):
@@ -44,19 +51,19 @@ def test_domain_extension_should_be_letters_only_from_2_to_4_chars(self):
44
51
self .assertFalse (is_email ('me@foo.___' ))
45
52
self .
assertFalse (
is_email (
'[email protected] ' ))
46
53
47
- def test_name_part_cannot_contain_suqare_brackets (self ):
54
+ def test_head_cannot_contain_suqare_brackets (self ):
48
55
self .
assertFalse (
is_email (
'[[email protected] ' ))
49
56
self .
assertFalse (
is_email (
'my][email protected] ' ))
50
57
51
- def test_domain_part_cannot_contain_bad_signs (self ):
58
+ def test_tail_cannot_contain_bad_signs (self ):
52
59
self .assertFalse (is_email ('me@#foo#.com' ))
53
60
self .assertFalse (is_email ('me@foo!.com' ))
54
61
self .assertFalse (is_email ('someone@[foo].com' ))
55
62
56
- def test_domain_part_cannot_be_uppercase (self ):
63
+ def test_tail_cannot_be_uppercase (self ):
57
64
self .
assertFalse (
is_email (
'[email protected] ' ))
58
65
59
- def test_domain_part_cannot_contain_dots_sequence (self ):
66
+ def test_tail_cannot_contain_dots_sequence (self ):
60
67
self .
assertFalse (
is_email (
'[email protected] ' ))
61
68
self .
assertFalse (
is_email (
'[email protected] ' ))
62
69
@@ -77,79 +84,124 @@ def test_max_email_length_is_respected(self):
77
84
invalid_email = ('a' * 320 ) + '@gmail.com'
78
85
self .assertFalse (is_email (invalid_email ))
79
86
80
- def test_local_part_length_is_respected (self ):
81
- # max local part is 64 (before "@")
87
+ def test_head_length_is_respected (self ):
88
+ # max head size is 64
82
89
invalid_email = ('a' * 65 ) + '@gmail.com'
83
90
self .assertFalse (is_email (invalid_email ))
84
91
85
- def test_octects_part_length_is_respected (self ):
86
- # max octets part is 255 (after "@")
92
+ def test_tail_length_is_respected (self ):
93
+ # max tail size is 255
87
94
invalid_email = 'a@{}.com' .format (255 * 'x' )
88
95
self .assertFalse (is_email (invalid_email ))
89
96
90
- def test_plus_is_valid_char_in_local_part (self ):
91
- self .
assertTrue (
is_email (
"[email protected] " ))
97
+ def test_plus_is_valid_char_in_head (self ):
98
+ self .
assertTrue (
is_email (
'[email protected] ' ))
99
+
100
+ def test_plus_is_invalid_char_in_tail (self ):
101
+ self .assertFalse (is_email ('mymail@foo+bar.com' ))
102
+
103
+ def test_minus_is_valid_char_in_head (self ):
104
+ self .
assertTrue (
is_email (
'[email protected] ' ))
105
+
106
+ def test_slash_is_valid_char_in_head (self ):
107
+ self .
assertTrue (
is_email (
'my/[email protected] ' ))
108
+
109
+ def test_slash_is_invalid_char_in_tail (self ):
110
+ self .assertFalse (is_email ('mymail@foo/bar.com' ))
111
+
112
+ def test_back_slash_is_valid_char_in_head (self ):
113
+ self .
assertTrue (
is_email (
'my\\ [email protected] ' ))
114
+
115
+ def test_equal_is_valid_char_in_head (self ):
116
+ self .
assertTrue (
is_email (
'[email protected] ' ))
117
+
118
+ def test_equal_is_invalid_char_in_tail (self ):
119
+ self .assertFalse (is_email ('mymail@gm=ail.com' ))
92
120
93
- def test_minus_is_valid_char_in_local_part (self ):
94
- self .
assertTrue (
is_email (
"my- [email protected] " ))
121
+ def test_question_mark_is_valid_char_in_head (self ):
122
+ self .
assertTrue (
is_email (
'my? [email protected] ' ))
95
123
96
- def test_slash_is_valid_char_in_local_part (self ):
97
- self .assertTrue (is_email ("my/mail@gmail .com" ))
124
+ def test_question_mark_is_invalid_char_in_tail (self ):
125
+ self .assertFalse (is_email ('mymail@gm?ail .com' ))
98
126
99
- def test_back_slash_is_valid_char_in_local_part (self ):
100
- self .
assertTrue (
is_email (
"my \\ [email protected] " ))
127
+ def test_sharp_is_valid_char_in_head (self ):
128
+ self .
assertTrue (
is_email (
'my# [email protected] ' ))
101
129
102
- def test_equal_is_valid_char_in_local_part (self ):
103
- self .assertTrue (is_email ("my=mail@gmail .com" ))
130
+ def test_sharp_is_invalid_char_in_tail (self ):
131
+ self .assertFalse (is_email ('mymail@gma#il .com' ))
104
132
105
- def test_question_mark_is_valid_char_in_local_part (self ):
106
- self .
assertTrue (
is_email (
"my? [email protected] " ))
133
+ def test_dollar_is_valid_char_in_head (self ):
134
+ self .
assertTrue (
is_email (
'my$ [email protected] ' ))
107
135
108
- def test_sharp_is_valid_char_in_local_part (self ):
109
- self .assertTrue (is_email ("my#mail@gmail .com" ))
136
+ def test_dollar_is_invalid_char_in_tail (self ):
137
+ self .assertFalse (is_email ('mymail@gm$ail .com' ))
110
138
111
- def test_dollar_is_valid_char_in_local_part (self ):
112
- self .
assertTrue (
is_email (
"my$ [email protected] " ))
139
+ def test_and_is_valid_char_in_head (self ):
140
+ self .
assertTrue (
is_email (
'my& [email protected] ' ))
113
141
114
- def test_and_is_valid_char_in_local_part (self ):
115
- self .assertTrue (is_email ("my&mail@gmail .com" ))
142
+ def test_and_is_invalid_char_in_tail (self ):
143
+ self .assertFalse (is_email ('mymail@gm&ail .com' ))
116
144
117
- def test_asterisk_is_valid_char_in_local_part (self ):
118
- self .
assertTrue (
is_email (
" my*[email protected] " ))
145
+ def test_asterisk_is_valid_char_in_head (self ):
146
+ self .
assertTrue (
is_email (
' my*[email protected] ' ))
119
147
120
- def test_apostrophe_is_valid_char_in_local_part (self ):
121
- self .assertTrue (is_email ("my'mail@gmail .com" ))
148
+ def test_asterisk_is_invalid_char_in_tail (self ):
149
+ self .assertFalse (is_email ('mymail@gmai*l .com' ))
122
150
123
- def test_acute_accent_is_valid_char_in_local_part (self ):
124
- self .
assertTrue (
is_email (
"my` [email protected] " ))
151
+ def test_apostrophe_is_valid_char_in_head (self ):
152
+ self .
assertTrue (
is_email (
'my \' [email protected] ' ))
125
153
126
- def test_percentage_is_valid_char_in_local_part (self ):
127
- self .assertTrue (is_email ("my%mail@gmail .com" ))
154
+ def test_apostrophe_is_invalid_char_in_tail (self ):
155
+ self .assertFalse (is_email ('mymail@gma \' il .com' ))
128
156
129
- def test_exclamation_mark_is_valid_char_in_local_part (self ):
130
- self .
assertTrue (
is_email (
"my! [email protected] " ))
157
+ def test_acute_accent_is_valid_char_in_head (self ):
158
+ self .
assertTrue (
is_email (
'my` [email protected] ' ))
131
159
132
- def test_caret_is_valid_char_in_local_part (self ):
133
- self .assertTrue (is_email ("my^mail@gmail .com" ))
160
+ def test_acute_accent_is_invalid_char_in_tail (self ):
161
+ self .assertFalse (is_email ('mymail@gma`il .com' ))
134
162
135
- def test_pipe_is_valid_char_in_local_part (self ):
136
- self .
assertTrue (
is_email (
"my| [email protected] " ))
163
+ def test_percentage_is_valid_char_in_head (self ):
164
+ self .
assertTrue (
is_email (
'my% [email protected] ' ))
137
165
138
- def test_tilde_is_valid_char_in_local_part (self ):
139
- self .assertTrue (is_email ("my~mail@gmail .com" ))
166
+ def test_percentage_is_invalid_char_in_tail (self ):
167
+ self .assertFalse (is_email ('mymail@gma%il .com' ))
140
168
141
- def test_curly_braces_are_valid_char_in_local_part (self ):
142
- self .
assertTrue (
is_email (
"my{[email protected] " ))
143
- self .
assertTrue (
is_email (
"my}[email protected] " ))
144
- self .assertTrue (is_email ("{mymail}@gmail.com" ))
169
+ def test_exclamation_mark_is_valid_char_in_head (self ):
170
+ self .
assertTrue (
is_email (
'[email protected] ' ))
145
171
146
- def test_local_part_cannot_start_with_period (self ):
172
+ def test_exclamation_mark_is_invalid_char_in_tail (self ):
173
+ self .assertFalse (is_email ('mymail@gm!ail.com' ))
174
+
175
+ def test_caret_is_valid_char_in_head (self ):
176
+ self .
assertTrue (
is_email (
'my^[email protected] ' ))
177
+
178
+ def test_caret_is_invalid_char_in_tail (self ):
179
+ self .assertFalse (is_email ('mymail@gma^il.com' ))
180
+
181
+ def test_pipe_is_valid_char_in_head (self ):
182
+ self .
assertTrue (
is_email (
'my|[email protected] ' ))
183
+
184
+ def test_pipe_is_invalid_char_in_tail (self ):
185
+ self .assertFalse (is_email ('mymail@gm|ail.com' ))
186
+
187
+ def test_tilde_is_valid_char_in_head (self ):
188
+ self .
assertTrue (
is_email (
'[email protected] ' ))
189
+
190
+ def test_tilde_is_invalid_char_in_tail (self ):
191
+ self .assertFalse (is_email ('mymail@gma~il.com' ))
192
+
193
+ def test_curly_braces_are_valid_char_in_head (self ):
194
+ self .
assertTrue (
is_email (
'my{[email protected] ' ))
195
+ self .
assertTrue (
is_email (
'my}[email protected] ' ))
196
+ self .assertTrue (is_email ('{mymail}@gmail.com' ))
197
+
198
+ def test_head_cannot_start_with_period (self ):
147
199
self .
assertFalse (
is_email (
'[email protected] ' ))
148
200
149
- def test_local_part_cannot_end_with_period (self ):
201
+ def test_head_cannot_end_with_period (self ):
150
202
self .
assertFalse (
is_email (
'[email protected] ' ))
151
203
152
- def test_local_part_cannot_have_multiple_consecutive_periods (self ):
204
+ def test_head_cannot_have_multiple_consecutive_periods (self ):
153
205
self .
assertFalse (
is_email (
'[email protected] ' ))
154
206
self .
assertFalse (
is_email (
'[email protected] ' ))
155
207
@@ -158,14 +210,21 @@ def test_empty_spaces_are_allowed_only_if_escaped(self):
158
210
self .
assertTrue (
is_email (
'my\\ [email protected] ' ))
159
211
self .assertTrue (is_email ('"my mail"@gmail.com' ))
160
212
161
- def test_local_part_can_be_quoted (self ):
213
+ def test_head_can_be_quoted (self ):
162
214
self .assertTrue (is_email ('"foo"@example.com' ))
163
215
216
+ def test_head_quotes_must_be_correct (self ):
217
+ self .
assertFalse (
is_email (
'"[email protected] ' ))
218
+ self .
assertFalse (
is_email (
'no"[email protected] ' ))
219
+ self .assertFalse (is_email ('nope"@gmail.com' ))
220
+ self .assertFalse (is_email ('""@gmail.com' ))
221
+ self .assertFalse (is_email ('"no"pe"@gmail.com' ))
222
+
164
223
def test_with_quoted_string_multiple_at_are_accepted (self ):
165
224
self .assertTrue (is_email ('"Abc@def"@example.com' ))
166
225
167
226
def test_with_escape_multiple_at_are_accepted (self ):
168
227
self .
assertTrue (
is_email (
'Abc\\ @[email protected] ' ))
169
228
170
- def test_local_part_can_have_self_escape (self ):
229
+ def test_head_can_have_self_escape (self ):
171
230
self .
assertTrue (
is_email (
'Joe.\\ \\ [email protected] ' ))
0 commit comments