Exemplo n.º 1
0
def test_configure_smtp_object_no_port(tmpdir, smtpserver, monkeypatch):
    monkeypatch.setattr(smtplib.SMTP, "__init__", mock_smtp_init)
    config = create_configuration(tmpdir, smtp_host=smtpserver.addr[0])
    email_pub = EmailPublisher(config)
    smtp_obj = email_pub.configure_smtp_object(smtpserver.addr[0], None)
    assert smtp_obj._host == smtpserver.addr[0]
    assert smtp_obj._port == 0
Exemplo n.º 2
0
def test_configure_smtp_object_custom_timeout(tmpdir, smtpserver, monkeypatch):
    monkeypatch.setattr(smtplib.SMTP, "__init__", mock_smtp_init)
    config = create_configuration(tmpdir, smtp_port=str(smtpserver.addr[1]))
    timeout_seconds = 15
    email_pub = EmailPublisher(config, connect_timeout_seconds=timeout_seconds)
    smtp_obj = email_pub.configure_smtp_object(smtpserver.addr[0],
                                               smtpserver.addr[1])
    assert smtp_obj._timeout == timeout_seconds
Exemplo n.º 3
0
def test_email_publisher_with_defaults(tmpdir, smtpserver):
    config = create_configuration(tmpdir, smtp_host=smtpserver.addr[0],
                                  smtp_port=str(smtpserver.addr[1]))
    email_pub = EmailPublisher(config)
    assert email_pub._replacement_context == {}
    assert email_pub._config['email_host'] == smtpserver.addr[0]
    assert email_pub._config['email_port'] == smtpserver.addr[1]
    assert email_pub._email_notifications_config_key == \
        EmailPublisher.EMAIL_NOTIFICATIONS_CONFIG_KEY
    assert email_pub.name() == "EmailPublisher"
    assert email_pub.priority_threshold is None
    assert email_pub._connect_timeout == 10
Exemplo n.º 4
0
def test_email_publisher_with_custom_name(tmpdir, smtpserver):
    config = create_configuration(tmpdir, smtp_host=smtpserver.addr[0],
                                  smtp_port=str(smtpserver.addr[1]))
    email_pub = EmailPublisher(config, name="Custom Name")
    assert email_pub.name() == "Custom Name"
Exemplo n.º 5
0
def create_default_email_publisher(tmpdir, smtpserver):
    config = create_configuration(tmpdir, smtp_host=smtpserver.addr[0],
                                  smtp_port=str(smtpserver.addr[1]))
    return EmailPublisher(config, defaults=config["email_defaults"]["general"])
Exemplo n.º 6
0
def test_email_publisher_repr(tmpdir, smtpserver):
    config = create_configuration(tmpdir, smtp_host=smtpserver.addr[0],
                                  smtp_port=str(smtpserver.addr[1]))
    email_pub = EmailPublisher(config)
    email_pub.__repr__()
Exemplo n.º 7
0
def test_requires_config():
    with pytest.raises(ValueError):
        EmailPublisher(config=None)
Exemplo n.º 8
0
def test_configure_smtp_object_no_host(tmpdir, smtpserver, monkeypatch):
    monkeypatch.setattr(smtplib.SMTP, "__init__", mock_smtp_init)
    config = create_configuration(tmpdir, smtp_port=str(smtpserver.addr[1]))
    email_pub = EmailPublisher(config)
    smtp_obj = email_pub.configure_smtp_object(None, smtpserver.addr[1])
    assert smtp_obj._host == "localhost"
Exemplo n.º 9
0
def test_email_publisher_with_custom_timeout_seconds(tmpdir, smtpserver):
    config = create_configuration(tmpdir, smtp_host=smtpserver.addr[0],
                                  smtp_port=str(smtpserver.addr[1]))
    timeout_seconds = 15
    email_pub = EmailPublisher(config, connect_timeout_seconds=timeout_seconds)
    assert email_pub._connect_timeout == timeout_seconds