def test_handle_disconnect(monkeypatch, smtp_port): def simulate_disconnect(self): raise smtplib.SMTPServerDisconnected() monkeypatch.setattr('smtplib.SMTP.rset', simulate_disconnect) monkeypatch.setattr('smtplib.SMTP.mail', lambda *args: (550, 'NOPE')) conn = SMTPConnection(account_id=1, email_address='*****@*****.**', auth_type='password', auth_token='secret_password', smtp_endpoint=('smtp.gmail.com', smtp_port), log=get_logger()) with pytest.raises(smtplib.SMTPSenderRefused): conn.sendmail(['*****@*****.**'], 'hello there')
def test_handle_disconnect(monkeypatch, smtp_port): def simulate_disconnect(self): raise smtplib.SMTPServerDisconnected() monkeypatch.setattr("smtplib.SMTP.rset", simulate_disconnect) monkeypatch.setattr("smtplib.SMTP.mail", lambda *args: (550, "NOPE")) conn = SMTPConnection( account_id=1, email_address="*****@*****.**", smtp_username="******", auth_type="password", auth_token="secret_password", smtp_endpoint=("smtp.gmail.com", smtp_port), log=get_logger(), ) with pytest.raises(smtplib.SMTPSenderRefused): conn.sendmail(["*****@*****.**"], "hello there")