Files
slic/tests/test_utils_sendsms.py
T
tligui_y 12b39428c1
Run CI Tests / test (push) Successful in 1m40s
Add tests/test_utils_sendsms.py
2025-08-12 23:07:03 +02:00

41 lines
1.1 KiB
Python

import os
import getpass
import time
import glob
from slic.utils.sendsms import sendsms, SMS_GATEWAY_ADDRESS
def test_sendsms_local_delivery():
# Fake phone number
phone_number = "+41000000000"
text = "Hello from sendsms test"
# Path to Maildir 'new'
maildir_new = os.path.expanduser("~/Maildir/new")
os.makedirs(maildir_new, exist_ok=True)
# Clean up old mails
for f in glob.glob(os.path.join(maildir_new, "*")):
os.remove(f)
# Send SMS (actually sends a local email)
msg = sendsms(phone_number, text)
# Wait for delivery
files = []
for _ in range(50): # ~5 seconds
time.sleep(0.1)
files = sorted(glob.glob(os.path.join(maildir_new, "*")))
if files:
break
assert files, f"No message delivered to {maildir_new}"
# Read content of the delivered message
with open(files[-1], "r", encoding="utf-8", errors="replace") as f:
content = f.read()
# Check destination email format and body
expected_addr = f"{phone_number}@{SMS_GATEWAY_ADDRESS}"
assert f"To: {expected_addr}" in content
assert text in content