def test_success_emit():
    handler = EmailHandler(debuglevel=False)
    record = {
        'type': 'email',
        'from': '*****@*****.**',
        'recipients': ['*****@*****.**', '*****@*****.**'],
        'html': 'This is a test email. It can <i>also</i> contain HTML code',
        'text': 'This is a test email. It is text only'
    }
    result = handler.emit(record, silent=False)
    assert result == None
def test_bad_host(monkeypatch):
    monkeypatch.setattr(settings, 'EMAIL_HOST', 'nohost.jrd.com')

    handler = EmailHandler(debuglevel=False)
    record = {
        'type': 'email',
        'from': '*****@*****.**',
        'recipients': ['*****@*****.**', '*****@*****.**'],
        'html': 'This is a test email. It can <i>also</i> contain HTML code',
        'text': 'This is a test email. It is text only'
    }
    with pytest.raises(socket.gaierror):
        handler.emit(record, silent=False)
def test_bad_user(monkeypatch):
    monkeypatch.setattr(settings, 'EMAIL_HOST_USER', 'wael')

    handler = EmailHandler(debuglevel=False)
    record = {
        'type': 'email',
        'from': '*****@*****.**',
        'recipients': ['*****@*****.**', '*****@*****.**'],
        'html': 'This is a test email. It can <i>also</i> contain HTML code',
        'text': 'This is a test email. It is text only'
    }
    with pytest.raises(smtplib.SMTPAuthenticationError):
        handler.emit(record, silent=False)