Example #1
0
def test_send_message(monkeypatch):
    monkeypatch.setattr(backends.AwsBackend, "client", mock.MagicMock())
    monkeypatch.setattr(builtins, "open", mock.MagicMock())
    monkeypatch.setattr(renderer, "generate_content", mock.MagicMock())
    with pytest.raises(AttributeError):
        backends.AwsBackend().send("test", "test", ["*****@*****.**"], theme="test")

    backends.AwsBackend().send(
        "test", "test", ["*****@*****.**"], file_path="test", theme="test"
    )
Example #2
0
def test_verify_auth(monkeypatch):
    monkeypatch.setattr(boto3, "client", mock.MagicMock())

    assert backends.AwsBackend().verify_auth("access_key", "secret_key") is True
    boto3.client.assert_called_with(
        "ses",
        aws_access_key_id="access_key",
        aws_secret_access_key="secret_key",
        region_name="us-east-1",
    )

    monkeypatch.setattr(boto3, "client", MockClient)
    assert backends.AwsBackend().verify_auth("access_key", "secret_key") is False
Example #3
0
def test_send(monkeypatch):
    monkeypatch.setattr(backends.AwsBackend, "send", mock.MagicMock())

    command = application.find("send")
    command_tester = CommandTester(command)
    command_tester.execute("[email protected] test --c test --t test [email protected]")

    backends.AwsBackend().send.assert_called_with(
        sender="*****@*****.**",
        subject="test",
        content="test",
        to=["*****@*****.**"],
        file_path=None,
        theme="test",
        context={},
    )

    assert "Messages added to queue" in command_tester.io.fetch_output()

    command_tester.execute("[email protected] test --c test")

    assert "You must supply at least one recipient" in command_tester.io.fetch_output()

    command_tester.execute("[email protected] test [email protected] -e grrr=arg")

    assert (
        "You must provide either the content or file_path argument only"
        in command_tester.io.fetch_output()
    )

    command_tester.execute("--backend=grrr [email protected] test [email protected]")
    assert 'No backend called grrr' in command_tester.io.fetch_output()
Example #4
0
def test_client(monkeypatch):
    monkeypatch.setattr(utilities, "get_config", mock.MagicMock())
    monkeypatch.setattr(boto3, "client", mock.MagicMock())
    utilities.get_config.return_value = dict(access_key=1, secret_key=1)
    backends.AwsBackend().client

    boto3.client.assert_called_with(
        "ses", aws_access_key_id=None, aws_secret_access_key=None, region_name="us-east-1"
    )
Example #5
0
def test_verify(monkeypatch):
    monkeypatch.setattr(backends.AwsBackend, "verify_address", mock.MagicMock())

    command = application.find("verify")
    command_tester = CommandTester(command)
    command_tester.execute("*****@*****.**")

    backends.AwsBackend().verify_address.assert_called_with("*****@*****.**")
    assert (
        "This email address has already been verified"
        in command_tester.io.fetch_output()
    )

    backends.AwsBackend().verify_address.return_value = False
    command_tester.execute("*****@*****.**")
    assert "Email sent to [email protected]" in command_tester.io.fetch_output()

    command_tester.execute("--backend=grrr [email protected]")
    assert 'No backend called grrr' in command_tester.io.fetch_output()
Example #6
0
def test_init(monkeypatch):
    monkeypatch.setattr(backends.AwsBackend, "login", mock.MagicMock())
    command = application.find("init")
    command_tester = CommandTester(command)
    command_tester.execute("access_key=access_key secret_key=secret_key region=region aws_config_file=aws_config_file")

    backends.AwsBackend().login.assert_called_with(
        access_key="access_key",
        secret_key="secret_key",
        region="region",
        aws_config_file="aws_config_file",
    )
    assert "Initiated successfully" in command_tester.io.fetch_output()

    command_tester.execute("--backend=grrr")
    assert 'No backend called grrr' in command_tester.io.fetch_output()
Example #7
0
def test_login(monkeypatch):
    monkeypatch.setattr(configparser, "ConfigParser", mock.MagicMock())
    monkeypatch.setattr(backends.AwsBackend, "verify_auth", mock.MagicMock())
    backends.AwsBackend().login(aws_config_file="cred")
    configparser.ConfigParser().read.assert_called_with("cred")
Example #8
0
def test_verify_address(monkeypatch):
    monkeypatch.setattr(boto3, "client", MockClient)
    backend = backends.AwsBackend()

    assert backend.verify_address("*****@*****.**") is True
    assert backend.verify_address("*****@*****.**") is False