예제 #1
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]
예제 #2
0
def test_handle_inbound_call_no_event(database):
    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 event was found" in ncco[0]["text"]
예제 #3
0
def inbound_call(client):
    call = flask.request.get_json()
    event_number = lowlevel.normalize_number(call["to"])
    conversation_uuid = call["conversation_uuid"]
    call_uuid = call["uuid"]

    ncco = voice.handle_inbound_call(
        event_number=event_number,
        conversation_uuid=conversation_uuid,
        call_uuid=call_uuid,
        host=flask.request.host,
    )

    return flask.jsonify(ncco)
예제 #4
0
def test_handle_inbound_call_no_members(database):
    event = create_event()
    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"]
예제 #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"]
예제 #6
0
def test_handle_inbound_call_blocked(database):
    event = create_event()
    add_unverfied_members(event)

    nexmo_client = mock.create_autospec(nexmo.Client)

    db.BlockList.create(event=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"]
예제 #7
0
def test_handle_inbound_call_custom_greeting(database):
    event = create_event()
    add_members(event)

    nexmo_client = mock.create_autospec(nexmo.Client)

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

    ncco = voice.handle_inbound_call(
        reporter_number="1234",
        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!"
예제 #8
0
def test_handle_inbound_call(database):
    event = create_event()
    add_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,
    )

    # 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 two organizers.
    assert nexmo_client.create_call.call_count == 2

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

    assert calls_created[0]["to"] == [{"type": "phone", "number": "101"}]
    assert calls_created[0]["from"] == {"type": "phone", "number": "5678"}
    assert "example.com" in calls_created[0]["answer_url"][0]
    assert calls_created[1]["to"] == [{"type": "phone", "number": "202"}]
    assert calls_created[1]["from"] == {"type": "phone", "number": "5678"}
    assert "example.com" in calls_created[1]["answer_url"][0]