test: use smtplib.SMTP[_SSL] timeout = notifications.smtp-timeout

A new option has been added for configuration of SMTP timeout:
- notifications.smtp-timeout

During tests, we can change this timeout to be small, so we aren't
depending on hardware-based RNG to pass the timeout.

Without a timeout, users can run into a long-running test for no
particular reason.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-03-08 17:51:44 -08:00
parent 13217be939
commit e00cf5f124
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
4 changed files with 37 additions and 21 deletions

View file

@ -104,7 +104,10 @@ class Notification:
False: smtplib.SMTP,
True: smtplib.SMTP_SSL,
}
server = classes[use_ssl](server_addr, server_port)
smtp_timeout = aurweb.config.getint("notifications",
"smtp-timeout")
server = classes[use_ssl](server_addr, server_port,
timeout=smtp_timeout)
if use_starttls:
server.ehlo()

View file

@ -36,6 +36,9 @@ class FakeSMTP:
def quit(self) -> None:
self.quit_count += 1
def __call__(self, *args, **kwargs) -> "FakeSMTP":
return self
class FakeSMTP_SSL(FakeSMTP):
""" A fake version of smtplib.SMTP_SSL used for testing. """