Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fd6e106a
Commit
fd6e106a
authored
Aug 04, 2010
by
Richard Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve smtpd module test coverage
parent
989a249c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
5 deletions
+83
-5
Lib/test/test_smtpd.py
Lib/test/test_smtpd.py
+83
-5
No files found.
Lib/test/test_smtpd.py
View file @
fd6e106a
...
...
@@ -7,8 +7,8 @@ import asyncore
class
DummyServer
(
smtpd
.
SMTPServer
):
def
__init__
(
self
,
*
args
):
smtpd
.
SMTPServer
.
__init__
(
self
,
*
args
)
def
__init__
(
self
,
localaddr
,
remoteaddr
):
smtpd
.
SMTPServer
.
__init__
(
self
,
localaddr
,
remoteaddr
)
self
.
messages
=
[]
def
process_message
(
self
,
peer
,
mailfrom
,
rcpttos
,
data
):
...
...
@@ -16,13 +16,38 @@ class DummyServer(smtpd.SMTPServer):
if
data
==
'return status'
:
return
'250 Okish'
class
DummyDispatcherBroken
(
Exception
):
pass
class
BrokenDummyServer
(
DummyServer
):
def
listen
(
self
,
num
):
raise
DummyDispatcherBroken
()
class
SMTPDServerTest
(
TestCase
):
def
setUp
(
self
):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
def
test_process_message_unimplemented
(
self
):
server
=
smtpd
.
SMTPServer
(
'a'
,
'b'
)
conn
,
addr
=
server
.
accept
()
channel
=
smtpd
.
SMTPChannel
(
server
,
conn
,
addr
)
def
write_line
(
line
):
channel
.
socket
.
queue_recv
(
line
)
channel
.
handle_read
()
write_line
(
b'MAIL From:eggs@example'
)
write_line
(
b'RCPT To:spam@example'
)
write_line
(
b'DATA'
)
self
.
assertRaises
(
NotImplementedError
,
write_line
,
b'spam
\
r
\
n
.
\
r
\
n
'
)
def
tearDown
(
self
):
asyncore
.
socket
=
smtpd
.
socket
=
socket
class
SMTPDChannelTest
(
TestCase
):
def
setUp
(
self
):
smtpd
.
socket
=
asyncore
.
socket
=
mock_socket
...
...
@@ -142,8 +167,8 @@ class SMTPDChannelTest(TestCase):
b'354 End data with <CR><LF>.<CR><LF>
\
r
\
n
'
)
self
.
write_line
(
b'data
\
r
\
n
more
\
r
\
n
.'
)
self
.
assertEqual
(
self
.
channel
.
socket
.
last
,
b'250 Ok
\
r
\
n
'
)
self
.
assertEqual
(
self
.
server
.
messages
[
-
1
]
,
(
'peer'
,
'eggs@example'
,
[
'spam@example'
],
'data
\
n
more'
)
)
self
.
assertEqual
(
self
.
server
.
messages
,
[(
'peer'
,
'eggs@example'
,
[
'spam@example'
],
'data
\
n
more'
)]
)
def
test_DATA_syntax
(
self
):
self
.
write_line
(
b'MAIL From:eggs@example'
)
...
...
@@ -151,6 +176,13 @@ class SMTPDChannelTest(TestCase):
self
.
write_line
(
b'DATA spam'
)
self
.
assertEqual
(
self
.
channel
.
socket
.
last
,
b'501 Syntax: DATA
\
r
\
n
'
)
def
test_data_transparency_section_4_5_2
(
self
):
self
.
write_line
(
b'MAIL From:eggs@example'
)
self
.
write_line
(
b'RCPT To:spam@example'
)
self
.
write_line
(
b'DATA'
)
self
.
write_line
(
b'..
\
r
\
n
.
\
r
\
n
'
)
self
.
assertEqual
(
self
.
channel
.
received_data
,
'.'
)
def
test_multiple_RCPT
(
self
):
self
.
write_line
(
b'MAIL From:eggs@example'
)
self
.
write_line
(
b'RCPT To:spam@example'
)
...
...
@@ -161,6 +193,7 @@ class SMTPDChannelTest(TestCase):
(
'peer'
,
'eggs@example'
,
[
'spam@example'
,
'ham@example'
],
'data'
))
def
test_manual_status
(
self
):
# checks that the Channel is able to return a custom status message
self
.
write_line
(
b'MAIL From:eggs@example'
)
self
.
write_line
(
b'RCPT To:spam@example'
)
self
.
write_line
(
b'DATA'
)
...
...
@@ -183,9 +216,54 @@ class SMTPDChannelTest(TestCase):
self
.
write_line
(
b'RSET hi'
)
self
.
assertEqual
(
self
.
channel
.
socket
.
last
,
b'501 Syntax: RSET
\
r
\
n
'
)
def
test_attribute_deprecations
(
self
):
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__server
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__server
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__line
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__line
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__state
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__state
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__greeting
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__greeting
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__mailfrom
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__mailfrom
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__rcpttos
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__rcpttos
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__data
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__data
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__fqdn
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__fqdn
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__peer
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__peer
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__conn
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__conn
=
'spam'
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
spam
=
self
.
channel
.
_SMTPChannel__addr
with
support
.
check_warnings
((
''
,
PendingDeprecationWarning
)):
self
.
channel
.
_SMTPChannel__addr
=
'spam'
def
test_main
():
support
.
run_unittest
(
SMTPDChannelTest
)
support
.
run_unittest
(
SMTPD
ServerTest
,
SMTPD
ChannelTest
)
if
__name__
==
"__main__"
:
test_main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment