Ejemplo n.º 1
0
def test_invalid_user_recipient(mocker, test_client, init_database, standard_user):
    session = send_enter_recipient_state()
    state_machine = UssdStateMachine(session, standard_user)
    state_machine.send_sms = mocker.MagicMock()
    state_machine.feed_char("1234")

    assert state_machine.state == "exit_invalid_recipient"
    assert session.session_data is None
Ejemplo n.º 2
0
def test_change_current_pin(mocker, test_client, init_database):
    session = new_pin_confirmation_state()
    user = standard_user()

    state_machine = UssdStateMachine(session, user)
    state_machine.send_sms = mocker.MagicMock()

    state_machine.feed_char("2222")

    assert user.verify_pin("2222") is True
    state_machine.send_sms.assert_called_with(user.phone,
                                              "pin_change_success_sms")
Ejemplo n.º 3
0
def test_save_directory_info(mocker, test_client, init_database):
    session = UssdSessionFactory(state="change_my_business_prompt")
    user = standard_user()
    user.phone = phone()
    assert next(filter(lambda x: x.key == 'bio', user.custom_attributes),
                None) is None
    state_machine = UssdStateMachine(session, user)
    state_machine.send_sms = mocker.MagicMock()

    state_machine.feed_char("My Bio")
    assert state_machine.state == "exit"
    bio = next(filter(lambda x: x.key == 'bio', user.custom_attributes), None)
    assert bio.value == "My Bio"
Ejemplo n.º 4
0
def test_change_language(mocker, test_client, init_database, session_factory,
                         user_input, language):
    session = session_factory()
    user = standard_user()
    user.phone = phone()
    assert user.preferred_language is None

    state_machine = UssdStateMachine(session, user)
    state_machine.send_sms = mocker.MagicMock()

    state_machine.feed_char(user_input)
    assert state_machine.state == "complete"
    assert user.preferred_language == language
    state_machine.send_sms.assert_called_with(user.phone,
                                              "language_change_sms")
Ejemplo n.º 5
0
def test_invalid_phone_number(
        mocker, test_client, init_database, standard_user, create_transfer_account_user, external_reserve_token
):
    session = send_enter_recipient_state()

    invalid_recipient_phone = "1"

    state_machine = UssdStateMachine(session, standard_user)
    state_machine.send_sms = mocker.MagicMock()
    state_machine.feed_char(invalid_recipient_phone)

    assert state_machine.state == "exit_invalid_recipient"
    assert session.session_data is None

    assert not state_machine.send_sms.called
Ejemplo n.º 6
0
def test_opt_out_of_marketplace(mocker, test_client, init_database):
    session = UssdSessionFactory(
        state="opt_out_of_market_place_pin_authorization")
    user = standard_user()
    user.phone = phone()
    assert next(
        filter(lambda x: x.key == 'market_enabled', user.custom_attributes),
        None) is None
    state_machine = UssdStateMachine(session, user)
    state_machine.send_sms = mocker.MagicMock()

    state_machine.feed_char("0000")
    assert state_machine.state == "complete"
    assert user.is_market_enabled == False
    state_machine.send_sms.assert_called_with(user.phone,
                                              "opt_out_of_market_place_sms")
Ejemplo n.º 7
0
def test_invalid_recipient(
        mocker, test_client, init_database, standard_user, create_transfer_account_user, external_reserve_token
):
    session = send_enter_recipient_state()

    invalid_recipient_phone = "+61234567890"

    state_machine = UssdStateMachine(session, standard_user)
    state_machine.send_sms = mocker.MagicMock()
    state_machine.feed_char(invalid_recipient_phone)

    assert state_machine.state == "exit_invalid_recipient"
    assert session.session_data is None

    state_machine.send_sms.assert_called_with(
        invalid_recipient_phone,
        "upsell_message_recipient",
        first_name=standard_user.first_name,
        last_name=standard_user.last_name,
        token_name=standard_user.default_organisation.token.name
    )