Esempio n. 1
0
def test_object_initialization():
    """
    API: NotifySNS Plugin() initialization

    """

    # Initializes the plugin with a valid access, but invalid access key
    with pytest.raises(TypeError):
        # No access_key_id specified
        plugins.NotifySNS(
            access_key_id=None,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            targets='+1800555999',
        )

    with pytest.raises(TypeError):
        # No secret_access_key specified
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=None,
            region_name=TEST_REGION,
            targets='+1800555999',
        )

    with pytest.raises(TypeError):
        # No region_name specified
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=None,
            targets='+1800555999',
        )

    with pytest.raises(TypeError):
        # No recipients
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            targets=None,
        )

    with pytest.raises(TypeError):
        # No recipients - garbage recipients object
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            targets=object(),
        )

    with pytest.raises(TypeError):
        # The phone number is invalid, and without it, there is nothing
        # to notify
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            targets='+1809',
        )

    with pytest.raises(TypeError):
        # The phone number is invalid, and without it, there is nothing
        # to notify; we
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            targets='#(invalid-topic-because-of-the-brackets)',
        )
def test_object_initialization():
    """
    API: NotifySNS Plugin() initialization

    """

    # Initializes the plugin with a valid access, but invalid access key
    try:
        # No access_key_id specified
        plugins.NotifySNS(
            access_key_id=None,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            recipients='+1800555999',
        )
        # The entries above are invalid, our code should never reach here
        assert(False)

    except TypeError:
        # Exception correctly caught
        assert(True)

    try:
        # No secret_access_key specified
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=None,
            region_name=TEST_REGION,
            recipients='+1800555999',
        )
        # The entries above are invalid, our code should never reach here
        assert(False)

    except TypeError:
        # Exception correctly caught
        assert(True)

    try:
        # No region_name specified
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=None,
            recipients='+1800555999',
        )
        # The entries above are invalid, our code should never reach here
        assert(False)

    except TypeError:
        # Exception correctly caught
        assert(True)

    try:
        # No recipients
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            recipients=None,
        )
        # Still valid even without recipients
        assert(True)

    except TypeError:
        # Exception correctly caught
        assert(False)

    try:
        # No recipients - garbage recipients object
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            recipients=object(),
        )
        # Still valid even without recipients
        assert(True)

    except TypeError:
        # Exception correctly caught
        assert(False)

    try:
        # The phone number is invalid, and without it, there is nothing
        # to notify
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            recipients='+1809',
        )
        # The recipient is invalid, but it's still okay; this Notification
        # still becomes pretty much useless at this point though
        assert(True)

    except TypeError:
        # Exception correctly caught
        assert(False)

    try:
        # The phone number is invalid, and without it, there is nothing
        # to notify; we
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            recipients='#(invalid-topic-because-of-the-brackets)',
        )
        # The recipient is invalid, but it's still okay; this Notification
        # still becomes pretty much useless at this point though
        assert(True)

    except TypeError:
        # Exception correctly caught
        assert(False)
Esempio n. 3
0
def test_object_initialization(mock_post):
    """
    API: NotifySNS Plugin() initialization

    """

    # Initializes the plugin with a valid access, but invalid access key
    with pytest.raises(TypeError):
        # No access_key_id specified
        plugins.NotifySNS(
            access_key_id=None,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=TEST_REGION,
            targets='+1800555999',
        )

    with pytest.raises(TypeError):
        # No secret_access_key specified
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=None,
            region_name=TEST_REGION,
            targets='+1800555999',
        )

    with pytest.raises(TypeError):
        # No region_name specified
        plugins.NotifySNS(
            access_key_id=TEST_ACCESS_KEY_ID,
            secret_access_key=TEST_ACCESS_KEY_SECRET,
            region_name=None,
            targets='+1800555999',
        )

    # No recipients
    obj = plugins.NotifySNS(
        access_key_id=TEST_ACCESS_KEY_ID,
        secret_access_key=TEST_ACCESS_KEY_SECRET,
        region_name=TEST_REGION,
        targets=None,
    )

    # The object initializes properly but would not be able to send anything
    assert obj.notify(body='test', title='test') is False

    # The phone number is invalid, and without it, there is nothing
    # to notify
    obj = plugins.NotifySNS(
        access_key_id=TEST_ACCESS_KEY_ID,
        secret_access_key=TEST_ACCESS_KEY_SECRET,
        region_name=TEST_REGION,
        targets='+1809',
    )

    # The object initializes properly but would not be able to send anything
    assert obj.notify(body='test', title='test') is False

    # The phone number is invalid, and without it, there is nothing
    # to notify; we
    obj = plugins.NotifySNS(
        access_key_id=TEST_ACCESS_KEY_ID,
        secret_access_key=TEST_ACCESS_KEY_SECRET,
        region_name=TEST_REGION,
        targets='#(invalid-topic-because-of-the-brackets)',
    )

    # The object initializes properly but would not be able to send anything
    assert obj.notify(body='test', title='test') is False