Skip to content

Commit

Permalink
Add test for error after connection timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed May 16, 2019
1 parent b2119be commit f90ff25
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/test_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import pytest

from aiosmtplib import SMTP, SMTPConnectTimeoutError, SMTPTimeoutError
from aiosmtplib import (
SMTP,
SMTPConnectTimeoutError,
SMTPServerDisconnected,
SMTPTimeoutError,
)
from aiosmtplib.protocol import SMTPProtocol


Expand Down Expand Up @@ -125,3 +130,13 @@ async def test_connect_timeout_error(hostname, port):
host=hostname, port=port
)
assert str(exc.value) == expected_message


async def test_server_disconnected_error_after_connect_timeout(hostname, port, message):
client = SMTP(hostname=hostname, port=port)

with pytest.raises(SMTPConnectTimeoutError):
await client.connect(timeout=0.0)

with pytest.raises(SMTPServerDisconnected):
await client.sendmail(message["From"], [message["To"]], str(message))

0 comments on commit f90ff25

Please sign in to comment.