| 1 |
import asyncio |
| 2 |
import sys |
| 3 |
|
| 4 |
|
| 5 |
async def test_command_line_send(hostname: str, smtpd_server_port: int) -> None: |
| 6 |
proc = await asyncio.create_subprocess_exec( |
| 7 |
sys.executable, |
| 8 |
b"-m", |
| 9 |
b"aiosmtplib", |
| 10 |
stdin=asyncio.subprocess.PIPE, |
| 11 |
stdout=asyncio.subprocess.PIPE, |
| 12 |
) |
| 13 |
|
| 14 |
inputs = ( |
| 15 |
bytes(hostname, "ascii"), |
| 16 |
bytes(str(smtpd_server_port), "ascii"), |
| 17 |
b"[email protected]", |
| 18 |
b"[email protected]", |
| 19 |
b"Subject: Hello World\n\nHi there.", |
| 20 |
) |
| 21 |
messages = ( |
| 22 |
b"SMTP server hostname [localhost]:", |
| 23 |
b"SMTP server port [25]:", |
| 24 |
b"From:", |
| 25 |
b"To:", |
| 26 |
b"Enter message, end with ^D:", |
| 27 |
) |
| 28 |
|
| 29 |
output, errors = await proc.communicate(input=b"\n".join(inputs)) |
| 30 |
|
| 31 |
assert errors is None |
| 32 |
for message in messages: |
| 33 |
assert message in output |
| 34 |
|
| 35 |
assert proc.returncode == 0 |