示例#1
0
async def test_error_account_suspended(yessssms, requests_mock, caplog):
    """Test login that fails after multiple attempts."""
    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._login_url,
        status_code=200,
        text="BlaBlaBla<strong>Login nicht erfolgreichBlaBla",
    )

    message = "Testing YesssSMS platform :)"

    yessssms.send_message(message)
    assert requests_mock.called is True
    assert requests_mock.call_count == 1

    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._login_url,
        status_code=200,
        text="Wegen 3 ungültigen Login-Versuchen ist Ihr Account für "
        "eine Stunde gesperrt.",
    )

    message = "Testing YesssSMS platform :)"

    with caplog.at_level(logging.ERROR):
        yessssms.send_message(message)
    assert requests_mock.called is True
    assert requests_mock.call_count == 2
示例#2
0
async def test_sms_sending_error(yessssms, requests_mock, caplog):
    """Test sms sending error."""
    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._login_url,
        status_code=302,
        # pylint: disable=protected-access
        headers={"location": yessssms.yesss._kontomanager},
    )
    # pylint: disable=protected-access
    login = yessssms.yesss._logindata["login_rufnummer"]
    requests_mock.get(
        # pylint: disable=protected-access
        yessssms.yesss._kontomanager,
        status_code=200,
        text=f"test...{login}</a>",
    )
    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._websms_url,
        status_code=HTTP_INTERNAL_SERVER_ERROR,
    )

    message = "Testing YesssSMS platform :)"

    with caplog.at_level(logging.ERROR):
        yessssms.send_message(message)

    assert requests_mock.called is True
    assert requests_mock.call_count == 3
    for record in caplog.records:
        if (record.levelname == "ERROR"
                and record.name == "homeassistant.components.yessssms.notify"):
            assert "YesssSMS: error sending SMS" in record.message
示例#3
0
async def test_empty_message_error(yessssms, caplog):
    """Test for an empty SMS message error."""
    message = ""
    with caplog.at_level(logging.ERROR):
        yessssms.send_message(message)

    for record in caplog.records:
        if (record.levelname == "ERROR"
                and record.name == "homeassistant.components.yessssms.notify"):
            assert "Cannot send empty SMS message" in record.message
示例#4
0
async def test_error_account_suspended_2(yessssms, caplog):
    """Test login that fails after multiple attempts."""
    message = "Testing YesssSMS platform :)"
    # pylint: disable=protected-access
    yessssms.yesss._suspended = True

    with caplog.at_level(logging.ERROR):
        yessssms.send_message(message)
    for record in caplog.records:
        if (record.levelname == "ERROR"
                and record.name == "homeassistant.components.yessssms.notify"):
            assert "Account is suspended, cannot send SMS." in record.message
示例#5
0
async def test_no_recipient_error(yessssms, caplog):
    """Test for missing/empty recipient."""
    message = "Testing YesssSMS platform :)"
    # pylint: disable=protected-access
    yessssms._recipient = ""

    with caplog.at_level(logging.ERROR):
        yessssms.send_message(message)
    for record in caplog.records:
        if (record.levelname == "ERROR"
                and record.name == "homeassistant.components.yessssms.notify"):
            assert ("You need to provide a recipient for SMS notification"
                    in record.message)
示例#6
0
async def test_login_error(yessssms, requests_mock, caplog):
    """Test login that fails."""
    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._login_url,
        status_code=200,
        text="BlaBlaBla<strong>Login nicht erfolgreichBlaBla",
    )

    message = "Testing YesssSMS platform :)"

    with caplog.at_level(logging.ERROR):
        yessssms.send_message(message)
    assert requests_mock.called is True
    assert requests_mock.call_count == 1
示例#7
0
async def test_connection_error(yessssms, requests_mock, caplog):
    """Test connection error."""
    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._login_url,
        exc=yessssms.yesss.ConnectionError,
    )

    message = "Testing YesssSMS platform :)"

    with caplog.at_level(logging.ERROR):
        yessssms.send_message(message)

    assert requests_mock.called is True
    assert requests_mock.call_count == 1
    for record in caplog.records:
        if (record.levelname == "ERROR"
                and record.name == "homeassistant.components.yessssms.notify"):
            assert "cannot connect to provider" in record.message
示例#8
0
async def test_send_message(yessssms, requests_mock, caplog):
    """Test send message."""
    message = "Testing YesssSMS platform :)"
    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._login_url,
        status_code=302,
        # pylint: disable=protected-access
        headers={"location": yessssms.yesss._kontomanager},
    )
    # pylint: disable=protected-access
    login = yessssms.yesss._logindata["login_rufnummer"]
    requests_mock.get(
        # pylint: disable=protected-access
        yessssms.yesss._kontomanager,
        status_code=200,
        text=f"test...{login}</a>",
    )
    requests_mock.post(
        # pylint: disable=protected-access
        yessssms.yesss._websms_url,
        status_code=200,
        text="<h1>Ihre SMS wurde erfolgreich verschickt!</h1>",
    )
    requests_mock.get(
        # pylint: disable=protected-access
        yessssms.yesss._logout_url,
        status_code=200,
    )

    with caplog.at_level(logging.INFO):
        yessssms.send_message(message)
    for record in caplog.records:
        if (record.levelname == "INFO"
                and record.name == "homeassistant.components.yessssms.notify"):
            assert "SMS sent" in record.message

    assert requests_mock.called is True
    assert requests_mock.call_count == 4
    assert (requests_mock.last_request.scheme + "://" +
            requests_mock.last_request.hostname +
            requests_mock.last_request.path + "?" +
            requests_mock.last_request.query) in yessssms.yesss._logout_url  # pylint: disable=protected-access