Esempio n. 1
0
def test_handle_verification_affirmative_message(sleep, database):
    client = mock.create_autospec(nexmo.Client, instance=True)

    client.application_id = "appid"
    client.send_message.return_value = {"messages": [{"error-text": ""}]}

    injector.set("nexmo.client", client)

    hotline_virtual_number = "1234567890"
    injector.set("secrets.virtual_number", hotline_virtual_number)

    event = helpers.create_event()

    responses = ("ok", "yes", "okay")
    for response in responses:
        member = helpers.add_unverfied_members(event)
        verification.maybe_handle_verification(member.number, response)

        member = db.get_member_by_number(member.number)
        assert member.verified

        expected_msg = "Thank you, your number is confirmed."
        client.send_message.assert_called_with({
            "from": event.primary_number,
            "to": member.number,
            "text": expected_msg
        })
Esempio n. 2
0
def test_handle_member_answer(database):
    event = helpers.create_event()
    helpers.add_members(event)

    nexmo_client = mock.create_autospec(nexmo.Client)

    ncco = voice.handle_member_answer(
        event_number="5678",
        member_number="202",
        origin_conversation_uuid="conversation",
        origin_call_uuid="call",
        client=nexmo_client,
    )

    assert len(ncco) == 2

    # The member should have been greeted and then connected to a conference
    # call.
    assert ncco[0]["action"] == "talk"
    assert "Test event" in ncco[0]["text"]
    assert "Alice" in ncco[0]["text"]
    assert ncco[1]["action"] == "conversation"
    assert ncco[1]["name"] == "conversation"

    # The conference call should have been notified that the member is joining.
    nexmo_client.send_speech.assert_called_once_with("call", text=mock.ANY)
Esempio n. 3
0
def test_start_member_verification_no_primary_event_number(sleep, database):
    client = mock.create_autospec(nexmo.Client, instance=True)

    client.application_id = "appid"
    client.send_message.return_value = {"messages": [{"error-text": ""}]}

    injector.set("nexmo.client", client)

    hotline_virtual_number = "1234567890"
    injector.set("secrets.virtual_number", hotline_virtual_number)

    event = helpers.create_event(create_primary_number=False)
    member = helpers.add_unverfied_members(event)

    verification.start_member_verification(member)

    expected_msg = (
        f"You've been added as a member of the {member.event.name} event on conducthotline.com."
        " Reply with YES or OK to confirm.")

    client.send_message.assert_called_once_with({
        "from": hotline_virtual_number,
        "to": member.number,
        "text": expected_msg
    })
Esempio n. 4
0
def test_handle_inbound_call(database):
    hotline = helpers.create_event()
    members = helpers.add_members(hotline)
    caller = members[0]

    nexmo_client = mock.create_autospec(nexmo.Client)

    ncco = voice.handle_inbound_call(
        reporter_number=caller.number,
        event_number="+5678",
        conversation_uuid="conversation",
        call_uuid="call",
        host="example.com",
        client=nexmo_client,
    )

    # The caller should have been greeted and then connected to a conference
    # call.
    assert len(ncco) == 2
    assert ncco[0]["action"] == "talk"
    assert "Thank you" in ncco[0]["text"]
    assert ncco[1]["action"] == "conversation"
    assert ncco[1]["name"] == "conversation"

    # The nexmo client should have been used to call the other
    # member of the hotline, excluding the original caller.
    assert nexmo_client.create_call.call_count == 1

    calls_created = [
        call[1][0] for call in nexmo_client.create_call.mock_calls
    ]

    assert calls_created[0]["to"] == [{"type": "phone", "number": "202"}]
    assert calls_created[0]["from"] == {"type": "phone", "number": "5678"}
    assert "example.com" in calls_created[0]["answer_url"][0]
Esempio n. 5
0
def test_handle_inbound_call_non_member_doesnt_connect(database):
    hotline = helpers.create_event()
    helpers.add_members(hotline)

    nexmo_client = mock.create_autospec(nexmo.Client)

    ncco = voice.handle_inbound_call(
        reporter_number="1234567",
        event_number="5678",
        conversation_uuid="conversation",
        call_uuid="call",
        host="example.com",
        client=nexmo_client,
    )

    assert len(ncco) == 1
    assert "You're not a verified member of this hotline" in ncco[0]["text"]
Esempio n. 6
0
def test_handle_inbound_call_no_members(database):
    event = helpers.create_event()
    helpers.add_unverfied_members(event)

    nexmo_client = mock.create_autospec(nexmo.Client)

    ncco = voice.handle_inbound_call(
        reporter_number="1234",
        event_number="5678",
        conversation_uuid="conversation",
        call_uuid="call",
        host="example.com",
        client=nexmo_client,
    )

    assert len(ncco) == 1
    assert "no verified members" in ncco[0]["text"]
Esempio n. 7
0
def test_handle_inbound_call_blocked(database):
    event = helpers.create_event()
    helpers.add_unverfied_members(event)

    nexmo_client = mock.create_autospec(nexmo.Client)

    helpers.create_block_list(event, number="1234", blocked_by="test")

    ncco = voice.handle_inbound_call(
        reporter_number="1234",
        event_number="+5678",
        conversation_uuid="conversation",
        call_uuid="call",
        host="example.com",
        client=nexmo_client,
    )

    assert len(ncco) == 1
    assert "unavailable" in ncco[0]["text"]
Esempio n. 8
0
def test_handle_inbound_call_custom_greeting(database):
    event = helpers.create_event()
    members = helpers.add_members(event)
    caller = members[0]

    nexmo_client = mock.create_autospec(nexmo.Client)

    event.voice_greeting = "Ahoyhoy!"
    event.save()

    ncco = voice.handle_inbound_call(
        reporter_number=caller.number,
        event_number="5678",
        conversation_uuid="conversation",
        call_uuid="call",
        host="example.com",
        client=nexmo_client,
    )

    # The caller should have been greeted with the custom greeting.
    assert ncco[0]["action"] == "talk"
    assert ncco[0]["text"] == "Ahoyhoy!"
Esempio n. 9
0
def test_handle_verification_negative_message(sleep, database):
    client = mock.create_autospec(nexmo.Client, instance=True)

    client.application_id = "appid"
    client.send_message.return_value = {"messages": [{"error-text": ""}]}

    injector.set("nexmo.client", client)

    hotline_virtual_number = "1234567890"
    injector.set("secrets.virtual_number", hotline_virtual_number)

    event = helpers.create_event()

    responses = ("nyet", "nay", "no way")
    for response in responses:
        member = helpers.add_unverfied_members(event)
        verification.maybe_handle_verification(member.number, response)

        member = db.get_member_by_number(member.number)
        assert not member.verified

        client.send_message.assert_not_called()